Skip to content

richecr/duck-orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

caf12a1 · Dec 8, 2024
May 13, 2023
Dec 8, 2024
Nov 7, 2021
Dec 8, 2024
Dec 8, 2024
Jul 10, 2021
Aug 8, 2021
May 7, 2023
May 13, 2023
Oct 31, 2021
May 13, 2023
Jul 11, 2021
May 13, 2023
Aug 20, 2022
May 13, 2023
Oct 2, 2021
Dec 8, 2024
Dec 8, 2024
Dec 8, 2024

Repository files navigation

The Duck-ORM package is an asynchronous ORM for Python, with support for Postgres and SQLite. ORM is built with:

Requirements: Python 3.8+

Duck-ORM is still under development.

Installation

$ pip install duck-orm

!!! note Don't forget to install databases before installing duck-orm.

Quickstart

For this example we will create a connection to the SQLite database and create a model.

$ pip install databases[sqlite]
$ pip install ipython

Note that we want to use ipython here, because it supports using await expressions directly from the console.

Creating the connection to the SQLite database:

from databases import Database
from duck_orm.model import Model

db = Database('sqlite:///example.db')
await db.connect()

Defining a model:

from duck_orm.sql import fields as Field

class Person(Model):
    __tablename__ = 'persons'
    __db__ = db

    id: int = Field.Integer(primary_key=True, auto_increment=True)
    first_name: str = Field.String(unique=True)
    last_name: str = Field.String(not_null=True)
    age: int = Field.BigInteger(min_value=18)

# Table creation in the database.
await Person.create()
  • The __tablename__ attribute is used to define the table's name in the database.
  • The __db__ attribute is the instance of the database connection.
  • And then the definition of the fields, their types and restrictions.
  • And finally, the table creation in the database.

Author

License

DuckORM is built as an open-source tool and remains completely free(MIT license).