Giter Club home page Giter Club logo

pyclj's Introduction

pyclj

A python reader/writer for clojure data literals. On clojure's extensible data notations, checkout Rich Hickey's edn spec: https://github.com/richhickey/edn

Install

pip install pyclj

Usage

The API is very similar to python's built-in json module.

  • dump(data, fileobj)
  • dumps(data)
  • load(fileobj)
  • loads(string)

Clojure -> Python Type Mapping

Clojure Python
list list
vector list
set set
map dict
nil None
string string
int int
float float
boolean boolean
char string
keyword string

Python -> Clojure Type Mapping

Python Clojure
list vector
set set
dict map
None nil
string string
int int
float float
boolean boolean

License

pyclj is distributed under MIT license.

pyclj's People

Contributors

bhagany avatar mattbierbaum avatar sunng87 avatar tobereplaced avatar wlabelle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyclj's Issues

Decoder does not handle type "object"

I have a response that returns the following syntax

#object[<namespace>.<record> <hex_number> "<edn>"]

Here is a sample output

#object[com.example.funktown.DoubleEntity 0x66c5e52e "{:my/keyword1 :my/keyword2, :keyword3 1462827186240, :my/keyword3 \"This is a string\", :my/key5 #inst \"1970-01-01T00:00:00.000-00:00\"}"]

However, calling clj.loads(data) with the above fails with the following:

>>> data = '#object[com.example.funktown.DoubleEntity 0x66c5e52e "{:my/keyword1 :my/keyword2, :keyword3 1462827186240, :my/keyword3 \"This is a string\", :my/key5 #inst \"1970-01-01T00:00:00.000-00:00\"}"]'
>>> clj.loads(data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/clj.py", line 407, in loads
    result = load(buf)
  File "/usr/lib/python2.7/site-packages/clj.py", line 403, in load
    return decoder.decode()
  File "/usr/lib/python2.7/site-packages/clj.py", line 82, in decode
    v = self.__read_token()
  File "/usr/lib/python2.7/site-packages/clj.py", line 263, in __read_token
    raise ValueError('Unexpected char: "%s" at line %d, col %d' % (c, self.cur_line, self.cur_pos))
ValueError: Unexpected char: "#" at line 1, col 1

I'm not familiar with clojure well enough, but it would be nice to handle the type object. Or maybe provide function that would return only the the EDN data structure.

Example of usage?

Hi,

I wonder if you have a project where you show an example of how this library can be used to communicate with a running clojure process.

Check invalid boolean literal

pyclj just ignores invalid boolean literal.

it's better to raise a ValueError in this condition

clj.loads("[tits fool not :this@is@wrong lolwut]")
[True, False, None, True, None, None, None, None, None, None, None, None, None, None, None, None, None, None, True]

Support tuple

Add tuple encoder. Tuple should be encoded as clojure vector.

Version 0.3.0 disappeared from PyPi

From at least July 2014 until yesterday (17 June 2015), I had pyclj==0.3.0 in my requirements file for a project. However, version 0.3.0 seems to have completely disappeared from PyPi: where did it go?

I'm falling back on pyclj==0.2.2 since the latest release here on Github is that version, but I'm crossing my finger that this won't break the Python datomic package.

No module named 'cStringIO'

>>> import clj
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.3/site-packages/clj.py", line 47, in <module>
    from cStringIO import StringIO
ImportError: No module named 'cStringIO'

symbols?

Is there no support for symbols? The loads method is choking on all edn with symbols that I give it.

Human-readable pretty-printing

Currently clj.dumps provides a single-line dump. For large datasets this can limit human readability.

The simplistic solution taken by json is to add an indent keyword and to supply a newline plus suitable indentation for every element of every iterable.

A nicer solution is to try to hit a certain line width. This is done, for example, by the ipython interpretter.

New namespaced map syntax in Clojure 1.9 alphas

Clojure is adding a new shorthand syntax feature for maps with namespaced keys, and it uses this syntax for EDN as well. For example:

user> (pr-str {:foo/bar :foobar :foo/baz :foobaz})
"#:foo{:bar :foobar, :baz :foobaz}"

It would be very helpful for me to have this syntax supported, and I hope to send you a pull request for it soon.

Bug in parsing values in a vector/list/whatever.

>>> clj.loads('[23[]]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "clj.py", line 293, in loads
    result = load(buf)
  File "clj.py", line 289, in load
    return decoder.decode()
  File "clj.py", line 61, in decode
    v = self.__read_token()
  File "clj.py", line 159, in __read_token
    v = number(numstr)
  File "clj.py", line 50, in number
    return int(v)
user=> [23[]]
[23 []]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.