Giter VIP home page Giter VIP logo

stringly's Introduction

Stringly: Human Readable Object Serialization

Stringly aims to facilitate foreign function calls into Python by providing human readable serialization and de-serialization of arbitrary Python objects.

Stringly is similar to Python's pickle protocol in that the serialized form follows directly from class introspection. This as opposed to serialization technologies such as JSON and YAML, which are self contained but support only a predefined set of data types. Similar to those technologies, however, and unlike pickle, the resulting strings are human readible and human writable.

A typical use case of stringly is as part of a command line parser, using the stringly representation to instantiate objects direcly from the command line.

Example

Stringly requires type hints to infer object types. Since these are getting more and more common, chances are that stringly will work directly out of the box. In case extra work is required, the reward is double as this effort should also benefit static type checkers such as mypy.

The following is an example of a class that is suitable for stringlification:

>>> import typing, dataclasses, stringly
>>>
>>> @dataclasses.dataclass
... class A:
...   name: str
...   data: typing.Dict[str,int]

Objects are serialized using stringly.dumps:

>>> a = A('hi', {'foo': 1, 'bar': 2})
>>> stringly.dumps(A, a)
# 'name=hi,data={foo=1,bar=2}'

Objects are de-serialized using stringly.loads:

>>> a = stringly.loads(A, 'name=bye,data={baz=3}')
>>> a.name
# 'bye'
>>> a.data
# {'baz': 3}

stringly's People

Contributors

gertjanvanzwieten avatar joostvanzwieten avatar

Stargazers

Oromion avatar Benji York avatar

Watchers

James Cloos avatar  avatar  avatar Wijnand Hoitinga avatar

stringly's Issues

prettify directly nested scopes

Currently a stringly of the type "key={{value1},{value2},{value3}}" cannot be elegantly prettified. Perhaps we can invent syntax to mark a double indent after key, as well as a renewed scope after value1, value2.

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.