Skip to main content

Generate attrs models content using DRF from sqlalchemy models.

Project description

exdrf-gen-al2at

exdrf-gen-al2at is an exdrf-gen plugin that generates attrs-based Python modules from an ExDataset built from your SQLAlchemy declarative models. Output is driven by Jinja2 templates under al2at_templates/ and the composite tree in exdrf_gen.fs_support (TopDir, CategDir, ResFile, …).

Python 3.12.2+ is required.

What it generates

Layout under the output directory:

  • Root __init__.py, api.py
  • Per category: {category}/__init__.py, {category}/api.py
  • Per resource: {category}/{resource}.py from c/m.py.j2

Templates receive out_module, db_module, type_to_attrs, and standard dataset/resource context from exdrf-gen (see the exdrf-gen README for fs_support and preserve markers).

Dependencies

Declared in pyproject.toml for this package:

  • attrs

You also need (same environment as your SQLAlchemy models):

  • exdrf-gen — shared CLI, Jinja environment, fs_support
  • exdrf-alGetDataset and dataset_from_sqlalchemy for the DATASET argument
  • click — used by the CLI

Install the plugin package in editable or release form alongside those dependencies.

Command-line usage

The command is registered on the shared exdrf_gen Click group. With exdrf-gen installed:

exdrf-gen al2at DATASET OUT-PATH OUT-MODULE DB-MODULE

Same entry point via python -m exdrf_gen (loads plugins, then the CLI):

python -m exdrf_gen al2at DATASET OUT-PATH OUT-MODULE DB-MODULE

Arguments:

  • DATASETmodule.path:Symbol pointing to your SQLAlchemy declarative Base (or equivalent). Resolved by exdrf_al.click_support.GetDataset.
  • OUT-PATH — output directory (created as needed). Override with env var EXDRF_AL2AT_PATH.
  • OUT-MODULE — Python package name for generated imports.
  • DB-MODULE — module where SQLAlchemy model classes live (passed into templates).

Global options on the root group include --debug.

Python API

from exdrf_gen_al2at.creator import generate_attrs_from_alchemy
from exdrf_gen.jinja_support import jinja_env

generate_attrs_from_alchemy(
    d_set=dataset,
    out_path="/path/to/out",
    out_module="my_app.generated",
    db_module="my_app.db.models",
    env=jinja_env,
)

Plugin registration

This package registers:

[project.entry-points.'exdrf.plugins']
exdrf_gen = 'exdrf_gen_al2at'

Importing exdrf_gen_al2at calls install_plugin with the template directory so jinja_env can resolve al2at_templates.

See also

  • exdrf-genREADME.md (plugins, Jinja, fs_support)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exdrf_gen_al2at-0.1.17.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exdrf_gen_al2at-0.1.17-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file exdrf_gen_al2at-0.1.17.tar.gz.

File metadata

  • Download URL: exdrf_gen_al2at-0.1.17.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for exdrf_gen_al2at-0.1.17.tar.gz
Algorithm Hash digest
SHA256 a5b079e7438f0b81ad5f271ba448e23ec52640cd08de59417a98d61e963629b7
MD5 6a5b8f2c02445c276f3edddc70ed7e7b
BLAKE2b-256 cc63112174157c05c7ca62ff563bba52e520ec12acdcfac750474ac92e1e7a5e

See more details on using hashes here.

File details

Details for the file exdrf_gen_al2at-0.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for exdrf_gen_al2at-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 705a2dfa94a65bdb2a502af3d1d36c76d53051db02bf0f26ffb016ddfcd1e4c3
MD5 cb20b906d9aba82050ae646d8279eb2d
BLAKE2b-256 2fcb6a5dde22e116eaf5c2e8d4f893752a8831ece6527f6452be18864fb62604

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page