Skip to main content

Tortoise ORM backend for DuckDB

Project description

Tortoise ORM backend for DuckDB

This integration allows you to use asyncio duckdb APIs with Tortoise ORM.

Install

tortoise-orm-extra-duckdb is compatible with Python 3.11 and newer. You can install it from PyPI:

$ pip install tortoise-orm-extra-duckdb

Usage

It is very simple to use. You only need to add two lines of code to the original project and switch the database to duckdb.

import asyncio

from tortoise import Tortoise, fields, run_async
from tortoise.models import Model
+ from tortoise.patch import monkey_patch


class Event(Model):
    id = fields.IntField(primary_key=True)
    name = fields.TextField(description="Name of the event that corresponds to an action")
    datetime = fields.DatetimeField(
        null=True, description="Datetime of when the event was generated"
    )

    class Meta:
        table = "event"
        table_description = "This table contains a list of all the example events"

    def __str__(self):
        return self.name


async def main():
~   await Tortoise.init(db_url="duckdb://:memory:", modules={"models": ["__main__"]})
    await Tortoise.generate_schemas()

    event = await Event.create(id=1, name="Test")
    await Event.filter(id=event.id).update(name="Updated name")

    print(await Event.filter(name="Updated name").first())

    await Event(id=2, name="Test 2").save()
    print(await Event.all().values_list("id", flat=True))
    print(await Event.all().values("id", "name"))


if __name__ == "__main__":
+   monkey_patch()
    asyncio.run(main())

License

tortoise-orm-extra-duckdb is licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for details.

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_orm_extra_duckdb-2025.9.15.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

tortoise_orm_extra_duckdb-2025.9.15-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file tortoise_orm_extra_duckdb-2025.9.15.tar.gz.

File metadata

File hashes

Hashes for tortoise_orm_extra_duckdb-2025.9.15.tar.gz
Algorithm Hash digest
SHA256 0a0d3769e4dcf56adf12d955749a5b3c29691de9499150c98fd9271f3385dd47
MD5 06579dd1aeb7fbd7308f7d47b0925ac7
BLAKE2b-256 ecc3effdb820e8205b10907e1588b1d92039f266f67ffa6748c6faf12e92d748

See more details on using hashes here.

Provenance

The following attestation bundles were made for tortoise_orm_extra_duckdb-2025.9.15.tar.gz:

Publisher: publish.yml on cnfairydream/tortoise-orm-extra-duckdb

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

File details

Details for the file tortoise_orm_extra_duckdb-2025.9.15-py3-none-any.whl.

File metadata

File hashes

Hashes for tortoise_orm_extra_duckdb-2025.9.15-py3-none-any.whl
Algorithm Hash digest
SHA256 6d36c691450d781ffc8609c82594681443b42d24b97116fd479aa5bc2f43b7a7
MD5 2cb4dcc1a24555edf1104901a2291424
BLAKE2b-256 9084eec2310ce2a4aacd2273f4a81eacc4e1e0102a4250e1b0b3fcaa7ee60384

See more details on using hashes here.

Provenance

The following attestation bundles were made for tortoise_orm_extra_duckdb-2025.9.15-py3-none-any.whl:

Publisher: publish.yml on cnfairydream/tortoise-orm-extra-duckdb

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