Automatic Creation of ORM Models from Python Dataclasses.
Project description
Welcome to ORMatic
ORMatic is a python package that automatically converts python dataclasses to sqlalchemy tables. This is done using the imperative mapping.
When designing the dataclasses there are a couple of rules that need to be followed:
- Fields that are not mapped start with an
_(underscore). - The only allowed union is the
Optional[_T]union. Whenever you want a union of other types, use inheritance instead. - Iterables are never optional and never nested. If you want an optional iterable, use an empty iterable as default factory instead.
- No multiple inheritance.
Features:
-
Automatic conversion of dataclasses to sqlalchemy tables.
-
Automatic application of relationships.
-
Automatic generation of ORM interface.
-
ORM interface only affects your code if it is imported.
-
Support for inheritance.
-
Support for optional fields.
-
Support for nested dataclasses.
-
Support for many-many relationships.
-
Support for self-referencing relationships.
Example
The most common use case is to create an ORM for an existing set of dataclasses. An example for such a set of dataclasses is found in example.py. The automatically generated ORM interface is found in orm_interface.py. Example usage of the ORM interface is found in integration.py.
The following script generates the bindings in orm_interface.py.
import sqlacodegen.generators
from sqlalchemy import create_engine
from sqlalchemy.orm import registry, Session
from ormatic.example import *
from ormatic.ormatic import ORMatic
def main():
mapper_registry = registry()
engine = create_engine('sqlite:///:memory:')
classes = [Position, Orientation, Pose, Position4D, Positions, EnumContainer, Node]
ormatic = ORMatic(classes, mapper_registry)
ormatic.make_all_tables()
mapper_registry.metadata.create_all(engine)
generator = sqlacodegen.generators.TablesGenerator(mapper_registry.metadata, engine, [])
with open('orm_interface.py', 'w') as f:
ormatic.to_python_file(generator, f)
if __name__ == '__main__':
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ormatic-1.0.2.tar.gz.
File metadata
- Download URL: ormatic-1.0.2.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7de25663b277feec58fba81ff56b633c4901c4aa691eb8a25497cd143b73cf1c
|
|
| MD5 |
2b38be03315e0c1bb6ce5b40f0db9ac5
|
|
| BLAKE2b-256 |
9441576701ed434a2371b8105a66853ebc3494fd23724fb1c46c1c132f67130b
|
Provenance
The following attestation bundles were made for ormatic-1.0.2.tar.gz:
Publisher:
publish-to-pypi.yml on tomsch420/ormatic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ormatic-1.0.2.tar.gz -
Subject digest:
7de25663b277feec58fba81ff56b633c4901c4aa691eb8a25497cd143b73cf1c - Sigstore transparency entry: 204092187
- Sigstore integration time:
-
Permalink:
tomsch420/ormatic@27dd4e918be2b9f8c145f3162aa643642d6f3d23 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/tomsch420
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@27dd4e918be2b9f8c145f3162aa643642d6f3d23 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ormatic-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ormatic-1.0.2-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43f4df85d9298397eef602ccd71775d0423310b15b4bd78c9892b2072a504f70
|
|
| MD5 |
d592fc1ccc3e020db715e85c31530bf8
|
|
| BLAKE2b-256 |
70d4d42be2ed489b84d2025f25f55babbbff3ae1593ca8fa8911e7cfe1c59ed2
|
Provenance
The following attestation bundles were made for ormatic-1.0.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on tomsch420/ormatic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ormatic-1.0.2-py3-none-any.whl -
Subject digest:
43f4df85d9298397eef602ccd71775d0423310b15b4bd78c9892b2072a504f70 - Sigstore transparency entry: 204092191
- Sigstore integration time:
-
Permalink:
tomsch420/ormatic@27dd4e918be2b9f8c145f3162aa643642d6f3d23 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/tomsch420
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@27dd4e918be2b9f8c145f3162aa643642d6f3d23 -
Trigger Event:
push
-
Statement type: