Skip to main content

ent

https://travis-ci.org/jreese/ent.svg?branch=master

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 and yaml modules to automatically convert to and from Ent objects and raw JSON/YAML:

> from ent import json, yaml

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

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

> yaml.safe_load('bar: null\nfoo: true\n')
<Ent {'foo': True, 'bar': None}>

> yaml.dump(Ent(foo=True, bar=None))
u'baz: 1\nfoo: bar\n'

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 using the standard json module:

import json

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

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

We can do better with ent:

from ent import json

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

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

install

ent is compatible with Python 2.7+ and Python 3.3+. You can install it from PyPI with the following command:

$ pip install ent

license

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

Metadata

Release files for ent 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ent 0.3.3
File Size Uploaded Provenance
ent-0.3.3.tar.gz 5.5 kB Without provenance Details

Release files / ent-0.3.3.tar.gz

Download URL ent-0.3.3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fef020d2f7db222fee188e7b6be92c8e0c5f94029848f0a89c9dff057c3bc7bc
BLAKE2b-256 checksum
How to use checksums
4f37ab1179bbd7276a25c37fc442edbb626f12e57ff69c94eaff3a84d7ae7bc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ent 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page