Skip to main content

Extension field types for Tortoise ORM

Project description

tortoise-extensions

Optional extension field types for Tortoise ORM. This package targets Tortoise ORM 0.25.4 and later, but before 1.0 — Tortoise 1.x is not supported yet.

Install

Base package (requires Tortoise ORM in the supported range):

pip install tortoise-extensions

Optional extras:

pip install tortoise-extensions[pydantic]
pip install tortoise-extensions[uuid6]
pip install tortoise-extensions[pydantic,uuid6]

Usage

Pydantic JSON (pydantic extra)

from pydantic import BaseModel
from tortoise.models import Model

from tortoise_extensions.pydantic import PydanticJSONField


class Settings(BaseModel):
    theme: str = "dark"


class AppConfig(Model):
    settings: PydanticJSONField[Settings] = PydanticJSONField(
        Settings, default=Settings
    )

    class Meta:
        table = "app_configs"

PydanticJSONField round-trips through your Pydantic model: it accepts dicts from PostgreSQL JSONB, JSON strings from SQLite, and serializes models with model_dump(mode="json") on save.

UUID v6+ (uuid6 extra)

from tortoise.models import Model

from tortoise_extensions.uuid6 import FutureUUIDField


class Item(Model):
    id: FutureUUIDField = FutureUUIDField(primary_key=True)

    class Meta:
        table = "items"

Primary keys without an explicit default receive a UUID7 from the uuid6 package. PostgreSQL uses the native UUID column type; other backends store CHAR(36).

Contributing a new extension

  1. Open an issue first — describe the field behavior, SQL types per backend, which Tortoise versions you need, and the proposed optional-extra name (e.g. pip install tortoise-extensions[myextra]).
  2. After maintainers agree on the design, open a PR that includes:
    • Implementation in src/tortoise_extensions/<module>.py
    • Tests under tests/
    • An entry in [project.optional-dependencies] if the field needs third-party packages
    • README and docs updates for the new field
    • ISC SPDX headers on new files (licensor-config.yaml applies)
  3. Run pdm run quality locally before pushing.

Documentation

Published at docs.nicebots.xyz/tortoise-extensions.

pdm install -G docs
pdm run docs:build
pdm run docs:preview
pdm run docs:dev

Development

pdm install -G dev -G test -G docs
pdm run quality

Public APIs use Google-style docstrings; ruff enforces this via convention = "google".

License

ISC.

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

tortoise_extensions-0.0.1a1.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

tortoise_extensions-0.0.1a1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file tortoise_extensions-0.0.1a1.tar.gz.

File metadata

  • Download URL: tortoise_extensions-0.0.1a1.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.27.0 CPython/3.14.5 Linux/6.17.0-1013-azure

File hashes

Hashes for tortoise_extensions-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 a023e90bdd95b5b9ec8db4e3dea570300136ae34443d0e41a07aae449551f92a
MD5 516dc8a771362abba42af0d7229ac4e3
BLAKE2b-256 1d483e03f3be465621f695392231f0ee1cafe3059505fab67d3f0c58664e5f2b

See more details on using hashes here.

File details

Details for the file tortoise_extensions-0.0.1a1-py3-none-any.whl.

File metadata

File hashes

Hashes for tortoise_extensions-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 52942ca3b4124522a6364713488cf99d800dcda27d583229a041b6d79c4998f8
MD5 5f525fc56d90d9063521aca30d1a7c32
BLAKE2b-256 b51b43be97dd95efd9f877d2c84c6ad4d32496c7de0022d81ac745045b44e076

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