Skip to main content

Mixins for sqlalchemy and pydantic

Project description

Mixemy

CI CD

Ruff Checked with pyright Packaged with Poetry

Mixemy is a small library providing a set of mixins for SQLAlchemy and Pydantic to simplify common CRUD operations, validation, and schema management.

Features

  • Models: Base classes and mixins that extend SQLAlchemy declarative_base() models with useful fields like IDs and timestamps.
  • Schemas: Pydantic schemas for input validation, serialization, and more.
  • CRUD: Generic CRUD classes that can be extended to handle common database interactions—create, read, update, and delete.

Installation

pip install mixemy

or, if you prefer Poetry:

poetry add mixemy

Quick Start

Below is a minimal example demonstrating how to use mixemy to create a SQLAlchemy model, corresponding Pydantic schemas, and a CRUD class:

from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String

from mixemy import crud, models, schemas

# Define a SQLAlchemy model with some default fields (e.g., id, created_at, updated_at)
class ItemModel(models.IdAuditModel):
    value: Mapped[str] = mapped_column(String)

# Define Pydantic schemas for input and updates
class ItemInput(schemas.InputSchema):
    value: str

class ItemUpdate(schemas.InputSchema):
    value: str

# Extend the generic CRUD class to specify the model and schemas
class ItemCRUD(crud.IdAuditCRUD[ItemModel, ItemInput, ItemUpdate]):
    pass

# Instantiate the CRUD class with the model
item_crud = ItemCRUD(ItemModel)

Explanation

  • ItemModel
    Inherits from models.IdAuditModel, which provides default columns such as id, created_at, and updated_at. We add our own value field as a String.

  • ItemInput & ItemUpdate
    These are Pydantic schemas that extend schemas.InputSchema. Use these for type-safe request inputs in create and update operations.

  • ItemCRUD
    Extends crud.IdAuditCRUD, which already implements generic CRUD operations (like create, read, update, delete) for our model and schemas. You can override these methods if you need custom behavior.

Why Use Mixemy?

  • Speed up development by reducing boilerplate for common operations.
  • Stay type-safe with Pydantic schemas and generics in CRUD classes.
  • Extensible—override base classes or methods to customize or add new functionality.
  • Built for maintainability with consistent code structure and naming.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub if you have suggestions or feature requests.

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes.
  4. Push to your branch and open a pull request.

Happy coding with Mixemy! If you find this library helpful, feel free to star it on GitHub or contribute.

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

mixemy-0.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

mixemy-0.1.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file mixemy-0.1.2.tar.gz.

File metadata

  • Download URL: mixemy-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mixemy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 013f5c513bce3a0df010130b28e0fee687bb962be9103de699e4e1a1f32414f6
MD5 65e85d61d40572db846d47fb433088e7
BLAKE2b-256 2f0d54dffd3bab11e6448a16b85cab266f477ff20def7bccfb6448403fcbc712

See more details on using hashes here.

Provenance

The following attestation bundles were made for mixemy-0.1.2.tar.gz:

Publisher: cd.yml on frostyfeet909/mixemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mixemy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mixemy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mixemy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 899c693ff6c08555df21772a423cbb716154899c56065dd1410f240b82db3fcc
MD5 e1327baf077775ae5754163e86f424ec
BLAKE2b-256 e88ab43f32935b740a54c6ddeee15dec7ed89f718ff70e5e686cbaa7ea6d1675

See more details on using hashes here.

Provenance

The following attestation bundles were made for mixemy-0.1.2-py3-none-any.whl:

Publisher: cd.yml on frostyfeet909/mixemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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