Attributes

class sheraf.attributes.base.BaseAttribute(default=None, key=None, lazy=True, read_memoization=None, write_memoization=None, store_default_value=True)

Bases: object

Base type of all attributes of a base model.

Parameters
  • default (a callable object or a simple object) – The value this attribute will be initialized with. If it is a callable object, it will be called on initialization, else it will simply be copied. The callable object can take either no argument, or one argument that will be the parent model.

  • key – The key to identify the attribute in its parent persistent mapping.

  • lazy (bool) – If True, the objet carried by the attribute is created on the first read or write access. If False, it is created when the model object is created. Default is True.

  • read_memoization (bool) – Whether this attribute should be memoized on read. False by default.

  • write_memoization (bool) – Whether this attribute should be memoized on write. True by default.

When an attribute is memoized, its next reading will not result in a new database access. Attributes: - indexes: a dictionary of Indexes. The key with value None stands for this attribute’s name.

create(parent)
Returns

The attribute’s defined default value. If it is a callable, return the result of calling it instead.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

index(unique=False, key=None, values=None, search=None, mapping=None, primary=False)

Indexing an attribute allows very fast reading with filter() calls.

Parameters
  • unique – If the attribute is unique, and two models have the same value for this attribute, a UniqueIndexException is raised when trying to write the second one. Automatically set to True if primary is True.

  • key – The key the index will use. By default, just the attribute name is used.

  • values – A callable that takes the current attribute value and returns a collection of values to index. Each generated value will be indexed each time this attribute is edited. It may take time if the generated collection is large. By default, the current attribute raw value is used.

  • primary – If true, this will be the default index for the model. False by default.

When indexes are used, lazy is disabled.

>>> class People(sheraf.AutoModel):
...     # Simple indexing
...     name = sheraf.SimpleAttribute().index()
...
...     # Emails can only be owned once
...     email = sheraf.SimpleAttribute().index(unique=True)
...
...     # Indexing people by their decade
...     age = sheraf.SimpleAttribute().index(key="decade", values=lambda age: {age // 10})
...
>>> with sheraf.connection(commit=True):
...     m = People.create(name="George Abitbol", email="george@abitbol.com", age=55)
...
>>> with sheraf.connection():
...     assert [m] == People.filter(name="George Abitbol")
...     assert [m] == People.filter(decade=5)
...
>>> with sheraf.connection():
...     People.create(name="Peter", email="george@abitbol.com", age=35)
Traceback (most recent call last):
    ...
UniqueIndexException
is_created(parent)
Parameters

parent – The owner of this attribute

Returns

true if the object is effectively created

key(parent)
Returns

the key that identifies this attribute in its owner object

read(parent)

Reads some raw data from the parent model and transform it into something more convenient to use. Most of the time, you should use deserialize().

Parameters

parent – The model parent.

Returns

the transformed value of this attribute

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

write(parent, value)

Takes user data, transform it into something ZODB can store, and store it into the model parent persistent.

Parameters
  • parent – The owner object of this attribute

  • value – The user data to store.

Returns

The stored and reread data. In some cases it may be different that the input data.

class sheraf.attributes.ModelLoader(model=None, **kwargs)

Bases: object

Loads models from the base in a cache.

Inherited by most model types (Model[Attribute|List|Set|(Large)Dict])

Simple attributes

class sheraf.attributes.simples.BooleanAttribute(**kwargs)

Bases: sheraf.attributes.simples.TypedAttribute

Store a bool object.

type

alias of builtins.bool

class sheraf.attributes.simples.DateAttribute(default=None, **kwargs)

Bases: sheraf.attributes.simples.IntegerAttribute

Stores a datetime.date object.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.simples.DateTimeAttribute(default=None, key=None, lazy=True, read_memoization=None, write_memoization=None, store_default_value=True)

Bases: sheraf.attributes.base.BaseAttribute

Store a datetime.datetime object.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.simples.FloatAttribute(**kwargs)

Bases: sheraf.attributes.simples.TypedAttribute

Stores a float object.

type

alias of builtins.float

class sheraf.attributes.simples.IntegerAttribute(**kwargs)

Bases: sheraf.attributes.simples.TypedAttribute

Stores an int object.

type

alias of builtins.int

class sheraf.attributes.simples.SimpleAttribute(default=None, key=None, lazy=True, read_memoization=None, write_memoization=None, store_default_value=True)

Bases: sheraf.attributes.base.BaseAttribute

Store a primitive data.

The value can be a bool, str, int, float.

class sheraf.attributes.simples.StringAttribute(**kwargs)

Bases: sheraf.attributes.simples.TypedAttribute

Stores a str object.

type

alias of builtins.str

class sheraf.attributes.simples.StringUUIDAttribute(default=None, key=None, lazy=True, read_memoization=None, write_memoization=None, store_default_value=True)

Bases: sheraf.attributes.simples.UUIDAttribute

Stores an uuid.UUID but data is handled as a string.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.simples.TimeAttribute(default=None, **kwargs)

Bases: sheraf.attributes.simples.IntegerAttribute

Stores a datetime.time object.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.simples.TypedAttribute(**kwargs)

Bases: sheraf.attributes.base.BaseAttribute

Store a persistent dict of primitive data.

Keys and values can be str, int, float.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

type

alias of builtins.object

class sheraf.attributes.simples.UUIDAttribute(default=None, key=None, lazy=True, read_memoization=None, write_memoization=None, store_default_value=True)

Bases: sheraf.attributes.base.BaseAttribute

Stores an uuid.UUID.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.counter.CounterAttribute(default=0, **kwargs)

Bases: sheraf.attributes.simples.IntegerAttribute

CounterAttribute is very like SimpleAttribute with concurrency-proof operations.

It acts as a drop-in replacement for SimpleAttribute with increment and decrement methods that automatically solve conflicts. It supports all mathematical operations, but only solves conflicts using increment and decrement. Every other destructive operation are sensible to conflicts.

>>> class MyModel(sheraf.Model):
...     table = "mymodel"
...     # You can just replace SimpleAttribute or IntegerAttribute with CounterAttribute
...     counter = sheraf.CounterAttribute() # initialized with 0
...
>>> with sheraf.connection(commit=True):
...     m = MyModel.create()
...     m.counter.increment(1)
...     m.counter.decrement(1)

Here is how to produce a conflict case, and how CounterAttributes behaves to solve it:

>>> with sheraf.connection(commit=True):
...     sheraf.Database.get().nestable = True
...     m1 = MyModel.read(m.id)
...
...     with sheraf.connection(commit=True):
...         m2 = MyModel.read(m.id)
...         m2.counter.decrement(10)
...
...     m1.counter.increment(100)
...
>>> with sheraf.connection():
...     m3 = MyModel.read(m.id)
...     assert 90 == m3.counter

The conflict resolution understands that a transaction is adding 100 and another transaction is substracting 10 to the counter at the same time, and finally adds 90. The formula used is: new_state_a + new_state_b - old_state where old_state is 0 as it was the previous value registered in the database, and new_state_a and new_state_b are the conflicting new values (here -10 and 100).

Using += and -= operators would have raised a conflicts. increment or decrement must be called explicitely.

>>> with sheraf.connection(commit=True):
...     sheraf.Database.get().nestable = True
...     m1 = MyModel.read(m.id)
...
...     with sheraf.connection(commit=True):
...         m2 = MyModel.read(m.id)
...         m2.counter -= 10
...
...     m1.counter += 100
Traceback (most recent call last):
    ...
ZODB.POSException.ConflictError: database conflict error ...

Regular assignments and operations on the counter also raise conflicts for automatic conflict resolution.

>>> with sheraf.connection(commit=True):
...     sheraf.Database.get().nestable = True
...     m1 = MyModel.read(m.id)
...
...     with sheraf.connection(commit=True):
...         m2 = MyModel.read(m.id)
...         m2.counter = 10
...
...     m1.counter.increment(100)
Traceback (most recent call last):
    ...
ZODB.POSException.ConflictError: database conflict error ...
deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

read(parent)

Reads some raw data from the parent model and transform it into something more convenient to use. Most of the time, you should use deserialize().

Parameters

parent – The model parent.

Returns

the transformed value of this attribute

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

write(parent, value)

Takes user data, transform it into something ZODB can store, and store it into the model parent persistent.

Parameters
  • parent – The owner object of this attribute

  • value – The user data to store.

Returns

The stored and reread data. In some cases it may be different that the input data.

Collection attributes

Collection attributes are attributes that behave like native python collections such as dict, list or set. They usually combine different objects:

  • A persistent_type that is the persistent data structure that will store the data in ZODB. For instance ListAttribute usually uses sheraf.types.SmallList or LargeList.

  • An accessor_type that helps handling the persistent_type with an interface similar to the native type it refers. For instance ListAttribute uses ListAccessor that behaves like the python list.

  • An optional attribute that helps the accessor_type serialize and deserialize the data stored in the persistent_type. This allows pairing collections with other kinds of attributes. For example you can easilly handle Blob lists or dictionaries of InlineModelAttributes.

>>> class Horse(sheraf.InlineModel):
...     table = "horse"
...     name = sheraf.SimpleAttribute()
...
>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     favorite_numbers = sheraf.SmallListAttribute(
...         sheraf.IntegerAttribute(),
...     )
...     horses = sheraf.LargeDictAttribute(
...         sheraf.InlineModelAttribute(Horse),
...     )
...
>>> with sheraf.connection(commit=True):
...     george = Cowboy.create(
...         name="George Abitbol",
...         favorite_numbers=[1, 13, 21, 34],
...         horses = {
...             "first": {"name": "Jolly Jumper"},
...             "second": {"name": "Polly Pumper"},
...         },
...     )
...
...     assert 21 in george.favorite_numbers
...     assert "Jolly Jumper" == george.horses["first"].name

You can also nest collections as you like, and play for instance with DictAttribute or ListAttribute.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     dice_results = sheraf.LargeDictAttribute(
...         sheraf.SmallListAttribute(
...             sheraf.IntegerAttribute()
...         )
...     )
...
>>> with sheraf.connection(commit=True):
...     george = Cowboy.create(
...         name="George Abitbol",
...         dice_results={
...             "monday": [2, 6, 4],
...             "tuesday": [1, 1, 3],
...         }
...     )
...     assert 6 == george.dice_results["monday"][1]
class sheraf.attributes.collections.DictAttribute(attribute=None, persistent_type=None, accessor_type=<class 'sheraf.attributes.collections.DictAttributeAccessor'>, **kwargs)

Bases: sheraf.attributes.base.BaseAttribute

Attribute mimicking the behavior of dict.

>>> class Gun(sheraf.InlineModel):
...     nb_amno = sheraf.IntegerAttribute()
...
>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     guns = sheraf.LargeDictAttribute(
...         sheraf.InlineModelAttribute(Gun)
...     )
...
>>> with sheraf.connection(commit=True):
...    george = Cowboy.create(
...        name="George Abitbol",
...        guns={
...            "rita": {"nb_amno": 6},
...            "carlotta": {"nb_amno": 5},
...        }
...    )
...
...    assert george.guns["rita"].nb_amno == 6
...    for gun in george.guns.values():
...        assert gun.nb_amno >= 5
deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

class sheraf.attributes.collections.LargeDictAttribute(*args, **kwargs)

Bases: sheraf.attributes.collections.DictAttribute

Shortcut for DictAttribute(persistent_type=LargeDict)

class sheraf.attributes.collections.LargeListAttribute(*args, **kwargs)

Bases: sheraf.attributes.collections.ListAttribute

Shortcut for ListAttribute(persistent_type=LargeList).

class sheraf.attributes.collections.ListAttribute(attribute=None, persistent_type=None, accessor_type=<class 'sheraf.attributes.collections.ListAttributeAccessor'>, **kwargs)

Bases: sheraf.attributes.base.BaseAttribute

Attribute mimicking the behavior of list.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     faxes = sheraf.LargeListAttribute(
...         sheraf.BlobAttribute()
...     )
...
>>> with sheraf.connection():
...     george = Cowboy.create(
...         name="George Abitbol",
...         faxes=[
...             sheraf.Blob.create(filename="peter1.txt", data=b"Can you give me my pin's back please?"),
...         ],
...     )
...
...     george.faxes.append(sheraf.Blob.create(filename="peter2.txt", data=b"Hey! Did you receive my last fax?"))
...     assert "peter1.txt" == george.faxes[0].original_name
...     assert b"fax" in george.faxes[1].data
...
deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

class sheraf.attributes.collections.SetAttribute(attribute=None, persistent_type=<class 'BTrees.OOBTree.OOTreeSet'>, accessor_type=<class 'sheraf.attributes.collections.SetAttributeAccessor'>, **kwargs)

Bases: sheraf.attributes.simples.TypedAttribute

Attribute mimicking the behavior of set.

>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     favorite_numbers = sheraf.SetAttribute(
...         sheraf.IntegerAttribute()
...     )
...
>>> with sheraf.connection(commit=True):
...    george = Cowboy.create(
...        name="George Abitbol",
...        favorite_numbers={1, 8, 13}
...    )
...
...    assert 13 in george.favorite_numbers
...    george.favorite_numbers.add(8)
...    assert {1, 8, 13} == set(george.favorite_numbers)
deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

class sheraf.attributes.collections.SmallDictAttribute(*args, **kwargs)

Bases: sheraf.attributes.collections.DictAttribute

Shortcut for DictAttribute(persistent_type=SmallDict)

class sheraf.attributes.collections.SmallListAttribute(*args, **kwargs)

Bases: sheraf.attributes.collections.ListAttribute

Shortcut for ListAttribute(persistent_type=SmallList).

Model attributes

class sheraf.attributes.models.IndexedModelAttribute(model=None, **kwargs)

Bases: sheraf.attributes.ModelLoader, sheraf.attributes.base.BaseAttribute

read(parent)

Reads some raw data from the parent model and transform it into something more convenient to use. Most of the time, you should use deserialize().

Parameters

parent – The model parent.

Returns

the transformed value of this attribute

write(parent, value)

Takes user data, transform it into something ZODB can store, and store it into the model parent persistent.

Parameters
  • parent – The owner object of this attribute

  • value – The user data to store.

Returns

The stored and reread data. In some cases it may be different that the input data.

class sheraf.attributes.models.InlineModelAttribute(model=None, **kwargs)

Bases: sheraf.attributes.ModelLoader, sheraf.attributes.base.BaseAttribute

Class for defining attributes whose value is stored in their owner object as a dictionary, as opposed to ModelAttributes where the corresponding object ‘id’ is stored instead.

Use this class (1) to faster access the objects referenced by this attribute (2) to encapsulate data for which direct access through tables is not preferred.

InlineModelAttribute should refer to InlineModel.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

class sheraf.attributes.models.ModelAttribute(model=None, **kwargs)

Bases: sheraf.attributes.ModelLoader, sheraf.attributes.base.BaseAttribute

This attribute references another Model.

>>> class Horse(sheraf.Model):
...     table = "horse"
...     name = sheraf.SimpleAttribute()
...
>>> class Cowboy(sheraf.Model):
...     table = "cowboy"
...     name = sheraf.SimpleAttribute()
...     horse = sheraf.ModelAttribute(Horse)
...
>>> with sheraf.connection(commit=True):
...     jolly = Horse.create(name="Jolly Jumper")
...     george = Cowboy.create(name="George Abitbol", horse=jolly)
...
...     george.horse.name
'Jolly Jumper'

The referenced model can be dynamically created if its structure is passed through as a dict:

>>> with sheraf.connection(commit=True):
...     peter = Cowboy.create(name="Peter", horse={"name": "Polly Pumper"})
...     assert isinstance(peter.horse, Horse)
...     peter.horse.name
'Polly Pumper'

When the referenced model is deleted, the value of the attribute becomes None.

>>> with sheraf.connection(commit=True):
...     george = Cowboy.read(george.id)
...     jolly.delete()
...     assert george.horse is None
deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

serialize(value)

Get data and transform it into something ZODB can store.

Parameters

value – The input data.

Returns

The transformed data.

update(old_value, new_value, addition=True, edition=True, deletion=False, replacement=False)

Updates the value of the attribute.

Parameters
  • old_value – The previous value the attribute had.

  • new_value – The new value that the attribute should be updated with.

  • addition – On collections, adds elements to the attribute if they are present in new_value and not in old_value, defaults to True.

  • edition – On collections, edits the attribute element if present on both old_value and new_value, defaults to True.

  • deletion – On collections, removes an element if present in old_value and absent from new_value, default to False.

  • replacement – Replace sub-collections or sub-models instead of editing them in-place, defaults to False.

File attributes

class sheraf.attributes.blobs.Blob(**kwargs)

Bases: sheraf.models.inline.InlineModel

Blob objects wrap the raw data from regular files.

ZODB ZODB.blob.Blob are used to store the data.

classmethod create(data=None, filename=None, stream=None, **kwargs)
Parameters
  • data – the data to store in the blob

  • filename – the name of the original file

  • stream – If data is not set, data will be read from the stream stream.

  • kwargs – optional attributes to set

Returns

A sheraf object wrapping a ZODB.blob.Blob object, or None if this is an empty and unnamed file.

property data

The file binary data.

delete()

Delete the object from the base.

edit(value, addition=True, edition=True, deletion=False, replacement=False)

Take a dictionary and a set of options, and try to applies the dictionary values to the model structure.

Parameters
  • value – The dictionary containing the values. The dictionary elements that do not match the model attributes will be ignored.

  • addition – If True, elements present in value and absent from the model attributes will be added.

  • edition – If True, elements present in both value and the model will be updated.

  • deletion – If True, elements present in the model and absent from value will be deleted.

  • replacement – Like edition, but create a new element instead of updating one.

property file_extension

The original filename extension.

property filename

The name of the blob file.

open()

Opens the stored blob file.

property original_name

The original filename.

class sheraf.attributes.blobs.BlobAttribute(model=<class 'sheraf.attributes.blobs.Blob'>, **kwargs)

Bases: sheraf.attributes.models.InlineModelAttribute

This attribute stores binary files. It is mainly an interface that handles a Blob object.

deserialize(value)

Get raw data and transform it into something more convenient to use.

Parameters

value – The input data.

Returns

The transformed data.

class sheraf.attributes.files.FileAttribute(file_object_class=<class 'sheraf.attributes.files.FileObjectV2'>, **kwargs)

Bases: sheraf.attributes.base.BaseAttribute

This attribute stores a file on disk.

read(parent)

Reads some raw data from the parent model and transform it into something more convenient to use. Most of the time, you should use deserialize().

Parameters

parent – The model parent.

Returns

the transformed value of this attribute

write(parent, value)

Takes user data, transform it into something ZODB can store, and store it into the model parent persistent.

Parameters
  • parent – The owner object of this attribute

  • value – The user data to store.

Returns

The stored and reread data. In some cases it may be different that the input data.

Index

class sheraf.attributes.indexdetails.IndexDetails(attribute, unique, key, values_func, search_func, mapping, primary)

Bases: object

Parameters
  • attribute (class BaseAttribute) – The attribute being indexed

  • key – The key the index will use. By default, just the attribute name is used.

  • unique (bool) – If the attribute is unique, and two models have the same value for this attribute, a UniqueIndexException is raised when trying to write the second one. Automatically set to True if primary is True.

  • key – The key the index will use. By default, just the attribute name is used.

  • values_func – A callable that takes the current attribute value and returns a collection of values to index. Each generated value will be indexed each time this attribute is edited. It may take time if the generated collection is large. By default, the current attribute raw value is used.

  • search_func – A callable that takes some raw data and returns a collection of values to search in the index. By default, values_func is used.

  • mapping – The mapping object to be used to store the indexed values. OOBTree by default.