Registry / serialization / kml2geojson

kml2geojson

JSON →
library5.1.1pypypi✓ verified 85d ago

kml2geojson is a Python library that converts KML files to GeoJSON format. Current version is 5.1.1. Actively maintained.

pip install kml2geojson
INSTALL
IMPORT
SIG · KML2GEOJSON
K
kml2geojson
serializationpythonv5.1.1
Install
1.6s avg
Import
76ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.1.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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.082s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.070s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

convert
from kml2geojson import convert
import kml2geojson
Function convert is not a top-level attribute of the module.

Convert a KML file to GeoJSON object.

from kml2geojson import convert import os kml_path = 'path/to/file.kml' if not os.path.exists(kml_path): print("KML file not found.") else: geojson = convert(kml_path) # geojson is a dict that can be written as GeoJSON import json with open('output.geojson', 'w') as f: json.dump(geojson['features'] if 'features' in geojson else geojson, f)
kml2geojson --version
Debug
Known issues
breakingVersion 5.0.0 changed input/output: convert() now returns a dict instead of writing to file. Old code that expected file output will break.
fix
Update code to handle return value as dict.
affects: >=5.0.0
gotchaInput KML must be a file path or file-like object. Direct XML strings are not supported.
fix
Write XML string to a temporary file or use io.StringIO with proper encoding.
affects: all
deprecatedPython 3.11 minimum is required in version 5.1.1. Older versions (pre-5.0) supported Python 3.6+.
fix
Use Python 3.11 or newer.
affects: >=5.1.0
Errors
Common errors & fixes
TypeError: expected str, bytes or os.PathLike object, not dict
convert() takes a file path, not a dict.
fix
Pass a file path string to convert(), not a parsed KML dict.
KeyError: 'features'
Output may not have a 'features' key if the GeoJSON is a single feature or non-standard.
fix
Check the structure: geojson['features'] if 'features' in geojson else geojson.
Upgrade
Version history
5.1.1latest on PyPI · released Mar 12, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
kml2geojson — pip install kml2geojson · libregistry