Install & Compatibility
Where this runs
tested against v3.3.0 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Point
✓ from geojson import Point
LineString
✓ from geojson import LineString
Polygon
✓ from geojson import Polygon
Feature
✓ from geojson import Feature
FeatureCollection
✓ from geojson import FeatureCollection
dumps
✓ from geojson import dumps
loads
✓ from geojson import loads
✗ import json; json.loads(...)
Using `json.loads` directly will return a plain dictionary, losing the GeoJSON object methods and attributes. Use `geojson.loads` for richer objects.
dump
✓ from geojson import dump
load
✓ from geojson import load
✗ import json; json.load(...)
Using `json.load` directly will return a plain dictionary, losing the GeoJSON object methods and attributes. Use `geojson.load` for richer objects.
This quickstart demonstrates how to create common GeoJSON objects like `Point`, `Feature`, and `FeatureCollection`, and then serialize them into a GeoJSON formatted string using `geojson.dumps`.
from geojson import Point, Feature, FeatureCollection, dumps
# Create a Point geometry
point = Point((-115.81, 37.24))
# Create a Feature with the Point geometry and properties
feature = Feature(geometry=point, properties={"name": "Area 51"})
# Create a FeatureCollection containing the feature
feature_collection = FeatureCollection([feature])
# Serialize the FeatureCollection to a GeoJSON string with indentation
geojson_str = dumps(feature_collection, indent=2)
print(geojson_str)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'geojson'
The 'geojson' library is not installed in the Python environment where you are running your code, or the environment is not correctly activated.
fixInstall the package using pip: `pip install geojson` (or `pip3 install geojson` for Python 3 specific installations).
ValueError: Expected 0 or more linear rings, got (...)
This error occurs when creating a `geojson.Polygon` object because the coordinates are not nested correctly according to the GeoJSON specification. A Polygon's coordinates should be a list of linear rings, where each linear ring is itself a list of coordinate pairs, and the first and last coordinate pair of each linear ring must be identical. A common mistake is providing a single linear ring as a direct list of points instead of a list containing that list.
fixEnsure the coordinates for a `Polygon` are a list of lists of `(longitude, latitude)` tuples. For a simple polygon, it should be `[[exterior_ring_coords]]`. Example: `geojson.Polygon([[(0, 0), (1, 1), (1, 0), (0, 0)]])`
AttributeError: 'str' object has no attribute '_geom'
This error typically arises when you are attempting to perform a geospatial operation (often with a library like Shapely) that expects a geometry object, but you are instead providing a raw GeoJSON string. The `_geom` attribute is internal to some geometry libraries and is not present on a standard Python string.
fixIf you have a GeoJSON string, you need to parse it into a Python GeoJSON object (or a Shapely geometry object) before using it in operations that expect a geometry. Use `geojson.loads(json_string)` to get a `geojson` object, or `shapely.geometry.shape(geojson.loads(json_string))` to get a Shapely object.
AttributeError: 'Map' object has no attribute 'GeoJson'
This error occurs when attempting to add GeoJSON data to a Folium map using a non-existent method or attribute. In Folium, `GeoJson` is a separate class used to create a GeoJSON layer, which is then added to the map using `add_to()` or `add_child()`, not by directly accessing an attribute on the map object.
fixCreate a `folium.GeoJson` object separately and then add it to your map instance. Example: `geojson_data = geojson.loads(my_geojson_string)`; `folium.GeoJson(geojson_data).add_to(my_map)` or `my_map.add_child(folium.GeoJson(geojson_data))`.
Upgrade
Version history
3.3.0latest on PyPI · released May 28, 2026
Audit
Dependencies
No dependency data recorded yet.