Registry / serialization / topojson

topojson

JSON →
library1.10pypypi✓ verified 86d ago

topojson is a Python library to encode geographic data into the TopoJSON format, which encodes topology. It supports input from GeoJSON, Shapefile, GeoDataFrame, and other sources, and can output TopoJSON, GeoJSON, or GeoDataFrames. Current version is 1.10, requiring Python >=3.8. Release cadence is irregular, roughly several months between versions.

pip install topojson
INSTALL
IMPORT
SIG · TOPOJSON
T
topojson
serializationpythonv1.10
Install
4.2s avg
Import
431ms
Disk
102MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 4.3s
py 3.11
✓ —
✓ 4s
py 3.12
✓ —
✓ 3.9s
py 3.13
✓ —
✓ 3.9s
py 3.9
✕ build_error
✓ 4.9s
102MB installed
● package 102MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Topology
from topojson import Topology
topojson
import topojson
from topojson import *
Wildcard imports not recommended; use explicit imports.

Creates a Topology from a GeoJSON dict and outputs TopoJSON string.

from topojson import Topology import geopandas as gpd # Load a GeoJSON or Shapefile into a GeoDataFrame # Example: gdf = gpd.read_file('path/to/file.geojson') # Or use built-in example data = { 'type': 'FeatureCollection', 'features': [ { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'Polygon', 'coordinates': [[[0,0],[1,0],[1,1],[0,1],[0,0]]] } } ] } topo = Topology(data, prequantize=False) topojson_str = topo.to_json() print(topojson_str[:200])
Debug
Known issues
gotchaInput data order is not preserved in the output TopoJSON. Topology is computed based on shared arcs, and feature order may change.
fix
Do not rely on feature ordering; use properties to identify features.
affects: all
breakingIn version 1.9, the `ignore_index` parameter was introduced. By default, feature ids from GeoJSON source are kept unless duplicates exist. This changes previous behavior where ids were always dropped.
fix
Set `ignore_index=True` in `Topology()` to restore old behavior of ignoring ids.
affects: >=1.9
gotchaWhen using `prequantize=True` (default), coordinates are quantized to integers, which may reduce precision but also reduces file size. For lossless topology, set `prequantize=False`.
fix
Use `Topology(data, prequantize=False)` for exact coordinate preservation.
affects: all
deprecatedIn version 1.6, deprecated NumPy functions (e.g., `np.in1d`) were replaced. Issues may arise with older NumPy versions.
fix
Update NumPy to a recent version (>=1.20).
affects: >=1.6
Errors
Common errors & fixes
TypeError: __init__() got an unexpected keyword argument 'ignore_index'
Using `ignore_index` parameter with topojson version <1.9.
fix
Upgrade topojson: `pip install --upgrade topojson`
ValueError: Input data must be a dict with 'type' and 'features' keys or a GeoDataFrame
Passing an unsupported data format (e.g., plain list of coordinates).
fix
Wrap input in a GeoJSON FeatureCollection dict or use a GeoDataFrame.
AttributeError: module 'topojson' has no attribute 'Topology'
Importing incorrectly (e.g., `import topojson` then using `topojson.Topology` but the module may not expose the class directly in old versions).
fix
Use `from topojson import Topology`.
Upgrade
Version history
1.10latest on PyPI · released Jul 22, 2025
Audit
Dependencies
numpyrequiredArray computations
shapelyrequiredGeometry operations
pandasrequiredDataFrame handling
geopandasoptionalGeoDataFrame input/output
fionaoptionalShapefile reading
simplejsonoptionalJSON serialization
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
topojson — pip install topojson · libregistry