SDKs overview
CARTO provides Software Development Kits (SDKs) and libraries designed to facilitate interaction with its cloud-native geospatial platform. These tools enable developers to integrate CARTO's capabilities for spatial data management, analysis, and visualization into custom applications and data workflows. The official SDKs are primarily offered for Python and JavaScript, catering to both server-side data processing and client-side web development needs CARTO documentation portal.
The SDKs abstract the underlying RESTful APIs, providing a more convenient and idiomatic interface for common operations such as connecting to the CARTO platform, managing datasets, executing spatial analytics, and rendering maps. This approach aims to streamline the development of location intelligence applications and services by reducing the complexity of direct API interactions.
Key functionalities supported by CARTO's SDKs include:
- Data Ingestion and Management: Uploading, querying, and updating spatial datasets.
- Spatial Analytics: Accessing and executing functions from the CARTO Analytics Toolbox.
- Map Visualization: Creating and styling interactive maps for web applications.
- Platform Integration: Connecting to various CARTO services like the Spatial Data Catalog.
Official SDKs by language
CARTO offers official SDKs primarily for Python and JavaScript, designed to support different development environments and use cases CARTO developer guides. These SDKs are maintained by CARTO and provide stable interfaces for interacting with the platform's features.
The following table summarizes the official SDKs:
| Language | Package Name | Primary Use Case | Maturity |
|---|---|---|---|
| Python | cartoframes |
Data science, ETL, server-side data processing, integration with data warehouses | Stable |
| JavaScript | @deck.gl/carto, @carto/react |
Web mapping, client-side applications, interactive data visualization | Stable |
Installation
Installation methods for CARTO SDKs vary by language and environment. The following sections detail the typical installation procedures.
Python SDK (cartoframes)
The cartoframes library is the primary Python SDK for CARTO, offering tools for data scientists and developers to work with spatial data directly within Python environments. It integrates with popular data science libraries like Pandas and GeoPandas.
To install cartoframes, use pip:
pip install cartoframes
For additional features, such as integration with specific cloud data warehouses (e.g., BigQuery, Snowflake), refer to the cartoframes installation guide for optional dependencies.
JavaScript SDKs (@deck.gl/carto and @carto/react)
CARTO provides JavaScript libraries tailored for web mapping and application development. @deck.gl/carto is an extension for deck.gl, a WebGL-powered data visualization framework, enabling efficient rendering of large spatial datasets from CARTO. @carto/react is a React component library built on top of deck.gl and other CARTO libraries, designed for building full-featured location intelligence applications.
To install @deck.gl/carto with npm:
npm install @deck.gl/carto deck.gl
To install @carto/react with npm:
npm install @carto/react
These packages can also be installed using Yarn, following standard JavaScript package management practices.
Quickstart example
The following examples demonstrate basic usage of CARTO's Python and JavaScript SDKs.
Python Quickstart: Loading and Visualizing Data
This example uses cartoframes to connect to a CARTO account, load a dataset from a data warehouse, and display it as a map within a Jupyter notebook environment.
from cartoframes.auth import set_default_credentials
from cartoframes.data import Dataset
from cartoframes.viz import Map,
# Set your CARTO credentials
# Replace 'YOUR_CARTO_USERNAME' and 'YOUR_CARTO_API_KEY' with your actual credentials
# For security, consider using environment variables for sensitive info
set_default_credentials(username='YOUR_CARTO_USERNAME', api_key='YOUR_CARTO_API_KEY')
# Load a dataset from your CARTO account
# Replace 'your_dataset_name' with the actual name of your dataset
dataset = Dataset('your_dataset_name')
# Create a map visualization
m = Map(dataset)
# Display the map (works in Jupyter notebooks)
m
This snippet assumes you have a CARTO account configured and a dataset available. For detailed setup, refer to the cartoframes Getting Started guide.
JavaScript Quickstart: Displaying a Map with @carto/react
This example demonstrates how to create a basic map component using @carto/react within a React application, displaying data from a CARTO source. This requires a React project setup.
import React from 'react';
import { CartoMap, Layer, accessToken } from '@carto/react';
// Set your CARTO access token
// For production, use environment variables or a secure token management system
accessToken.set('YOUR_CARTO_ACCESS_TOKEN');
function MyMapComponent() {
const sourceId = 'your_carto_source_id'; // Replace with a valid CARTO source ID or table name
return (
<CartoMap
connectionName="carto_dw"
basemap="voyager"
viewState={{
latitude: 40.7, // Example coordinates for New York
longitude: -74,
zoom: 10
}}
style={{ width: '100%', height: '500px' }}
>
<Layer
id="my-carto-layer"
source={sourceId}
type="point"
getFillColor={[255, 0, 0, 150]}
getPointRadius={100} // Radius in meters for point layers
/>
</CartoMap>
);
}
export default MyMapComponent;
This example assumes a CARTO access token is set and a valid source ID exists in your CARTO account. More comprehensive examples and configurations are available in the CARTO for React documentation.
Community libraries
Beyond the official SDKs, the CARTO ecosystem benefits from various community-contributed libraries and open-source projects that extend its functionality or provide integrations with other tools. While not officially supported by CARTO, these libraries can offer specialized capabilities or alternative approaches for specific use cases.
- Geospatial Libraries: Many open-source geospatial libraries, such as GeoPandas for Python or Leaflet.js for JavaScript, can be used in conjunction with CARTO's SDKs. These libraries handle common geospatial operations, and their outputs or inputs can often be integrated with CARTO's platform for further analysis or visualization. For instance, GeoPandas DataFrames can be directly uploaded to CARTO via
cartoframes. - Data Connectors: Community-developed connectors might exist for specific data sources or platforms not directly covered by CARTO's official integrations, allowing for more diverse data ingestion pipelines.
- Visualization Extensions: Developers may create custom visualization components or extensions for front-end frameworks that interact with CARTO's APIs to display spatial data in unique ways.
Developers are advised to review the documentation and community support for any third-party libraries before integrating them into production systems Mozilla Developer Network's guide on Promises (as a general example of independent technical content useful for developers). The CARTO community forums and GitHub repositories are common places to discover and discuss these types of contributions.