Skip to main content

pycartosym

CI PyPI Python versions License

A Python package for lossless transcoding between CartoSym CSS (.cscss) and other encodings of the OGC Cartographic Symbology conceptual model (CS-JSON, SLD/SE), plus MapLibre Style as a practical interoperability target.

Supported Formats

CartoSym-CSS (.cscss) and CS-JSON (.cs.json) are the two OGC Cartographic Symbology encodings this package reads and writes losslessly. SLD/SE (.sld, 1.1.0 and 1.0.0, including SLD 1.0.0 with GeoServer <VendorOption> pass-through) is also OGC. MapLibre Style (.json) is the MapLibre/Mapbox de facto spec, not OGC, supported as a practical interoperability target. All are read and written.

Each codec is covered for the constructs the target format actually expresses (a symbolizer or property with no equivalent on the other side raises rather than silently dropping data).

Installation

From PyPI

pip install pycartosym

From Source

git clone https://github.com/maxcollombin/pycartosym.git
cd pycartosym
uv sync --all-extras

The generated ANTLR lexer/parser are already committed under src/pycartosym/grammar/generated/, so no separate grammar build step is needed. Prefix commands with uv run, or activate the project's .venv with source .venv/bin/activate.

Usage

# Format auto-detected from the file extensions where that's unambiguous
cartosym <input-file> -o <output-file>

# Explicit target format (needed for the SLD dialects and MapLibre,
# since a plain .sld/.json extension can't disambiguate those)
cartosym --to-format <sld|sld:1.0.0|sld:geoserver|maplibre|cscss|csjson> <input-file> -o <output-file>

# Display structure info for a CSCSS file, without converting it
cartosym parse <input-file>

# Validate a .cscss or .cs.json file against the grammar/JSON schema
cartosym validate <input-file>

# Full option and format reference
cartosym --help

A few concrete conversions, using the files under examples/ (examples/sld/ for SLD/SE):

cartosym examples/0-basic.cscss -o out.cs.json
cartosym examples/13-vector-point-circle.cscss --to-format sld -o out.sld
cartosym examples/sld/1-polygon-fill-stroke.sld --to-format maplibre -o out.json

Python API

Most users work through the cartosym CLI above. The cql2 submodule also exposes CQL2 (the OGC 21-065r2 query-expression sublanguage that CartoSym-CSS embeds in [ filter ] selectors and CS-JSON encodes as {"op": …, "args": …}) as a stable, importable API:

from pycartosym import cql2

# CQL2-Text -> expression model
expr = cql2.parse_text("population > 1000")

# Expression model -> CQL2-JSON
cql2.to_cql2_json(expr)
# {'op': '>', 'args': [{'property': 'population'}, 1000]}

# CQL2-JSON selector dict -> CartoSym-CSS filter text
cql2.to_cql2_text({
    "op": "and",
    "args": [
        {"op": "=", "args": [{"property": "a"}, 1]},
        {"op": "like", "args": [{"property": "b"}, "x%"]},
    ],
})
# "a = 1 and b like 'x%'"

# Operator/function vocabulary, derived from the CQL2 Pydantic models
cql2.vocab.SPATIAL_RELATE                       # 's_relate'
"s_intersects" in cql2.vocab.KNOWN_CQL2_CALLS   # True

cql2.parse_tree is a lower-level entry point for converting an already-parsed ANTLR expression context (as produced while walking the CartoSym-CSS grammar) — most callers want parse_text.

Development

uv sync --all-extras
uv run pytest

License

See LICENSE.

Metadata

Release files for pycartosym 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycartosym 0.5.0
File Size Uploaded
pycartosym-0.5.0.tar.gz 363.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycartosym 0.5.0
File Interpreter ABI Platform
pycartosym-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 654.1 kB

Release files / pycartosym-0.5.0.tar.gz

Download URL pycartosym-0.5.0.tar.gz
Size 363.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a2d9abc322fc5ba732e73489bb9d1679dca5579dc684729a7259f93403720c0f
BLAKE2b-256 checksum
How to use checksums
ae7c38d51b384bbd225036e8b12f28fe30ed4c11ab6a33a865cec1192d152733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / pycartosym-0.5.0-py3-none-any.whl

Download URL pycartosym-0.5.0-py3-none-any.whl
Size 291.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bfddd8564e3311bbc244e331f4c181bd9db2aa98faf0454bc7a185a8030af45
BLAKE2b-256 checksum
How to use checksums
5e3fd4eab2f6728b8236aca76698fc743ea0cb44fed7bb9d1aaea93a3a39120c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page