Skip to main content

A library for light and predictable python object mappings to Redis

Documentation Status

Documentation

Documentation is generated through sphinx and hosted at Read the Docs!

Why did you build this?

I wanted an object oriented way to interact with redis that would provide exacting control over database layout, predicatble and fast queries, and good documentation. (hopefully I got that last one right, but I’m not the one to judge)

The first goal of trol is a statically defined, human-readble database structure defined by python classes. This allows the dev to look at the database at runtime and read it as easily as the code which defined it. The dev should be able to modify the database and know exactly what effect it will have on the program. As a result of this, trol explicitly does not provide indexing or store supporting datastructures not defined by the programer.

The second goal of trol is fast and predictable querying. Any python access, function, or modification should result and in one or zero network transfers. One result of this is a structure which encourages the dev to create a database where eveything is defined in location and uniquely identifieable without searching.

Getting started

pip install trol and start defining your schema:

>>> import trol
>>> import redis
...
>>> class MyDatabase(trol.Database):
...   redis = redis.Redis()
...
...   favorite_breweries = trol.SortedSet('favbreweries', typ=trol.Model)
...
...   class Brewery(trol.Model):
...     def __init__(self, short_name):
...       self.id = short_name
...
...     location = trol.Property()
...     name = trol.Property(typ=str)
...     beers = trol.Set(typ=trol.Model)
...
...   class Beer(trol.Model):
...     def __init__(self, name, batch_number):
...       self.name = name
...       self.batch_number = batch_number
...
...     @property
...     def id(self):
...       return self.name + '@' + str(self.batch_number)
...
...     style = trol.Property()
...     rating = trol.Property(typ=int)
...
>>> brewery = MyDatabase.Brewery('frmt')
>>> brewery.location = (47.6490476, -122.3467747)
>>> brewery.name = "Fremont Brewing Company"
>>> lush = MyDatabase.Beer('Lush IPA', 120)
>>> lush.style = "Indian Pale Ale"
>>> lush.rating = 5
>>> universale = MyDatabase.Beer('Universale', 245)
>>> universale.style = "American Pale Ale"
>>> universale.rating = 5
>>> brewery.beers.add(lush, universale)
2
>>> MyDatabase.favorite_breweries.add(brewery, 10)
1
>>> set(MyDatabase.redis.keys()) == {
...   b'favbreweries',
...   b'Brewery:frmt:name',
...   b'Brewery:frmt:location',
...   b'Brewery:frmt:beers',
...   b'Beer:Lush IPA@120:style',
...   b'Beer:Lush IPA@120:rating',
...   b'Beer:Universale@245:style',
...   b'Beer:Universale@245:rating'
... }
True

Development

For local development, install the dependencies listed in requirements.txt and additionally the dev-dependencies in requirements-dev.txt.

As an additional development dependency, you should have Redis server installed locally. You can follow the instructions at https://redis.io/docs/getting-started/installation/ to get started. Note that on Ubuntu, you should install redis via apt rather than snap as the snap package does not include the redis-server binary.

Testing

Tests are written using nose2. Running tests can be accomplished by running python -m nose2.

Note that tests will run a redis-server process, so this command must be installed. as mentioned above, in addition to the requirements-dev.txt dependencies.

Release files for trol 0.5.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 trol 0.5.3
File Size Uploaded
trol-0.5.3.tar.gz 26.9 kB Details

Built distribution (wheel)

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

Total release size: 51.1 kB

Release files / trol-0.5.3.tar.gz

Download URL trol-0.5.3.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f5db9296dbe30c78023f68f10d1101cb5289663d9fb8da7fef3c477f29b7e341
BLAKE2b-256 checksum
How to use checksums
dacab7430b010cb242d299e5b61bebbd556fdb94c24f2ef896192ae9aa18ad96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.8.3 requests/2.28.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

Release files / trol-0.5.3-py3-none-any.whl

Download URL trol-0.5.3-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d02e73c7ff42101d8bfb0d94f2f4e55c2f08641d00b9e9ce642246c2a78e1001
BLAKE2b-256 checksum
How to use checksums
5d7e2ff5c045054d4cd272ecef83689464696394acb0a308b9759645b7eeea9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.8.3 requests/2.28.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

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