Skip to main content

DotObject v 1.3.1

Dot Notation Object

Dot lets you define objects in dot notation format.

You need to subclass Dot and define your own load and optionally save methods in order to use the dot notation object.

Background

Dot Notation object was originally designed to be the base library for a Redis client for Python. Thus the names ‘load’ and ‘save’ come from. The idea was to have python object that simply by writing obj.item=”value”, it sets the redis key “obj.item” with “value” value. And as soon as it detects you are retrieving the value, it gets the latest version from Redis. But in the mean time, it gives you a lazy object till it actually needs the value from Redis.

So the Dot notation object is basically a lazy object that once its “load” and “save” methods are defined, it will run those methods when the object is saved or retrieved.

Parameters

root_nameString, Optional.

It is used to overwrite the Dot object root name.

int_starts_with: String, Optional. Default: i

It is used to idefntify integer parts since Python does not let integers as attributes.

Returns

A lazy object that will be evaluated when it is actually used.

Examples

Defining your own Dot
>>> from dot import Dot
>>> class This(Dot):
...     def __init__(self, *args, **kwargs):
...         super(This, self).__init__(*args, **kwargs)
...         self.items = {}
...     def load(self, paths):
...         return {i: self.items[i] if i in self.items else "value %s" % i for i in paths}
...     def save(self, path, value):
...         self.items[path] = value
...
Creating a Dot object
>>> this = This()
>>> aa = this.part1.part2.part3.part4
>>> aa
<Lazy object: this.part1.part2.part3.part4>
>>> print(aa)
value this.part1.part2.part3.part4
>>> aa
value this.part1.part2.part3.part4
Dot objects get evaluated in a batch
>>> this = This()
>>> aa = this.part1
>>> aa
<Lazy object: this.part1>
>>> bb = this.part2
>>> bb
<Lazy object: this.part2>
>>> print(aa)
value this.part1
>>> aa
value this.part1
>>> bb
value this.part2
Dealing with paths that have integers as a part
>>> bb = this.part1.part2.i120
>>> bb
<Lazy object: this.part1.part2.120>
>>> print bb
value this.part1.part2.120
Dealing with Dots like dictionary keys
>>> cc = this['part1.part2.part4']
>>> cc
<Lazy object: this.part1.part2.part4>
>>> dd = this['part1.%s.part4' % 100]
>>> dd
<Lazy object: this.part1.100.part4>
>>> path = 'part1.part2'
>>> this[path] = 'This was set by a dynamic key.'
>>> this.path
This was set by a dynamic key.
Saving Dots
>>> this.part1.part2.part3.part4 = "new value"
>>> zz = this.part1.part2.part3.part4
>>> zz
new value
Changing Root name
>>> class That(This):
...    pass
>>> that = That()
>>> aa = that.something
>>> print(aa)
value that.something
>>> bb = this.something
>>> bb
<Lazy object: this.something>
Flushing cache
>>> aa = this.part1
>>> print aa
value this.part1
>>> bb = this.part1 # reads from the cache
>>> this.flush()
>>> bb = this.part1 # Will evaluate this.part1 again

Metadata

Release files for dotobject 1.3.1

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

Source distribution (sdist)

Source distribution for dotobject 1.3.1
File Size Uploaded
dotobject-1.3.1.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dotobject 1.3.1
File Interpreter ABI Platform
dotobject-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / dotobject-1.3.1.tar.gz

Download URL dotobject-1.3.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7e25720f6e1c00880b428bf5cfd5c19d12fd92eba420c9b0e7216931c086991f
BLAKE2b-256 checksum
How to use checksums
8d82bf623bb4aec8863b3914baa37b21f0fd6e9c05ec315284cd136be1d4e131
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / dotobject-1.3.1-py3-none-any.whl

Download URL dotobject-1.3.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de5e792246b6378d53265b38d2c726b65bc40a0d50ee67275b8019caf7ee2394
BLAKE2b-256 checksum
How to use checksums
337db9be288a41e492da3f21aad2e303eac71ab814eb12c73fb93d1684af63f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

3 release files

1.2.0

3 release files

1.1.0

3 release files

1.0.0

3 release files

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