Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / python-bindings

Python bindings

The Python bindings give Python users a high-level way to describe deck.gl maps, charts, and data views. pydeck turns Python objects into a deck.gl scene description and sends it to a browser through notebook or HTML output. pydeck-carto adds a Python-facing bridge to CARTO data sources, CARTO layers, and CARTO color rules while the browser still performs CARTO data access and drawing.

Binding role

Python-to-deck model

pydeck is the Python description layer for a deck.gl visualization. An engineer chooses layers, data, views, camera state, map settings, effects, and UI widgets in Python. The binding serializes that description into the JSON shape expected by the deck.gl runtime. The browser then creates the visualization. This keeps scene intent in Python while JavaScript handles drawing and map interaction. See JSON specification for the shared declarative boundary.

The main objects map to these responsibilities:

Python objectVisualization responsibility
LayerSelects a deck.gl layer type and supplies its data and visual properties.
View and ViewStateDefine the view layout and the starting camera position.
DeckGroups the scene and controls output, basemaps, tooltips, effects, and widgets.
WidgetAdds a deck.gl user-interface control or information panel to the scene.
Extension and EffectAdds optional layer behavior or visual processing to the scene.

The binding accepts common Python data forms such as records, pandas data frames, and objects with a Geo interface. It can also describe accessors as expressions so a layer can read fields from each record in the browser. The gallery includes specialized geospatial layers such as A5Layer, so the same model covers indexed cells as well as common points, paths, and polygons.

References: bindings/…/deck.py• L33-55 bindings/…/layer.py• L17-39 bindings/…/view.py• L6-33 bindings/…/view_state.py• L4-28 bindings/…/widget.py• L7-30 bindings/…/a5_layer.py• L20-40

Configuration flow

The binding sends a scene description across one clear boundary. Python creates the description. Serialization removes runtime-only state and maps Python field names to the JSON names used by deck.gl. A notebook or HTML bridge passes the result to the deck.gl browser runtime. The runtime creates the visualization and handles interaction.

This diagram shows how Python choices become a browser-rendered scene.

flowchart LR
  A[Python data and choices] --> B[pydeck scene objects]
  B --> C[deck.gl JSON description]
  C --> D[Notebook or HTML bridge]
  D --> E[deck.gl browser runtime]
  E --> F[Rendered map, chart, and interaction]

The JSON payload can use a compact form for HTML output without changing its meaning. This boundary lets a Python application use the wider deck.gl layer library without reimplementing the rendering engine. Browser-only behavior must be expressed through the serialized scene or through a supported notebook message path.

References: bindings/…/deck.py• L265-283 bindings/…/json_tools.py• L9-20 bindings/…/json_tools.py• L54-105 bindings/…/html.py• L144-190 bindings/…/test_deck.py• L45-80

Visualization construction

Layer and data descriptions

Layer is the main bridge from Python data to deck.gl visual marks. It names a deck.gl layer and passes layer properties through the scene description. The Python API therefore follows the deck.gl layer catalog instead of defining a separate set of visual primitives.

Data can remain as browser-loadable input or become JSON records. Supported pandas data can also use a binary transport path for larger numeric data. The serializer supports record-like Python objects even when they do not expose a normal attribute dictionary. This transport choice changes how data crosses the boundary. It does not change the layer model or make Python perform the rendering.

The examples cover point, line, path, polygon, grid, geospatial index, terrain, text, icon, trip, and flow views. They also show aggregation and time-driven scenes. Each example keeps data preparation in Python and expresses the visual result through a deck.gl layer.

References: bindings/…/layer.py• L17-39 bindings/…/layer.py• L121-169 bindings/…/json_tools.py• L72-94 bindings/…/type_checking.py• L1-35 bindings/…/binary_transfer.py• L34-61 bindings/pydeck/examples/01 - Introduction.ipynb#L36-L95 bindings/pydeck/examples/02 - Scatterplots.ipynb#L69-L113 bindings/…/trips_layer.py• L13-33

Extensions and community libraries

Extensions add optional deck.gl behavior to a layer, such as filtering, masking, or path styling. Python describes the extension and its layer properties, while deck.gl applies the behavior in the browser. Accessors remain serialized expressions rather than arbitrary Python or JavaScript callbacks, so the binding supports only the expression forms understood by the browser runtime.

The current examples also show typed extensions for brushing, filtering, masking, collision control, path styling, clipping, fill patterns, and terrain draping. These examples reinforce the boundary: Python selects the extension and its data-driven properties, while the browser applies the visual rule.

The same boundary supports layers, extensions, and widgets from external JavaScript libraries. A classic bundle or ES module is registered before the scene is displayed, then its exported types can be named in normal pydeck scene objects. ES modules can use the supported deck.gl package names supplied by the page, so compatible libraries can share pydeck's loaded runtime instead of bundling another copy. The community library path provides npm packages such as @deck.gl-community/three; its TreeLayer example shows Python preparing data while the browser renders the three-dimensional result. This path does not send edits from community editable layers back to Python.

References: bindings/…/extension.rst• L9-15 bindings/…/extension.rst• L35-52 bindings/…/extension.rst• L54-82 bindings/…/custom_layers.rst• L4-15 bindings/…/custom_layers.rst• L30-45 bindings/…/custom_layers.rst• L59-101 bindings/…/community_libraries.rst• L4-43 bindings/…/community_libraries.rst• L54-80 bindings/…/brushing_extension.py• L21-38 bindings/…/data_filter_extension.py• L22-42 bindings/…/mask_extension.py• L24-47 bindings/…/terrain_extension.py• L19-56 bindings/…/paris_trees.py• L5-17

View and camera descriptions

View and ViewState let Python describe both map scenes and non-geospatial scenes. A default Deck leaves the view choice to deck.gl and sends a top-level controller for the full-screen map. Explicit views can instead define fixed panes, independent cameras, or non-geospatial cameras.

Multiple views support responsive layouts through bounds such as pixels, percentages, and CSS calc() expressions. A SplitterWidget supports panes with a draggable divider and can nest split layouts. Each view can receive its own camera by using its view ID in initial_view_state.

OrthographicView and OrbitView extend pydeck beyond maps. They support two-dimensional charts and three-dimensional plots with ordinary deck.gl layers. These scenes normally disable the basemap and use plain x/y/z coordinates. GlobeView provides a named globe view for spherical map scenes.

The example set also covers globe projection and 3D terrain scenes. These are still the same Python-to-deck description flow, with the map provider and terrain data defining the browser-side environment.

References: bindings/…/deck.py• L115-127 bindings/…/view.rst• L9-66 bindings/…/view_state.rst• L8-40 bindings/…/widget.rst• L12-49 bindings/…/maplibre_globe.py• L30-58 bindings/…/terrain_layer.py• L18-38 bindings/…/terrain_extension.py• L19-71 bindings/…/scatter_plot.py• L111-123 bindings/…/multi_view.py• L44-70 bindings/…/CHANGELOG.rst• L9-23 bindings/…/test_deck.py• L163-183

Scene controls

Deck combines layers with camera state, view layout, basemap choice, tooltip policy, effects, and optional widgets. Typed effects provide a Python description for lighting and post-processing behavior. It also selects a basemap provider such as CARTO, Mapbox, Google Maps, or MapLibre. Provider-specific map drawing remains in the browser runtime.

Global pydeck.settings provides the extension point for extra JavaScript libraries, shared configuration, and default layer properties. A library can come from a URL or from an npm package through the configured ESM CDN. ES module packages can share pydeck's bundled deck.gl, luma.gl, loaders.gl, and math.gl packages instead of loading a second copy. Custom libraries load when notebook or HTML output is displayed. Re-registering a library name replaces its earlier entry, which keeps repeated notebook-cell runs from adding duplicate libraries.

ES module libraries and community packages must target the deck.gl runtime used by pydeck. A mismatched or unpinned community version produces a warning. Unsupported module subpaths or a page that loads another ES module before pydeck's import map can prevent a library from loading.

The built-in widget examples use the same scene-level control surface for navigation, screen utilities, scale and performance information, and feature popups. A widget belongs to a view and complements the layer data rather than replacing it.

References: bindings/…/deck.py• L41-55 bindings/…/deck.py• L121-160 bindings/…/settings.py• L9-32 bindings/…/settings.py• L75-147 bindings/…/widget.py• L7-37 bindings/…/custom_layers.rst• L4-15 bindings/…/custom_layers.rst• L30-45 bindings/…/custom_layers.rst• L59-101 bindings/…/community_libraries.rst• L14-52 bindings/…/CHANGELOG.rst• L9-31 bindings/…/widgets.py• L51-79 bindings/pydeck/examples/01 - Introduction.ipynb#L117-L133 bindings/…/test_settings.py• L40-157

Rendering surfaces

Notebook display

In a notebook, Deck prepares HTML for display in an iframe. Google Colab uses its own display path so the output height is managed by the Colab host. Both paths use the same serialized scene rather than a second scene model. The installed notebook extension enables the pydeck/extensionRequires loader target, which connects the package's static widget code to the notebook front end. See widgets and Jupyter for the broader widget package.

The lower-level DeckGLWidget supports messages for hover, click, resize, camera changes, and drag events. It can retain selected objects for Python code. The current pydeck 0.9 public display path does not support Deck.update(), so changing Python state does not update an already shown scene through that method.

Notebook examples show the intended two-way boundary for supported widget paths: browser selection can become selected_data in Python, and view-state events can update an ipywidgets control. Other examples show data and controls changing over time, but the current public pydeck 0.9 path still requires a supported display flow rather than relying on Deck.update().

References: bindings/…/deck.py• L17-27 bindings/…/deck.py• L195-227 bindings/…/html.py• L15-21 bindings/…/html.py• L136-190 bindings/…/pydeck.json• L1-4 bindings/…/test_nbextension_path.py• L19-36 bindings/…/Makefile• L49-59 bindings/pydeck/examples/03 - Event handlers and data selection in pydeck.ipynb#L83-L146 bindings/pydeck/examples/05 - Interacting with other Jupyter widgets.ipynb#L61-L110 bindings/…/test_deck.py• L82-160

HTML output

Deck.to_html() packages the serialized scene into a self-contained HTML page or returns an HTML string when requested. The page loads the deck.gl Jupyter widget bundle and its styles from a versioned CDN by default. Offline mode embeds the local bundle instead. This surface supports scripts, reports, and non-notebook use. The Python process does not need to remain active after the page is written.

The HTML surface embeds the scene JSON in compact form to reduce output size. It can also pass map provider keys, custom JavaScript libraries, runtime configuration, tooltip settings, and error-display settings into the page. Registered libraries are emitted as page configuration, so a custom layer or community package must be registered before HTML generation. Provider credentials must still be available through explicit arguments or the supported environment-variable conventions.

References: bindings/…/deck.py• L229-283 bindings/…/json_tools.py• L97-105 bindings/…/html.py• L37-64 bindings/…/html.py• L77-103 bindings/…/html.py• L144-190 bindings/…/settings.py• L88-147 bindings/…/Makefile• L17-35 bindings/pydeck/examples/01 - Introduction.ipynb#L200-L215 bindings/…/maplibre_globe.py• L48-58 bindings/…/test_settings.py• L21-74 bindings/…/test_deck.py• L65-80

CARTO integration

CARTO layer registration

pydeck-carto is an adapter between Python scene construction and the JavaScript CARTO layer package. Calling register_layers() adds the CARTO JavaScript bundle to pydeck's custom-library settings and supplies default error handling for CARTO layer types. Python can then name CARTO layer types through the normal pdk.Layer interface.

This adapter does not reimplement the CARTO layer runtime. The browser loads the CARTO bundle and uses its deck.gl layer implementations to fetch and draw data. See CARTO integration for the JavaScript package and its data-runtime responsibilities.

References: bindings/…/__init__.py• L1-11 bindings/…/layer.py• L1-60 modules/…/index.ts• L5-32

CARTO data sources

The Python adapter describes CARTO sources as deck.gl function values. Source helpers carry the connection name, access token, API base URL, and one of a table, SQL query, or tileset. The browser-side CARTO layer package consumes the source. Python supplies source intent and access details but does not query the warehouse itself.

The supported source families are:

Source familyPython source formsProduct use
VectorTable, query, or tilesetGeneral vector tile data.
H3Table, query, or tilesetH3-indexed data with optional aggregation.
QuadbinTable, query, or tilesetQuadbin-indexed data with optional aggregation.
RasterNo working source helperExperimental and not implemented in the Python adapter.

The adapter checks the main source options and converts Python names to the camel-case fields expected by the CARTO JavaScript API. Authentication still belongs to the application. The examples use carto-auth to obtain the token and API URL before creating a source.

References: bindings/…/sources.py• L8-45 bindings/…/sources.py• L66-142 bindings/…/sources.py• L145-233 bindings/…/sources.py• L236-437 bindings/…/README.md• L24-57

CARTO styles

The Python style helpers describe threshold bins, category mapping, and continuous interpolation. They return function values for deck.gl accessors. The browser applies the rule to feature attributes while rendering. These helpers provide a short Python syntax for CARTO styling without making the Python package a style engine.

Each rule can use a named CARTO palette or explicit colors. Missing values use a null color. Category rules also provide a fallback for values outside the declared category set.

References: bindings/…/styles.py• L6-109 modules/…/index.ts• L61-63 modules/…/color-bins-style.ts• L20-52 modules/…/color-categories-style.ts• L19-60 modules/…/color-continuous-style.ts• L20-51

Integration boundaries

Python and browser responsibilities

The Python side owns scene intent, data preparation, source description, and output selection. The browser side owns deck.gl layer construction, tile or query access, map drawing, and interactive event handling. This split lets pydeck use the deck.gl layer library while keeping Python code independent of WebGL and browser APIs.

The boundary is especially important for CARTO. A valid Python source description does not prove that a token, API URL, query, or tileset will work. The browser must load the registered CARTO library and complete the remote data request before the layer can render.

References: bindings/…/deck.py• L265-283 bindings/…/index.j2• L25-47 modules/…/vector-tile-layer.ts• L89-132

Python bindings are one application-facing path into deck.gl. They share the deck.gl runtime with React and map-host integrations but differ in how the scene reaches that runtime. Python uses serialized configuration and notebook or HTML bridges. React and host-map packages manage a live JavaScript scene in an application shell.

Use these pages to follow the neighboring boundaries:

References: bindings/…/README.md• L6-13 bindings/…/html.py• L144-190 bindings/…/settings.py• L42-59 bindings/…/index.rst• L16-28 bindings/…/index.rst• L129-135

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the pydeck JSON shape aligned with the deck.gl JSON and Jupyter runtime contracts when changing binding object names, view defaults, or serialization rules.
  • Keep runtime-only Python state and credentials out of the serialized scene when changing the serializer or adding state to binding objects.
  • Keep the Python frontend version, the bundled @deck.gl/jupyter-widget package, and the HTML CDN version aligned when changing widget or deck.gl versions.
  • Keep pydeck-carto library registration, default layer attributes, and exported CARTO layer names aligned when changing the CARTO JavaScript bundle.
  • Keep CARTO source helper field names and authentication fields aligned with the CARTO API client source contract.
  • Keep binary data metadata aligned between pandas-to-buffer conversion in pydeck and matrix deserialization in the Jupyter widget.
  • Recheck the notebook display boundary when changing Deck.show(), Deck.update(), or widget event messages because the public HTML path and lower-level widget path do not have the same behavior.
  • Keep view IDs, per-view camera keys, and SplitterWidget layout keys aligned when changing multi-view behavior.
  • Keep custom library registration fields, page-level deck.gl sharing, ESM CDN behavior, version compatibility, replacement of repeated names, import-map timing, and module-loading behavior aligned with the HTML loader when changing pydeck.settings.
  • Keep community package examples, gallery entries, thumbnail generation, and the generated image index aligned when adding or renaming a pydeck example.
  • Keep the pydeck/extensionRequires notebook loader name aligned across pydeck.json, the installed static bundle, and the Python extension-path metadata.

Important failure modes

TriggerConsequenceGuard
A CARTO layer is used before register_layers()The browser may not know the requested layer type or its default error handler.Register the CARTO library before constructing the CARTO layer.
A CARTO token, API URL, connection, table, query, or tileset is invalidThe Python scene serializes, but the browser-side data request fails and the layer does not render.Validate application credentials and source details through the CARTO-facing flow.
A notebook relies on Deck.update()The call raises NotImplementedError in the current pydeck 0.9 path.Create a new display or use the lower-level widget path where its contract applies.
A multi-view scene uses a view ID that is missing from initial_view_stateA pane can receive the wrong camera or the deck.gl default camera.Keep each view ID paired with its camera state.
A custom library bundles its own deck.gl copyThe custom layer can fail runtime type checks and be dropped.Build the library against the deck.gl already loaded on the page.
An ES module library has the wrong deck.gl minor version or fails browser module loading rulesThe library does not load, so its exported layer, extension, or widget type is unavailable.Match pydeck's deck.gl minor version and serve the module with the required MIME type and cross-origin access.
A module library uses an unsupported package subpath or loads after another ES module has runThe import map cannot resolve the dependency, so the library fails before its exports are available.Use only the shared package names and load the library before other page modules.
A community package is loaded without a compatible minor versionThe package can fail to load or render against pydeck's runtime.Use the default matching community version or pin the package to pydeck's deck.gl minor version.
The notebook loader name differs between the package metadata and pydeck.jsonThe notebook can install the extension but fail to load the front-end bundle.Keep the require target, destination, source path, and installed static file aligned.
Binary transport receives unsupported dataThe data cannot be prepared for the widget buffer.Use supported pandas numeric columns and the binary transport rules.
Offline HTML output lacks the local widget bundleThe generated page cannot create the deck.gl visualization.Build and package the pydeck notebook extension before using offline output.

Key files

FileWhy to read it
bindings/…/deck.pyDefines the scene-level Python API, view defaults, provider choices, and output paths.
bindings/…/layer.pyShows how Python layer and data descriptions enter the deck.gl configuration.
bindings/…/json_tools.pyDefines the serialization boundary shared by pydeck objects.
bindings/…/html.pyExplains notebook, Colab, browser, CDN, and offline output behavior.
bindings/…/settings.pyDefines custom JavaScript and npm library registration for the browser scene.
bindings/…/pydeck.jsonConnects the installed notebook extension to its front-end loader target.
bindings/…/widget.pyShows the Python shape for deck.gl UI widgets.
bindings/pydeck/MakefileShows how the Python package and Jupyter widget bundle are prepared, tested, and packaged together.
bindings/pydeck/docs/view.rstDescribes multi-view layouts and non-geospatial chart views.
bindings/pydeck/docs/widget.rstDescribes split views and deck.gl widgets exposed through Python.
bindings/pydeck/docs/custom_layers.rstExplains the boundary for dynamically loaded classic and ES module custom libraries.
bindings/pydeck/docs/community_libraries.rstExplains how community npm packages extend pydeck and share the deck.gl runtime.
bindings/pydeck/docs/extension.rstDescribes typed layer extensions and their Python expression limits.
bindings/pydeck/docs/CHANGELOG.rstRecords pydeck releases and changes that affect the deck.gl and browser integration contract.
bindings/pydeck/examples/01 - Introduction.ipynbGives the shortest end-to-end example of data, layers, views, widgets, notebook display, and HTML output.
bindings/…/a5_layer.pyShows a complete geospatial layer scene that reads remote indexed-cell data and writes standalone HTML.
bindings/pydeck/examples/03 - Event handlers and data selection in pydeck.ipynbShows browser selection and view-state events crossing into the Jupyter kernel.
bindings/pydeck/examples/05 - Interacting with other Jupyter widgets.ipynbShows how notebook controls can drive a visualization over time.
bindings/…/data_filter_extension.pyShows how Python configures a browser-side layer extension for data filtering.
bindings/…/terrain_extension.pyShows terrain construction and draped layers in one scene.
bindings/…/maplibre_globe.pyShows a MapLibre globe projection using the Python scene model.
bindings/…/widgets.pyShows deck.gl controls and information widgets configured from Python.
bindings/…/paris_trees.pyShows a community ES module layer used from Python.
bindings/…/scatter_plot.pyShows how pydeck can describe a non-geospatial chart without a basemap.
bindings/…/multi_view.pyShows independent cameras and a responsive inset view.
bindings/…/split_view.pyShows a draggable split layout managed by SplitterWidget.
bindings/…/layer.pyDefines the Python-to-CARTO library registration boundary.
bindings/…/sources.pyDefines CARTO table, query, and tileset source descriptions.
bindings/…/styles.pyDefines Python helpers for CARTO color rules.
modules/…/index.tsLists the CARTO layer and helper surface used by the browser runtime.