Registry / serialization / edn-format

edn-format

JSON →
library0.8.0pypypi✓ verified 23d ago

edn-format is a Python library that implements the Extensible Data Notation (EDN) format, providing functionalities to read (loads, loads_all) and write (dumps) EDN data, including support for custom tagged elements. The current version, 0.7.5, was released in November 2020, and the project is considered stable and actively maintained on GitHub, despite a less frequent release cadence.

pip install edn-format
INSTALL
IMPORT
SIG · EDN-FORMAT
E
edn-format
serializationpythonv0.8.0
Install
1.8s avg
Import
152ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.158s · 21.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.146s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

edn_format.loads
import edn_format edn_format.loads("[1 2 3]")
edn_format.dumps
import edn_format edn_format.dumps([1, 2, 3])
edn_format.loads_all
import edn_format edn_format.loads_all("1 2 3")
edn_format.Keyword
import edn_format edn_format.Keyword("my-key")
':my-key'
To explicitly create an EDN keyword in Python for dumping, use edn_format.Keyword.
edn_format.Char
import edn_format edn_format.Char("\n")
'\n'
Use edn_format.Char to represent EDN character literals. It subclasses Python's `str`.

This quickstart demonstrates how to serialize Python dictionaries containing various EDN types (keywords, sets, booleans, character literals) into an EDN string using `edn_format.dumps`, and then deserialize an EDN string back into Python data using `edn_format.loads`. It highlights the use of `edn_format.Keyword` and `edn_format.Char` for explicit EDN type representation.

import edn_format # Define some Python data python_data = { edn_format.Keyword('name'): 'Alice', edn_format.Keyword('age'): 30, edn_format.Keyword('tags'): {'python', 'edn'}, edn_format.Keyword('active?'): True, edn_format.Keyword('notes'): edn_format.Char('\n') # Example of EDN char literal } # Dump Python data to EDN string edn_string = edn_format.dumps(python_data, sort_keys=True, indent=2) print("--- EDN Output ---") print(edn_string) # Expected output might look like: # { # :active? true, # :age 30, # :name "Alice", # :notes \newline, # :tags #{"edn" "python"} # } # Load EDN string back to Python data edn_input = "{ :id 123 :items [\"apple\" \"banana\"] :metadata #myapp/custom {\"version\" \"1.0\"} }" loaded_data = edn_format.loads(edn_input) print("\n--- Loaded Python Data ---") print(loaded_data) # Example of accessing loaded data # print(loaded_data[edn_format.Keyword('id')]) # 123 # print(loaded_data[edn_format.Keyword('items')]) # ['apple', 'banana']
Debug
Known issues
gotchaThe library, following EDN's rationale, aims to yield immutable Python data structures (e.g., tuples for lists, frozensets for sets, ImmutableDict for maps) where possible. This can be unexpected for Python developers accustomed to mutable lists and dictionaries.
fix
Be aware that modifying returned collections might not be possible directly. Convert to mutable types (e.g., `list(immutable_list)`) if mutation is required.
affects: All versions
gotchaWhen serializing Python dictionaries, string keys will be dumped as EDN strings, not EDN keywords. To output EDN keywords for dictionary keys, you must explicitly use `edn_format.Keyword('your-key')` as the Python dictionary key.
fix
Use `edn_format.Keyword()` for dictionary keys if EDN keyword output is desired. Example: `edn_format.dumps({edn_format.Keyword('my-key'): 'value'})` will output `:my-key "value"`.
affects: All versions
gotchaEDN is a human-readable data format, and implementations like `edn-format` may not offer the same performance characteristics (speed and memory usage) as highly optimized binary serialization formats or even standard JSON libraries for high-throughput data transfer scenarios. For wire protocols, alternatives like Cognitect Transit might be more suitable.
fix
Evaluate performance requirements. For high-performance serialization, consider formats and libraries designed for that purpose. For durable storage or human-readable configurations, `edn-format` is generally suitable.
affects: All versions
gotchaWhile `edn-format` supports custom tagged literals, correctly implementing and registering reader/writer handlers for them can be complex and requires a good understanding of both the EDN specification and the library's extension mechanisms.
fix
Refer to the library's documentation or source for examples on how to register custom tag handlers (`edn_format.add_tag`). Ensure consistency between reading and writing implementations of custom types.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'edn'
The user is attempting to import the `edn-format` library using a shortened name (`edn`) instead of its correct package name (`edn_format`).
fix
Use the correct package name `edn_format` for importing, typically `import edn_format` or `from edn_format import loads, dumps`.
WARNING: Couldn't open 'parser.out'. [Errno 30] Read-only file system: '.../edn_format/parser.out'
The `edn-format` library, which uses PLY, attempts to create or write cached parser tables (`parser.out`, `edn_format.parsetab`) in its installation directory. This error occurs in read-only environments (e.g., Docker containers, some virtual environments, or system-wide installations without write permissions).
fix
These are generally warnings and often don't prevent the library from working. To prevent them, ensure the environment has write permissions during the initial import/use of `edn_format`, or pre-generate the parser tables in a writable environment before deploying to a read-only one. Setting the `PYTHONHASHSEED` environment variable to a fixed value can also help with consistent `parsetab.py` generation.
edn_format.exceptions.EDNParseError: Expected ... but got ...
The input EDN string provided to `edn_format.loads()` or `edn_format.loads_all()` is syntactically incorrect or malformed according to the EDN specification, such as having unclosed delimiters, misplaced commas, or invalid characters.
fix
Carefully inspect the EDN input string for syntax errors. Ensure all opening delimiters like `(`, `[`, `{`, `#_`, `#` have their corresponding closing characters and that the data structure adheres to EDN rules for elements like keywords, symbols, and tagged elements.
Python dictionary string keys are not converted to EDN keywords/symbols when using `edn_format.dumps()`.
By default, `edn_format.dumps()` serializes Python dictionary string keys directly as EDN strings, not as Clojure-style EDN keywords (e.g., `:key`) or symbols (e.g., `key`).
fix
To output EDN keywords or symbols, explicitly convert the Python string keys to `edn_format.Keyword` or `edn_format.Symbol` objects before passing the dictionary to `edn_format.dumps()`. For example, `edn_format.dumps({edn_format.Keyword('mykey'): 'value'})`.
Incorrectly handling or reading custom EDN tagged elements.
When `edn-format` encounters a custom tagged element (e.g., `#myapp/Person {:name "Alice"}`), it either represents it as a generic `edn_format.TaggedElement` object or raises an error if no custom reader function has been registered for that specific tag.
fix
Register a custom function to handle specific EDN tags using `edn_format.add_tag(tag_name, handler_function)`. The handler function will receive the value of the tagged element and should return the desired Python object representation.
Upgrade
Version history
0.8.0latest on PyPI · released Jul 21, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources