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.8.28.tar.gz (10.8 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.8.28-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for tortoise_orm_extra_duckdb-2025.8.28.tar.gz
Algorithm Hash digest
SHA256 70da4749350513d66d8781823f67f96285220e20e4d1892ea6f526cab94e0258
MD5 9f1837b01b1e1ae9eab26e6df38924ca
BLAKE2b-256 ef36fc8eda65cca40a8204b61d5f8981ad33817af3298d75bc78ec0c821911a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tortoise_orm_extra_duckdb-2025.8.28-py3-none-any.whl
Algorithm Hash digest
SHA256 a988f69aad216f932f17212880574e1955c99e4e3d74353c3489953af2dab636
MD5 caf8f8f6e4bd06dc4c7f659f31632142
BLAKE2b-256 a6a20aff04de1e5700fb6395ccf027eb720517d304b3d77ec894040c92ba7e21

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