{"id":5206,"library":"edn-format","title":"EDN Format Reader and Writer","description":"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.","status":"active","version":"0.7.5","language":"en","source_language":"en","source_url":"https://github.com/swaroopch/edn_format","tags":["EDN","serialization","deserialization","Clojure","data format"],"install":[{"cmd":"pip install edn-format","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"edn_format.loads","correct":"import edn_format\nedn_format.loads(\"[1 2 3]\")"},{"symbol":"edn_format.dumps","correct":"import edn_format\nedn_format.dumps([1, 2, 3])"},{"symbol":"edn_format.loads_all","correct":"import edn_format\nedn_format.loads_all(\"1 2 3\")"},{"note":"To explicitly create an EDN keyword in Python for dumping, use edn_format.Keyword.","wrong":"':my-key'","symbol":"edn_format.Keyword","correct":"import edn_format\nedn_format.Keyword(\"my-key\")"},{"note":"Use edn_format.Char to represent EDN character literals. It subclasses Python's `str`.","wrong":"'\\n'","symbol":"edn_format.Char","correct":"import edn_format\nedn_format.Char(\"\\n\")"}],"quickstart":{"code":"import edn_format\n\n# Define some Python data\npython_data = {\n    edn_format.Keyword('name'): 'Alice',\n    edn_format.Keyword('age'): 30,\n    edn_format.Keyword('tags'): {'python', 'edn'},\n    edn_format.Keyword('active?'): True,\n    edn_format.Keyword('notes'): edn_format.Char('\\n') # Example of EDN char literal\n}\n\n# Dump Python data to EDN string\nedn_string = edn_format.dumps(python_data, sort_keys=True, indent=2)\nprint(\"--- EDN Output ---\")\nprint(edn_string)\n# Expected output might look like:\n# {\n#   :active? true,\n#   :age 30,\n#   :name \"Alice\",\n#   :notes \\newline,\n#   :tags #{\"edn\" \"python\"}\n# }\n\n# Load EDN string back to Python data\nedn_input = \"{ :id 123 :items [\\\"apple\\\" \\\"banana\\\"] :metadata #myapp/custom {\\\"version\\\" \\\"1.0\\\"} }\"\nloaded_data = edn_format.loads(edn_input)\nprint(\"\\n--- Loaded Python Data ---\")\nprint(loaded_data)\n# Example of accessing loaded data\n# print(loaded_data[edn_format.Keyword('id')]) # 123\n# print(loaded_data[edn_format.Keyword('items')]) # ['apple', 'banana']","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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\"`.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"EDN 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"While `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}