Data Model (DM) reference#
This section describes the core Data Model (DM) layer in RESTAlchemy.
The DM layer is responsible for:
- Declaring domain models as Python classes.
- Defining fields, types and validation rules.
- Expressing relationships between models.
- Providing helper mixins for common patterns (UUID IDs, timestamps, names, etc.).
The DM layer is implemented in the following modules:
restalchemy.dm.modelsrestalchemy.dm.propertiesrestalchemy.dm.relationshipsrestalchemy.dm.typesrestalchemy.dm.filtersrestalchemy.dm.types_dynamic(advanced types)restalchemy.dm.types_network(network-related types)
This reference focuses on the first five modules, which you will use most of the time.
Quick overview#
A typical DM model is defined like this:
from restalchemy.dm import models, properties, types
class Foo(models.ModelWithUUID):
# Integer field, required
value = properties.property(types.Integer(), required=True)
# Optional string with default value
description = properties.property(types.String(max_length=255), default="")
Key ideas:
- You inherit from
Modelor one of the helper base classes such asModelWithUUID. - You use
properties.property()to declare fields. - You use
types.*classes to describe the type and constraints of each field.
Relationships between models are declared via relationships.relationship().
Filters (restalchemy.dm.filters) are used to describe query conditions when working with storage and API filtering.
Files in this section#
- Models
Model,ModelWithID,ModelWithUUID,ModelWithTimestamp, and other mixins.- Properties
- Property system:
Property,IDProperty,PropertyCollection,PropertyManager, helper factories. - Relationships
relationship(),required_relationship(),readonly_relationship(),Relationship,PrefetchRelationship.- Types
- Scalar, datetime, collection and structured types used in properties.
- Filters
- Filter clauses (
EQ,GT,In, etc.) and logical expressions (AND,OR).
All of these files exist in four languages with the same structure:
You can find the DM reference in each language under the corresponding reference/dm/ section.