Skip to main content

Dot notation object

Project description

DotObject v 1.0.0

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>
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

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

dotobject-1.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distributions

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

dotobject-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

dotobject-1.0.0-py2-none-any.whl (9.2 kB view details)

Uploaded Python 2

File details

Details for the file dotobject-1.0.0.tar.gz.

File metadata

  • Download URL: dotobject-1.0.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dotobject-1.0.0.tar.gz
Algorithm Hash digest
SHA256 98239172bb0ced0b29f0211fcaa5bcffa51b043494917f4bc67823ddb4b02d46
MD5 3b788aaa73c0814604e6c3e0217bed48
BLAKE2b-256 f2c4fadd41e0f9ac722b209c9bc10b8c213752cf48deb73478167ddf9347d1f6

See more details on using hashes here.

File details

Details for the file dotobject-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dotobject-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f40621b6bbbd986d1305264589238c59accd37949a2d8c90b9a290144dec8220
MD5 505aa1db9cb19a613eabec5c408895ad
BLAKE2b-256 d2830953d0033cd3ae67a506730db50c7a712b19cbb3669656579781e1807dec

See more details on using hashes here.

File details

Details for the file dotobject-1.0.0-py2-none-any.whl.

File metadata

File hashes

Hashes for dotobject-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 181ac0ef2c55118396fa71c649f044d1752feb493bad969e55177154d4785a0b
MD5 b67ee64bc9cfeb6887baf06ff8c920f8
BLAKE2b-256 2a8d2e76a9bfaa7022035f1089f82549f32d901594e83c47f12bffcbcd6d20f8

See more details on using hashes here.

Supported by

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