skillfed

kml2geojson

A Python library to convert KML files to GeoJSON files

kml2geojson v6.0.0 208.0K downloads/30d#9,537 on PyPI
Permissive license MIT Active released

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 kml2geojson

uv

uv add kml2geojson

poetry

poetry add kml2geojson

Installing 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

kml to geojson conversionkml parser pythongeographic data format conversionkml styling preservationlightweight kml convertergeojson from kml fileskml to geojson cli
geospatialformat-conversioncli-tool

More Utilities packages