Skip to main content

More Dots!

PyPI Latest Release Build Status Coverage Status Downloads

Overview

Box your JSON-like data in a Data object to get null-safe dot access. This library is a replacement for dict that is more consistent and easier to use.

See full documentation for all the features of mo-dots

See change log to read about major changes

Create instances

Define Data using named parameters, just like you would a dict

>>> from mo_dots import Data
>>> Data(b=42, c="hello world")
Data({'b': 42, 'c': 'hello world'})

You can also box an existing dicts so they can be used like Data

>>> from mo_dots import to_data
>>> to_data({'b': 42, 'c': 'hello world'})
Data({'b': 42, 'c': 'hello world'})

Dot Access

Access properties with attribute dots: a.b == a["b"]. You have probably seen this before.

Path Access

Access properties by dot-delimited path.

>>> a = to_data({"b": {"c": 42}})
>>> a["b.c"] == 42
True

Null-Safe Access

If a property does not exist then return Null rather than raising an error.

>>> a = Data()
>>> a.b == Null
True
>>> a.b.c == Null
True
>>> a[None] == Null
True

Path assignment

No need to make intermediate dicts

>>> a = Data()
>>> a["b.c"] = 42   # same as a.b.c = 42
a == {"b": {"c": 42}}

Path accumulation

Use += to add to a property; default zero (0)

>>> a = Data()
a == {}
>>> a.b.c += 1
a == {"b": {"c": 1}}
>>> a.b.c += 42
a == {"b": {"c": 43}}

Use += with a list ([]) to append to a list; default empty list ([])

>>> a = Data()
a == {}
>>> a.b.c += [1]
a == {"b": {"c": [1]}}
>>> a.b.c += [42]
a == {"b": {"c": [1, 42]}}

Serializing to JSON

The standard Python JSON library does not recognize Data as serializable. You may overcome this by providing default=from_data; which converts the data structures in this module into Python primitives of the same.

from mo_dots import from_data, to_data

s = to_data({"a": ["b", 1]})
result = json.dumps(s, default=from_data)  

Alternatively, you may consider mo-json which has a function value2json that converts a larger number of data structures into JSON.

Summary

This library is the basis for a data transformation algebra: We want a succinct way of transforming data in Python. We want operations on data to result in yet more data. We do not want data operations to raise exceptions. This library also solves Python's lack of consistency (lack of closure) under the dot (.) and slice [::] operators when operating on data objects.

Full documentation

Download files

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

Source Distribution

mo_dots-10.688.26234.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mo_dots-10.688.26234-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file mo_dots-10.688.26234.tar.gz.

File metadata

  • Download URL: mo_dots-10.688.26234.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mo_dots-10.688.26234.tar.gz
Algorithm Hash digest
SHA256 dfcfc0a93c53b1cce2c2be24418af67934008ae1305a064a48e6c9a3e76b55ac
MD5 00168fb4fa8c180629659e6e5c23573c
BLAKE2b-256 7275c6d32ba3253f244372f371fc42866a67eb49d7f1991fe6af1a5dea5f0947

See more details on using hashes here.

File details

Details for the file mo_dots-10.688.26234-py3-none-any.whl.

File metadata

  • Download URL: mo_dots-10.688.26234-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for mo_dots-10.688.26234-py3-none-any.whl
Algorithm Hash digest
SHA256 72d5125c0b114b88cbcf6bcd3cf2afd035a14dac44bae06bbc73e0e7042dba59
MD5 b91193554368679f5b1b01d8f6bc5dd1
BLAKE2b-256 d50cfdb876c193e3888ff8cd0824eef66596f1e6c7d80bff9e9bd4537556edd7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

10.688.26234 This release

2 files

10.687.26234

2 files

10.686.26234

2 files

10.685.25166

2 files

10.678.25061

2 files

10.677.25059

2 files

10.672.25036

2 files

10.671.25036

2 files

10.659.25005

2 files

10.647.24166

2 files

10.645.24152

2 files

10.632.24139

2 files

10.630.24136

2 files

10.627.24136

2 files

10.623.24125

2 files

10.622.24125

2 files

10.621.24125

2 files

10.615.24125

2 files

10.614.24125

2 files

10.613.24121

2 files

10.612.24121

2 files

10.611.24120

2 files

9.606.24115

2 files

9.605.24115

2 files

9.603.24115

2 files

9.602.24115

2 files

9.601.24115

2 files

9.600.24114

2 files

9.596.24113

2 files

9.595.24112

2 files

9.594.24112

2 files

9.593.24112

2 files

9.592.24112

2 files

9.584.24095

2 files

9.582.24095

2 files

9.578.24081

2 files

9.574.24078

2 files

9.570.24076

2 files

9.565.24076

2 files

9.564.24076

2 files

9.563.24076

2 files

9.562.24075

2 files

9.549.24062

2 files

9.547.24058

2 files

9.543.24046

2 files

9.541.24038

2 files

9.531.24035

2 files

9.530.24035

2 files

9.527.24034

1 file

9.520.24032

1 file

9.508.24028

1 file

9.502.24024

1 file

9.499.24023

1 file

9.491.24021

1 file

9.490.24021

1 file

9.476.24007

1 file

9.474.24004

1 file

9.455.23316

1 file

9.450.23304

1 file

9.440.23265

1 file

9.430.23234

1 file

9.428.23214

1 file

9.417.23168

1 file

9.408.23161

1 file

9.401.23144

1 file

9.376.23121

1 file

9.368.23092

1 file

9.365.23080

1 file

9.356.23062

1 file

9.341.23006

1 file

9.340.23006

1 file

9.339.23006

1 file

9.331.23005

1 file

9.300.22349

1 file

9.279.22339

1 file

9.278.22339

1 file

9.266.22338

1 file

9.251.22317

1 file

9.249.22317

1 file

9.238.22316

1 file

9.230.22310

1 file

9.213.22307

1 file

9.207.22283

1 file

9.189.22201

1 file

9.173.22126

1 file

9.169.22121

1 file

9.168.22121

1 file

9.163.22119

1 file

9.147.22086

1 file

9.134.22048

1 file

9.132.22039

1 file

9.128.22026

1 file

9.113.22021

1 file

9.110.22021

1 file

9.107.22008

1 file

9.101.22008

1 file

8.519.24031

1 file

8.518.24031

1 file

8.517.24030

1 file

8.516.24030

1 file

8.515.24030

1 file

8.514.24030

1 file

8.513.24030

1 file

8.509.24030

1 file

8.20.21357

1 file

8.4.21326

1 file

7.4.21313

1 file

6.2.21303

1 file

5.57.21262

1 file

5.22.21182

1 file

5.17.21182

1 file

5.8.21181

1 file

4.41.21142

1 file

4.22.21108

1 file

4.19.21059

1 file

4.2.20340

1 file

3.149.20327

1 file

3.141.20326

1 file

3.140.20326

1 file

3.135.20303

1 file

3.93.20259

1 file

3.92.20258

1 file

3.91.20246

1 file

3.85.20198

1 file

3.84.20198

1 file

3.78.20194

1 file

3.77.20190

1 file

3.74.20189

1 file

3.73.20189

1 file

3.72.20189

1 file

3.63.20108

1 file

3.62.20101

1 file

3.53.20059

1 file

3.52.20059

1 file

3.51.20059

1 file

3.47.20042

1 file

3.46.20032

1 file

3.41.20031

1 file

3.33.20028

1 file

3.32.20028

1 file

3.22.19344

1 file

3.19.19344

1 file

3.14.19317

1 file

3.8.19316

1 file

3.2.19316

1 file

2.53.19239

1 file

2.46.19127

1 file

2.45.19103

1 file

2.43.19055

1 file

2.37.19026

1 file

2.36.19026

1 file

2.32.19026

1 file

2.31.19025

1 file

2.30.19025

1 file

2.29.19025

1 file

2.27.19008

1 file

2.21.19007

1 file

2.20.18318

1 file

2.18.18240

1 file

2.17.18212

1 file

2.9.18212

1 file

2.8.18211

1 file

2.7.18148

1 file

2.5.18148

1 file

2.4.18148

1 file

1.7.18029

1 file

1.7.18025

1 file

1.7.18013

1 file

1.7.17339

1 file

1.6.17319

1 file

1.6.17264

1 file

1.5.17227

1 file

1.5.17206

1 file

1.5.17188

1 file

1.5.17187

1 file

1.3.17173

1 file

1.3.17131

1 file

1.3.17101

1 file

1.3.17085

2 files

1.3.17056

2 files

1.3.17050

2 files

1.3.17040

2 files

1.3.17035

2 files

1.2.17039

2 files

1.2.17035

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page