GitHub - fantix/gino: GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.

 4 years ago
source link: https://github.com/fantix/gino
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.



68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f67696e6f2e737667 68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f66616e7469782f67696e6f2f6d61737465722e737667 68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f66616e7469782f67696e6f2f6d61737465722e737667 Documentation Status Updates Gitter chat

GINO - GINO Is Not ORM - is a lightweight asynchronous ORM built on top of SQLAlchemy core for Python asyncio. Now (early 2018) GINO supports only one dialect asyncpg.

  • Free software: BSD license
  • Requires: Python 3.6



  • Robust SQLAlchemy-asyncpg bi-translator with no hard hack
  • Asynchronous SQLAlchemy-alike engine and connection
  • Asynchronous dialect API
  • Asynchronous-friendly CRUD objective models
  • Well-considered contextual connection and transaction management
  • Reusing native SQLAlchemy core to build queries with grammar sugars
  • Support Sanic and Tornado
  • Rich PostgreSQL JSONB support


import asyncio
from gino import Gino

db = Gino()

class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer(), primary_key=True)
    nickname = db.Column(db.Unicode(), default='noname')

async def main():
    await db.set_bind('postgresql://localhost/gino')

    # Create tables
    await db.gino.create_all()

    # Create object, `id` is assigned by database
    u1 = await User.create(nickname='fantix')
    print(u1.id, u1.nickname)  # 1 fantix

    # Returns all user objects with "d" in their nicknames
    users = await User.query.where(User.nickname.contains('d')).gino.all()
    print(users)  # [<User object>, <User object>]

    # Find one user object, None if not found
    user = await User.query.where(User.nickname == 'daisy').gino.first()
    print(user)  # <User object> or None

    # Execute complex statement and return command status
    status, result = await User.update.values(
        nickname='No.' + db.cast(User.id, db.Unicode),
        User.id > 10,
    print(status)  # UPDATE 8

    # Iterate over the results of a large query in a transaction as required
    async with db.transaction():
        async for u in User.query.order_by(User.id).gino.iterate():
            print(u.id, u.nickname)



There are a few tasks in GitHub issues marked as help wanted. Please feel free to take any of them and pull requests are greatly welcome.

To run tests:

$ python setup.py test


Credit goes to all contributors listed or not listed in the AUTHORS file. This project is inspired by asyncpgsa, peewee-async and asyncorm. asyncpg and SQLAlchemy as the dependencies did most of the heavy lifting. This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Special thanks to my wife Daisy and her outsourcing company DecentFoX Studio, for offering me the opportunity to build this project. We are open for global software project outsourcing on Python, iOS and Android development.

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK