Skip to main content

A library providing reusable utilities for SQLAlchemy.

Project description

unboil-sqlalchemy-mixins

Reusable mixins for SQLAlchemy models, designed to save you time and reduce boilerplate in your Python ORM code.

Features

  • IdentifiableMixin: Adds a string primary key with optional prefix to your models.
  • TimestampedMixin: Adds created_at and updated_at fields with automatic timestamping.

Installation

pip install unboil-sqlalchemy-mixins

Usage

IdentifiableMixin

Add a string id primary key to your models. You can also use a prefix for the ID:

from sqlalchemy.orm import DeclarativeBase
from unboil_sqlalchemy_mixins import IdentifiableMixin

class Base(DeclarativeBase):
    pass

class User(IdentifiableMixin, Base):
    __tablename__ = "users"
    # ... your fields ...

# Or with a prefix:
class PrefixedUser(IdentifiableMixin.with_prefix("user_"), Base):
    __tablename__ = "prefixed_users"
    # ... your fields ...

TimestampedMixin

Add created_at and updated_at fields that are automatically managed:

from sqlalchemy.orm import DeclarativeBase
from unboil_sqlalchemy_mixins import TimestampedMixin

class Base(DeclarativeBase):
    pass

class Post(TimestampedMixin, Base):
    __tablename__ = "posts"
    # ... your fields ...

Mixins API

IdentifiableMixin

  • Adds a string id primary key (32 hex chars by default).
  • Use IdentifiableMixin.with_prefix(prefix) to add a custom prefix to the ID.

TimestampedMixin

  • Adds created_at and updated_at fields (timezone-aware, auto-managed).

License

MIT

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

unboil_sqlalchemy_utils-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

unboil_sqlalchemy_utils-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file unboil_sqlalchemy_utils-0.1.0.tar.gz.

File metadata

  • Download URL: unboil_sqlalchemy_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for unboil_sqlalchemy_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e6dea95be6ffc84c513540268053cc0983a3373eaaf21963bf766e3cc253a053
MD5 8f9324e1e9ac57cfd5d5c5472de3b95d
BLAKE2b-256 1960d4c66345a350c45c5eb0a6a0068164d490b9b7619a959fae4d7df7a731a0

See more details on using hashes here.

File details

Details for the file unboil_sqlalchemy_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for unboil_sqlalchemy_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 500b6ff7c7a621d077a5c7db252184724025d406fce56cc9aa996c71924cf71f
MD5 321c6a49f30c48015b6e4c6d05aaa2cb
BLAKE2b-256 5851bb79642d75bcd029014be7d35f973d1e3c517a4d08534676f610ff261eb1

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