Alch-DC: Converting between SQLAlchemy ORM models and dataclass objects
Tired of manually converting dataclass objects to SQLAlchemy ORM models and backward?
If yes, alch-dc (Alchemy - Dataclass) is for you. It validates and maps between the
two paradigms for you.
Installation
If you're using uv then
uv add alch-dc
or install with pip:
pip install alch-dc
Quick start
from dataclasses import dataclass
from uuid import UUID, uuid4
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
# --- DATACLASS MODEL --- #
@dataclass
class Person:
id: UUID
name: str
age: int
# --- SQLALCHEMY MODEL --- #
class Base(DeclarativeBase):
pass
class PersonModel(Base):
__tablename__ = "people"
id: Mapped[UUID] = mapped_column(primary_key=True)
name: Mapped[str]
age: Mapped[int]
# --- ALCH-DC --- #
from alch_dc import Converter
# Create a converter to use throughout the project
converter = Converter(Person, PersonModel)
# Map dataclass object to ORM object
p = Person(id=uuid4(), name="minhdenthedev", age=22)
orm_p = converter.to_orm(p)
# Map ORM object to dataclass object
orm_p = PersonModel(id=uuid4(), name="minhdenthedev", age=22)
p = converter.from_orm(orm_p)
Best practices
When instantiating, the converter would validate the schema to make sure the two
classes are convertible. This operation is time-consuming and only needs to be checked
once, so it's best to instantiate the Converter class once and then use it throughout
your code.
Metadata
Release files for alch-dc 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| alch_dc-0.1.0.tar.gz | 3.3 kB | Without provenance | Details for alch_dc-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alch_dc-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for alch_dc-0.1.0-py3-none-any.whl |
Total release size: 8.1 kB
Release files / alch_dc-0.1.0.tar.gz
| Download URL | alch_dc-0.1.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e73407b5fce34534b50a855ae5290c4f61d96e039adfdc28392e4c34a8278529
|
|
BLAKE2b-256 checksum How to use checksums |
3e34578266f228b77a90cc6f9f50bd9246ff12b4bb123e339cce4345d621cf55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / alch_dc-0.1.0-py3-none-any.whl
| Download URL | alch_dc-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
232b042a51a1e24b0c49aa7eeeca8dda6b356d4d77056a657e81a943e4258149
|
|
BLAKE2b-256 checksum How to use checksums |
db41df9882ab7efb40fd891056ec45043ed76b29e8aa954e67945a7a9d9a65b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for alch-dc 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.