Skip to main content

library for creating arbitrary data structures

Project description

ent
===

[![Build Status](https://travis-ci.org/jreese/ent.svg?branch=master)](https://travis-ci.org/jreese/ent)


`ent` is a basic framework for generating attribute-based data structures from
dictionary-like data sources:

> from ent import Ent

> obj = Ent(foo='foo', bar=None)

> obj.foo
u'foo'

> obj.bar
None

`ent` can contain arbitrarily-nested hierarchies, as long as every node/leaf
is either a primitive type, or an ent:

> obj = Ent({
'foo': 'bar',
'list': [1, 2, 3, 4],
'inner': {
'foo': 'baz',
'bar': 'bang',
},
'ent': Ent(foo='bar'),
})

> obj.foo
u'bar'

> obj.list[2]
3

> obj.inner.foo
u'baz'

`ent` can be merged and diffed, and it will even enforce types when merging
keys that are shared:

> ent1 = Ent(foo=1, bar=True)

> ent2 = Ent(foo='hi', bar=False, goo='win')

> Ent.merge(ent1, ent2)
<Ent {'foo': 1, 'bar': False}>

> Ent.diff(ent1, ent2)
<Ent {'bar': False}>

`ent` even provides a stand-in for the `json` module to automatically convert
to and from Ent objects and raw JSON:

> from ent import json

> json.loads('{"foo": true, "bar": null}')
<Ent {'foo': True, 'bar': None}>

> json.dumps(Ent(foo=True, bar=None))
u'{"foo": true, "bar": null}'


why
---

When working with configs, or other content pulled from sources like JSON, it
can be really annoying to need to constantly use brackets to access nested
data structures.

Let's say we have a small JSON file containing my personal profile:

{
"name": "John Reese",
"urls": {
"blog": "https://noswap.com",
"github": "https://github.com/jreese",
"facebook": "https://www.facebook.com/nucleareclipse"
}
}

Now let's read in that data and print some of it out:

import json

with open(...) as f:
data = json.load(f)

name = data['name']
url = data['urls']['github']

We can do better:

from ent import json

with open(...) as f:
data = json.load(f)

name = data.name
url = data.urls.github


license
-------

ent is copyright 2015 John Reese, and is licensed under the MIT license.

Project details


Download files

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

Source Distribution

ent-0.2.3.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file ent-0.2.3.tar.gz.

File metadata

  • Download URL: ent-0.2.3.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ent-0.2.3.tar.gz
Algorithm Hash digest
SHA256 70afe39076995a91feef471f6d7c9cb956bd1e3c718bd29e000926234eba4e6e
MD5 caa695565ff4248c6730e2f03d451a9b
BLAKE2b-256 b0351ac081d4041ca38630bed1b186b5929e2888caf2234da8a54cec6d2d3ffb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page