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-formatVerified import paths — ran on the pinned version, not inferred.
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.
Be aware that modifying returned collections might not be possible directly. Convert to mutable types (e.g., `list(immutable_list)`) if mutation is required.
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"`.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.
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.
Use the correct package name `edn_format` for importing, typically `import edn_format` or `from edn_format import loads, dumps`.
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.
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.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'})`.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.
No dependency data recorded yet.