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

CartoSym-CSS, CS-JSON, MapLibre and the CQL2 API work with the core dependencies. SLD/SE needs the sld extra (pip install "pycartosym[sld]", or [all]).

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

# Convert (`convert` is the default command, so `cartosym convert IN -o OUT` is the same).
# Formats come from the file extensions; a .json or .xml input is recognised
# from its content.
cartosym <input-file> -o <output-file>

# Without -o (or with -o -), the result goes to stdout; .cscss <-> .cs.json by default
cartosym <input-file>

# Explicit formats: -f/--from and -t/--to (also --from-format/--to-format)
cartosym <input-file> -t <sld|sld:1.0.0|sld:geoserver|maplibre|cscss|csjson> -o <output-file>

# From stdin (the format is recognised from the content)
cat style.cscss | cartosym - -t maplibre

# Several files into a folder (-t names the target format)
cartosym styles/*.cscss -t csjson -o out/

# Check .cscss files against the grammar, .cs.json files against their schema,
# .sld files against the OGC schemas (SLD 1.0.0, SLD/SE 1.1.0) and
# .maplibre.json files with the specification's validator; --validate checks an
# SLD/SE or MapLibre input before converting it, and the output
cartosym validate <file> [<file> ...]

# Fail (exit status 6) when the conversion drops or cannot convert something;
# the warnings say what, and the output is still written
cartosym <input-file> -o <output-file> --strict

# Full option and format reference (also: python -m pycartosym --help)
cartosym --help
cartosym convert --help

Exit statuses: 0 success, 1 usage, 2 file not found, 3 invalid input (or output with --validate), 4 unsupported conversion, 5 a construct the target format cannot express, 6 warnings with --strict. With several inputs, the highest status of them.

SLD/SE validation needs the sld extra (lxml), as SLD conversion does; GeoServer <VendorOption>s are accepted where GeoServer reads them. MapLibre validation runs the specification's own validator (version 27.0.0, shipped in the package) with Node.js 22.13 or later; nothing is downloaded, and Node runs it under its permission model, with read access to the style only.

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 -t sld -o out.sld
cartosym examples/sld/1-polygon-fill-stroke.sld -t 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.8.1

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.8.1
File Size Uploaded Provenance Actions
pycartosym-0.8.1.tar.gz 599.3 kB With provenance Details for pycartosym-0.8.1.tar.gz

Built distribution (wheel)

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

Total release size: 1.1 MB

Release files / pycartosym-0.8.1.tar.gz

Download URL pycartosym-0.8.1.tar.gz
Size 599.3 kB
Tags Source
SHA-256 checksum
How to use checksums
382eabd7284b12692e38d86e1dc9126218d7c8104d61a3973315b7a7761ff131
BLAKE2b-256 checksum
How to use checksums
5181c3018513b1ae4d073e99f326aca85d85569cdb5c127ceee0e43a1ee925f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

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

Download URL pycartosym-0.8.1-py3-none-any.whl
Size 533.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90b2a6d28ba453975fd4f346b7630b495545c0176baf2cc7175f157cf57a81ed
BLAKE2b-256 checksum
How to use checksums
7ccac077310d1b2de07860a4fe98f9cdb1ba5e79f8a00e868fa0f951e5443834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Security for pycartosym 0.8.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pycartosym-0.8.1.tar.gz

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 Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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