Skip to main content

SqlAlchemy support for Ex-DRF

exdrf-al is the SQLAlchemy 2.x bridge for exdrf: declarative metadata is turned into ExDataset / ExResource / ExField trees used by generators (al2pd, al2qt, al2r, …), Qt (exdrf-qt), and Alembic helpers (Click commands in this package). It depends on exdrf and exdrf-pd.

The library provides guidance and support code for using SQLAlchemy with Ex-DRF.

Usage

Start by basing your models off Base from exdrf_al.base module. It is a rather simple class that allows for model and fields iteration. If you don't want to use it, take a look at the implementation of that class for how to extract the information you need from your models.

Models

The library reads the description of models from the sqlAlchemy metadata. On top of that you can add additional information by adding members to the info key in the __table_args__ model attribute.

The keys that are used inside the info dictionary are documented in exdrf.resource.ResExtraInfo, which is the pydantic class that parses the information. Here is brief description of the most important keys:

  • label: takes a string that is interpreted by the DSL in exdrf. label_dsl; it is used to generate code that computes the label of a record given the record. The exdrf.label_dsl module includes code to create python and typescript code from a parsed label definition.

Example:

class Example(Base):
    __tablename__ = "the_table"
    __table_args__ = {
        "info": {
            "label": """(if name name (concat "ID:" " id))""",
        }
    }
    id: int
    name: Optional[str] = None

Fields

Just like with the models, the model field metadata is used to extract the information. Additionally, we use values in the dictionary assigned to the info attribute to add additional information.

The keys that are used inside the info consist of a common subset for all field types and specific keys for each field type. The common keys parsed by the exdrf.field.FieldInfo class are documented with that class, and each field type is described in its own module under exdrf.field_types.

Example:

class Example(Base):
    __tablename__ = "the_table"
    id: Mapped[int] = mapped_column(
        primary_key=True,
        doc="The unique identifier for a record within its table",
        info={
            "sortable": False
        }
    )
    name: Mapped[Optional[str]] = mapped_column(
        doc="The name of the record",
        info={
            "filterable": False,
            "multiline": True,
            "min_length": 3,
        }
    )

Relationships

relationship(..., info={...}) is validated with exdrf.field_types.ref_base.RelExtraInfo, which extends exdrf.field.FieldInfo. Keys such as direction and doc are required or conventional; optional keys from FieldInfo apply as well.

When use_rel is true on a non-bridge OneToMany relationship, Qt code generation (exdrf-gen-al2qt) emits a dedicated editor tab with a DrfRelated-style transfer list (Qt{Parent}Rel{Ref}) instead of an inline Qt{Ref}MuSe control on category tabs.

Example:

items: Mapped[Set["Item"]] = relationship(
    "Item",
    back_populates="owner",
    collection_class=set,
    info={
        "doc": "Owned items",
        "direction": "OneToMany",
        "use_rel": True,
    },
)

Metadata

Release files for exdrf-al 0.1.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for exdrf-al 0.1.22
File Size Uploaded Provenance Actions
exdrf_al-0.1.22.tar.gz 55.8 kB Without provenance Details for exdrf_al-0.1.22.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for exdrf-al 0.1.22
File Interpreter ABI Platform Actions
exdrf_al-0.1.22-py3-none-any.whl Python 3 none any Details for exdrf_al-0.1.22-py3-none-any.whl

Total release size: 122.1 kB

Release files / exdrf_al-0.1.22.tar.gz

Download URL exdrf_al-0.1.22.tar.gz
Size 55.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c9e1d97b81e41fb0bc80111b2723ce577f3ade5551d8a29918d91b9c472b3fd7
BLAKE2b-256 checksum
How to use checksums
fc01f5ce601f1f0a4865294ec9879c97e59bc773105a84eb413a4c7b811242a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / exdrf_al-0.1.22-py3-none-any.whl

Download URL exdrf_al-0.1.22-py3-none-any.whl
Size 66.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d82cc23479051535de56211e12672f019e869dc7cdfcd9255d1ee73af50e0a8e
BLAKE2b-256 checksum
How to use checksums
3a5450bf217c39bb939c6ce889e046ce668f294827da4539232cc1a1c86b3e48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for exdrf-al 0.1.22

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page