Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyPI Release Version GitHub Workflow Status for tests GitHub Workflow Status for docs Codacy coverage Dependabot Gitter chat

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

  • Free software: BSD license

  • Requires: Python 3.5

Documentation

Features

  • 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, Tornado, aiohttp and Quart

  • Rich PostgreSQL JSONB support

Installation

pip install gino

Showcase

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),
    ).where(
        User.id > 10,
    ).gino.status()
    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)


asyncio.get_event_loop().run_until_complete(main())

About The Name

About the name GINO Is Not ORM - because I don’t really like ORM (smile). GINO does perform the Object-Relational Mapping work under the Data Mapper Pattern, but it is just not a traditional ORM. The Objects in GINO are completely stateless from database - they are pure plain Python objects in memory. Changing their attribute values does not make them “dirty” - or in a different way of thinking they are always “dirty”. Any access to database must be explicitly executed. Using GINO is more like making up SQL clauses with Models and Objects, executing them to make changes in database, or loading data from database and wrapping the results with Objects again. Objects are just row data containers, you are still dealing with SQL which is represented by Models and SQLAlchemy core grammars. Besides if you don’t like ORM at all, you can use GINO without ORM:

from gino import Gino

db = Gino()

user = db.Table(
    'users', db,
    db.Column('id', db.BigInteger(), primary_key=True),
    db.Column('nickname', db.Unicode()),
)

async def main():
    async with db.with_bind('postgresql://localhost/gino'):
        users = await db.select([user]).gino.all()
        print(users)


import asyncio

asyncio.get_event_loop().run_until_complete(main())

Contribute

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:

$ make install test

For the tests to be run, a database has to be available (please read more in CONTRIBUTING.rst)

Meanwhile, these are also very much appreciated:

Projects using GINO

  • AintQ - asyncio task queue on PostgreSQL

  • ExchangeratesAPI - Foreign exchange rates API with currency conversion

Credits

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. And we are hiring!

GINO is developed proudly with PyCharm.

Metadata

Release files for gino 1.0.0rc4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gino 1.0.0rc4
File Size Uploaded
gino-1.0.0rc4.tar.gz 44.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gino 1.0.0rc4
File Interpreter ABI Platform
gino-1.0.0rc4-py3-none-any.whl Python 3 none any Details

Total release size: 90.9 kB

Release files / gino-1.0.0rc4.tar.gz

Download URL gino-1.0.0rc4.tar.gz
Size 44.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1a3ef763218b0b1041cb6c01958a901dcf90d438b37377af0a78a279870b0ec1
BLAKE2b-256 checksum
How to use checksums
b6c92fa95c4eaf7082bdfc1e326f9f6c3cfa971eff1ea5d1abc16b34ffc1e860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.2 Linux/5.0.0-1032-azure

Release files / gino-1.0.0rc4-py3-none-any.whl

Download URL gino-1.0.0rc4-py3-none-any.whl
Size 46.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce87a865d402547a9bc498e5301d56d97bec8a1d96e30d40059873557736901f
BLAKE2b-256 checksum
How to use checksums
76f070691df06092010f43f77fc40c3e3af6ba4828e551a416eb676c8e935095
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.2 Linux/5.0.0-1032-azure

Release history Release notifications | RSS feed

1.0.1

2 release files

1.0.0

2 release files

This release

1.0.0rc4 This release

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

1 release file

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page