ecma426
A maintained, close-to-spec implementation of ECMA-426: Source Maps in pure Python. Supports both decoding and encoding, including index maps with sections.
Features
- Up to date — tracks the current ECMA-426 spec.
- Close to spec — code is organized around spec sections, making it easy to verify correctness.
- Pure Python — no C extensions, no dependencies.
- Both directions — decode JSON maps into Python structures, encode tokens back to valid sourcemaps.
- Sections supported — index maps (
sections) are handled according to the specification.
Installation
pip install ecma426
Usage
Top-level decode:
import json
import ecma426
with open("app.min.js.map") as f:
data = json.load(f)
smap = ecma426.loads(data)
print(smap.tokens[0])
Low-level encode / decode:
from ecma426 import codec
from ecma426.model import Mapping
tokens = [
Mapping(generated_line=0, generated_column=0, source="app.js", original_line=0, original_column=0, name=None)
]
# Encode into a sourcemap dict
smap = codec.encode(tokens)
# Decode back into a MappingIndex
decoded = codec.decode(smap)
Lookups:
# Strict lookup (exact match only, KeyError if absent)
mapping = smap[(10, 42)]
# Nearest-left lookup (will give you "something" at least for slight mismatches)
# returns the mapping at or immediately before (line, column) on the same line
mapping = smap.lookup_left(line=10, column=42)
Future work / Roadmap
We are closely watching the spec for any proposed changes.
Support for DebugIds (pass-through) is already included.
Alternatives
- python-sourcemap -- only supports decoding, no sections.
- evmar's python-sourcemap -- unmaintained (13 years old).
- Sentry's symbolic -- much more than sourcemaps; Rust dependency.
License
3-clause BSD, see LICENSE.
Metadata
Release files for ecma426 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ecma426-0.2.0.tar.gz | 15.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ecma426-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.8 kB
Release files / ecma426-0.2.0.tar.gz
| Download URL | ecma426-0.2.0.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fca8d880807f057572c4b5f8db0025f0546b641f494a08d3bdae5b2d759150f1
|
|
BLAKE2b-256 checksum How to use checksums |
abbce711d5a64bcbb679c329bd9226c3e2acb8c4e61facb58d99ae885af3e222
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / ecma426-0.2.0-py3-none-any.whl
| Download URL | ecma426-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8142bfc974f1df8072b8e03f86f4d81bdd17cf5b8fb57afbb1429a7dce81592
|
|
BLAKE2b-256 checksum How to use checksums |
e2a2be89d7dbb596890766dd5b21734a1971c6fe407a89a770043195cc2383e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|