Skip to main content

Some extensions for redis-limpyd, a redis orm (sort of) in python.

Project description

PyPI Version Build Status

redis-limpyd-extensions

Some extensions for redis-limpyd (redis orm (sort of) in python)

Where to find it:

Install:

Python versions 2.7, and 3.5 to 3.8 are supported (CPython and PyPy).

Redis-server versions >= 3 are supported.

Redis-py versions >= 3 are supported.

Redis-limpyd versions >= 2 are supported.

You can still use limpyd-extensions versions < 2 if you need something older than the above requirements.

pip install redis-limpyd-extensions

List of available extensions:

  • Add/remove related on both sides

  • Dynamic fields

Dynamic fields

Dynamic fields provide a way to add unlimited fields to a model by defining a (or many) dynamic field, and use it with a dynamic part. ie a dynamic field name “foo” can be used with as many dynamic parts as you want to create dynamic variations: “foo_bar” for the dynamic part “bar”, “foo_baz” for the dynamic part “baz”, and so on.

A simple API to use them, and filter on them, is provided.

To use a dynamic field, your model must inherit from the following mixin: ModelWithDynamicFieldMixin, found in limpyd_extensions.dynamic.model. It’s a mixin, you should use it with another RedisModel class. Fields are available as field classes (DynamicStringField, DynamicInstanceHashField, DynamicListField, DynamicSetField, DynamicSortedSetField, DynamicHashField) or as a mixin (DynamicFieldMixin) if you want to adapt an external field. You can find them in limpyd_extensions.dynamic.fields

A short example on how to define a dynamic field on a model:

from limpyd.model import RedisModel

from limpyd_extension.dynamic.model import ModelWithDynamicFieldMixin
from limpyd_extension.dynamic.fields import DynamicSetField


class MyModel(ModelWithDynamicFieldMixin, RedisModel):
    foo = DynamicSetField(indexable=True)

As the foo field is dynamic, you cannot run any command on it, but only on its dynamic variations. How to do it ?

There is two ways:

  • use the get_field method of the model:

foo_bar = myinstance.get_field('foo_bar')
  • use the get_for method of the field:

foo_bar = myinstance.foo.get_for('bar')

The latter is useful if you have a variable instead of known value:

somebar = 'bar'
foo_bar = myinstance.foo.get_for(somevar)

Note that you can use this shortcut instead of using get_for:

foo_bar = myinstance.foo(somevar)

Knowing this, you can do operations on these fields:

myinstance.foo(somevar).sadd('one', 'two', 'three')
myinstance.foo(othervar).sadd('four', 'five')
myotherinstance.foo(somevar).sadd('three', 'thirty')
print myinstance.foo(somevar).smembers()
print myinstance.foo(othervar).smembers()
print myotherinstance.foo(somevar).smembers()

To know the existing versions in a dynamic_field, you can use scan_fields.

It takes the same argument as the sscan command of SetField (from limpyd), because it is applied on the inventory key where all versions are saved.

So if you have some versions:

You can retrieve them all:

Or only a part:

Filtering

To filter on indexable dynamic fields, there is two ways too:

  • use the classic way, if you now the dynamic part in advance:

MyModel.collection(foo_bar='three')
  • use the new dynamic_filter method:

MyModel.collection().dynamic_filter('foo', 'bar', 'three')

Parameters are: the field name, the dynamic part, the value for the filter and, not show in the previous example, the index suffix to use.

This suffix is default to ‘’.

But if what you want to do is

MyModel.collection(foo_bar__eq='three')

You can use dynamic_filter this way:

MyModel.collection().dynamic_filter('foo', 'bar', 'three', 'eq')  # you can use '__eq' too

The collection manager used with ModelWithDynamicFieldMixin depends on ExtendedCollectionManager, so you can chain filters and dynamic filters on the resulting collection.

Provided classes

Here is the list of modules and classes provided with the limpyd_extensions.dynamic module:

  • model

    • mixins

      • ModelWithDynamicFieldMixin(object) - A mixin tu use for your model with dynamic fields

  • collection

    • mixins

      • CollectionManagerForModelWithDynamicFieldMixin(object) - A mixin to use if you want to add the dynamic_filter method to your own collection manager

    • full classes

      • CollectionManagerForModelWithDynamicField(CollectionManagerForModelWithDynamicFieldMixin, ExtendedCollectionManager) - A simple class inheriting from our mixin and the manager from limpyd.contrib.collection

  • field

    • mixins

      • DynamicFieldMixin(object) - A mixin within all the stuff for dynamic fields is done, to use to add dynamic field support to your own fields

    • full classes All fields simply inherits from our mixin and the wanted base field, without anymore addition:

      • DynamicStringField(DynamicFieldMixin, StringField)

      • DynamicInstanceHashField(DynamicFieldMixin, InstanceHashField)

      • DynamicListField(DynamicFieldMixin, ListField)

      • DynamicSetField(DynamicFieldMixin, SetField)

      • DynamicSortedSetField(DynamicFieldMixin, SortedSetField)

      • DynamicHashField(DynamicFieldMixin, HashField)

  • related

    • mixins

      • DynamicRelatedFieldMixin(DynamicFieldMixin) - A mixin within all the stuff for dynamic related fields is done, to use to add dynamic field support to your own related fields

    • full classes

      • DynamicFKStringField(DynamicRelatedFieldMixin, FKStringField)

      • DynamicFKInstanceHashField(DynamicRelatedFieldMixin, FKInstanceHashField)

      • DynamicM2MSetField(DynamicRelatedFieldMixin, M2MSetField)

      • DynamicM2MListField(DynamicRelatedFieldMixin, M2MListField)

      • DynamicM2MSortedSetField(DynamicRelatedFieldMixin, M2MSortedSetField)

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

redis-limpyd-extensions-2.1.dev0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

redis_limpyd_extensions-2.1.dev0-py2.py3-none-any.whl (14.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file redis-limpyd-extensions-2.1.dev0.tar.gz.

File metadata

  • Download URL: redis-limpyd-extensions-2.1.dev0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for redis-limpyd-extensions-2.1.dev0.tar.gz
Algorithm Hash digest
SHA256 dc1c186b113dbc423359d088f37566afc6fef146d7026d795fea09416a8c8e2f
MD5 e4449e38c1a3b08ee47285dd6a7785fc
BLAKE2b-256 f6a776ce0b1c8f9b10b01be99409b703399681484dfe4613fd53b47d34594a16

See more details on using hashes here.

File details

Details for the file redis_limpyd_extensions-2.1.dev0-py2.py3-none-any.whl.

File metadata

  • Download URL: redis_limpyd_extensions-2.1.dev0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0b4

File hashes

Hashes for redis_limpyd_extensions-2.1.dev0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8e91f17407b2b057f0f78565e8c0558f6b292556a32c41fab5df3bdb867115da
MD5 f8a2e82b78f464dd2d74e298410b835a
BLAKE2b-256 57f3adc45b429732748ce6465c33cc8614643e6365ce4ec480ea2ce13ca54132

See more details on using hashes here.

Supported by

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