Skip to main content

Simple format for serialization, similar to json. Not useful for most general use.

Project description

Simple python module for loading and dumping structures in req format, a very simple {string: (string|list(string))} format.

Parses a structure like this:



    'Foo': 'Bar',
    'Baz': [

The load and dump methods will maintain the encoding given and will not correct on errors. If you pass a utf-8 filehandle to load, you’ll get unicode output. If you pass a bytestring filehandle to load, you’ll get bytestring output. loads is the same, but with either a unicode or bytestring input. dump will try to do the same, and dumps will attempt to determine the type. All dicts and arrays are expected to be entirely homogeneous (either entirely composed of unicode strings or entirely composed of byte strings). To not enforce this in the client side is undefined, and may be an explicit error in the future. Another undefined action is to embed newlines in any strings.

The only truly ambiguous case is dumps when given an empty dict. In this case, dumps will return an empty str object, which is unicode on Python 3 and bytes on Python 2.

For structures parsed into lists, the logic is as such:

  • Any underscore and non-negative integer ending a key will automatically coerce into an list.
  • The actual values of the integers aren’t important. They will be ordered based on their decimal order. Holes and starting index aren’t bothered with.
  • If a field has an integer index given, but also has a non-indexed field of the same name, the non-indexed field will be given top precedence (essentially an index of -1)
  • Output of lists is 1-indexed by default, but this may be changed via a kwarg. If you need holes for whatever reason, you should pre-process the arrays into regular dict mappings.

This format is order-independent by default, but you may use an OrderedDict or something to maintain order on reading and writing. This does mean that dumping and loading an object (or vice versa) aren’t guaranteed to yield the exact same representation, but doing any 3 alternating operations in a row usually should.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for req, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size req-1.0.0-py2.py3-none-any.whl (5.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page