Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/richecr/duck-orm
ORM async for Python
https://github.com/richecr/duck-orm
assynchronous database hacktoberfest orm postgresql python sql sqlite3
Last synced: about 4 hours ago
JSON representation
ORM async for Python
- Host: GitHub
- URL: https://github.com/richecr/duck-orm
- Owner: richecr
- License: mit
- Created: 2021-03-08T01:06:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-02T22:42:36.000Z (about 1 year ago)
- Last Synced: 2023-10-03T07:02:48.150Z (about 1 year ago)
- Topics: assynchronous, database, hacktoberfest, orm, postgresql, python, sql, sqlite3
- Language: Python
- Homepage: https://richecr.github.io/duck-orm/
- Size: 564 KB
- Stars: 12
- Watchers: 0
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# [DuckORM](https://pypi.org/project/duck-orm/)
The `Duck-ORM` package is an asynchronous ORM for Python, with support for **Postgres** and **SQLite**. ORM is built with:
- [databases](https://github.com/encode/databases)
**Requirements**: Python 3.8+
**Duck-ORM is still under development**.
## Installation
```bash
$ 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.
```bash
$ 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:
```Python
from databases import Database
from duck_orm.model import Modeldb = Database('sqlite:///example.db')
await db.connect()
```### Defining a model:
```Python
from duck_orm.sql import fields as Fieldclass Person(Model):
__tablename__ = 'persons'
__db__ = dbid: 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
- Rich Ramalho - [@richecr](https://github.com/richecr) - [@richzinho_ecr](https://twitter.com/richzinho_ecr)
## License
`DuckORM` is built as an open-source tool and remains completely free(MIT license).