4

I'm trying to use EDN to communicate between a simple Python server and an in browser app written using ClojureScript.

So the server needs to generate and return chunks of EDN format for the browser.

I've installed https://github.com/swaroopch/edn_format which seems to be a recommended EDN library for Python.

But I want to be able to generate a map that uses Clojure symbols for keys. Eg. {:a 1 :b 2}

However, if I create a Python dictionary {"a":1, "b":2} and pass it to the dumps function, the final EDN keeps the keys as strings, not symbols.

Obviously there are no :symbols in Python. But is there a way to convince edn_format.dumps to turn dictionary string-keys into them? Or is there a better edn library for Python that can do this?

c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
interstar
  • 26,048
  • 36
  • 112
  • 180

1 Answers1

5

You can use the keyword_keys argument:

edn_format.dumps({'a': 1}, keyword_keys=True)
# => {:a 1}

Or the Keyword constructor:

edn_format.dumps({edn_format.Keyword('a'): 1})
# => {:a 1}
Aleph Aleph
  • 5,215
  • 2
  • 13
  • 28