kml2geojson
A Python library to convert KML files to GeoJSON files
What it is and what it does
kml2geojson is a Python library that translates KML (Keyhole Markup Language) files into GeoJSON format. It's designed as a lightweight, dependency-minimal alternative to GDAL, with a codebase adapted from the Node.js togeojson package. The library handles standard KML elements like Placemarks, GroundOverlays, and NetworkLinks, and converts them to valid GeoJSON FeatureCollections.
Beyond basic conversion, it preserves KML styling information (colors, opacity, icons), can catalog all styles used in a document, optionally organizes output by KML folder structure, and supports typed ExtendedData via KML Schemas. It works both as a Python library and as a command-line tool (k2g), making it suitable for batch processing or integration into data pipelines. The package depends only on click for CLI support.
Use it for:
- Convert geographic data from Google Earth KML exports to GeoJSON for web mapping libraries like Leaflet or Mapbox.
- Batch-process KML files from GPS devices or survey tools into a standardized format for GIS analysis.
- Preserve KML styling (colors, icons) when migrating map data to web-based visualization platforms.
- Extract and organize nested KML folder hierarchies into separate GeoJSON FeatureCollections for layered map rendering.
- Parse KML with custom ExtendedData attributes and convert them to GeoJSON properties for downstream processing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts KML files to GeoJSON format, preserving styling, folder structure, and extended data while offering a lightweight alternative to GDAL.
Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a specific problem (KML-to-GeoJSON conversion with styling preservation) that GDAL is often overkill for. Suitable for web-focused geospatial workflows where lightweight dependencies matter.
Install
kml2geojson on PyPI
pip
pip install kml2geojsonuv
uv add kml2geojsonpoetry
poetry add kml2geojsonInstalling kml2geojson
Before you install
Installs cleanly with a single runtime dependency (click). Actively maintained with a recent release (39 days ago) and support for current Python versions (3.11+).
License in practice
MIT license permits commercial and private use with minimal restrictions—suitable for most projects that include proper attribution.
Quickstart
pip install kml2geojson
from kml2geojson import convert
result = convert('input.kml')
# result is a dict with 'feature_collections' key
# Or from CLI: k2g input.kml output.geojson
Requires Python 3.11 or later.
Verify before relying
- Performance characteristics with large KML files (file size limits, conversion speed).
- Completeness of KML 2.2 spec coverage beyond the documented feature set.
- Behavior when KML contains unsupported or malformed geometry elements.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — click |
| Maintenance | actively maintained — 39 days since the last release |
| First released | |
| Downloads | 208,019/month — #9,537 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: kml2geojson-6.0.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
osm2geojsonConverts OpenStreetMap and Overpass API data…
permissive · top 15,000 on PyPI
arcgis2geojsonConverts ArcGIS JSON format to GeoJSON format,…
permissive · top 15,000 on PyPI
fastkmlReads, writes, and manipulates KML files—an…
copyleft · top 15,000 on PyPI
geojsonEncodes, decodes, and represents GeoJSON…
permissive · top 5,000 on PyPI
geometConverts between GeoJSON, WKT/WKB, Extended…
permissive · top 5,000 on PyPI
pyulogParses ULog files (a self-describing logging…
permissive · top 15,000 on PyPI
simplekmlSimplekml generates KML (Keyhole Markup…
copyleft · top 15,000 on PyPI
plpygisConverts geometries between WKB/EWKB, WKT/EWKT,…
copyleft · top 15,000 on PyPI
cligjProvides reusable Click command-line argument…
permissive · top 5,000 on PyPI
pykmlpyKML parses and creates KML documents using a…
permissive · top 15,000 on PyPI