Skip to main content

Python library to easily map Objects to Caching Systems like Redis

Project description

py-distobjects

py-distobjects (Python Distributed Objects) is a Python library to easily map Objects to Caching Systems like Redis.

Usage

  • Simply define classes with minimum schema and connect to a backend
  • Create objects from those classes and use them as if they are regualer objects
  • Even Concurrent Access from multiple hosts will work as long as conntected to same backend
  • You can update the object from any Host/Process, you can access the updated values instently from other Hosts/Processes by just reading attribute without explicit refresh/reading

Why? when i can use redis directly

  • Same reson as why we use ORMs for Database access when we can use SQL directly
  • No need to worry about keys, values, Serialization, and Deserialization etc. all over the code.
  • It just makes it easily organize/maintain the code by abstracting some functions

Creating object in host1

>>> from distobjects import RedisBackend, DObject
>>> from distobjects.fields import TextField
>>> import redis
>>>
>>> r = redis.Redis(host='redis-server1', port=6379, db=5)
>>> redis_backend = RedisBackend(client=r)
>>> class MyStudent(DObject):
...    class Meta:
...        backend = redis_backend
...    first_name = TextField()
...    last_name = TextField()
...
>>> student1 = MyStudent("1")
>>> student1.first_name = "Harry"
>>> student1.last_name = "James"

Reading object in host2

>>> from distobjects import RedisBackend, DObject
>>> from distobjects.fields import TextField
>>> import redis
>>>
>>> r = redis.Redis(host='redis-server1', port=6379, db=5)
>>> redis_backend = RedisBackend(client=r)
>>> class MyStudent(DObject):
...    class Meta:
...        backend = redis_backend
...    first_name = TextField()
...    last_name = TextField()
...
>>> student = MyStudent("1")
>>> student
<__main__.MyStudent object at 0x105bc29d0>
>>> student.first_name
'Harry'
>>> student.last_name
'James'

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

distobjects-0.0.1a1.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file distobjects-0.0.1a1.tar.gz.

File metadata

  • Download URL: distobjects-0.0.1a1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.4

File hashes

Hashes for distobjects-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 707c2686ac98282c71481f656df54fbbbf2c869b7998d4a0b74b53828c2fab12
MD5 23a972b658431c562dd85029e68a944b
BLAKE2b-256 4a02b748e8f99c4aa959d0cf4bea5024da86212178df630ea70eb73d5f6efd46

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