Skip to main content

GINO

https://img.shields.io/pypi/v/gino.svg https://img.shields.io/travis/fantix/gino.svg Documentation Status Updates

GINO - GINO Is Not ORM - is an extremely simple Python ORM, using SQLAlchemy core to define table models, and asyncpg to interact with database.

There’s been a lot of words about ORM a.k.a. Object-relational mapping - good or bad - as well as a lot of ORM libraries in Python. It is crucial to pick a most suitable one for your project, and for your team. GINO tries to stay in the middle between ORM and non-ORM, offering an extremely simple option.

GINO tries to define database tables with plain old Python objects - they are normal Python objects, a rollback doesn’t magically change their values. Any database operations are explicit. There are no dirty models, no sessions, no magic. You have concrete control to the database, through a convenient object interface. That’s it.

GINO depends on asyncpg, which means it works only for PostgreSQL and asyncio, which means Python 3 is required - actually 3.6 required for now. Based on SQLAlchemy, gate to its ecosystem is open - feel free to use e.g. Alembic to manage your schema changes. And we specially designed a few candies for the Sanic server.

Usage

A piece of code is worth a thousand words:

from gino import Gino
from sqlalchemy import Column, BigInteger, Unicode

db = Gino()


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

    id = Column(BigInteger(), primary_key=True)
    nickname = Column(Unicode(), default='noname')

This is quite similar to SQLAlchemy ORM, but it is actually SQLAlchemy core:

  • db = Gino() is actually a sqlalchemy.MetaData object

  • class User actually defines a sqlalchemy.Table at User.__table__

Other than that, User is just a normal Python object:

u = User()
u.id = 7
u.id += 2
u.nickname = 'fantix'

Think as if User is defined normally (keep in imagination, not an example):

class User:
    def __init__(self):
        self.id = None
        self.nickname = None

However on class level, you have access to SQLAlchemy columns, which allows you to do SQLAlchemy core programming:

from sqlalchemy import select
query = select([User.nickname]).where(User.id == 9)

The Gino object offers a SQLAlchemy dialect for asyncpg, allowing to execute the query in asyncpg:

import asyncpg
conn = await asyncpg.connect('postgresql://localhost/gino')
query, params = db.compile(query)
rv = await conn.fetchval(query, *params)

And GINO offers some sugars:

u1 = await User.get(9, bind=conn)
u2 = await User.create(bind=conn, nickname=u1.nickname))

async with conn.transaction():
    query, params = db.compile(User.query.where(User.id > 2))
    async for u in User.map(conn.cursor(query, *params)):
        print(u.id, u.nickname)

Features

  • Declare SQLAlchemy core tables with plain model objects, no ORM magic

  • Easily construct queries and execute them through asyncpg

There’re a few usage examples in the examples directory.

Contribute

To run tests:

python setup.py test

Credits

Credit goes to all contributors 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.

History

0.2.2 (2017-08-02)

  • Support SQLAlchemy result processor

  • Added rich support on JSON/JSONB

  • Bug fixes

0.2.1 (2017-07-28)

  • Added update and delete API

0.2.0 (2017-07-28)

  • Changed API, no longer reuses asyncpg API

0.1.1 (2017-07-25)

  • Added db.bind

  • API changed: parameter conn renamed to optional bind

  • Delegated asyncpg Pool with db.create_pool

  • Internal enhancement and bug fixes

0.1.0 (2017-07-21)

  • First release on PyPI.

Metadata

Release files for gino 0.2.2

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 0.2.2
File Size Uploaded
gino-0.2.2.tar.gz 20.6 kB Details

Release files / gino-0.2.2.tar.gz

Download URL gino-0.2.2.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
340d8c0c87869c3396e5505a86d5d1bd249333ef5c02219d072541e6429906b5
BLAKE2b-256 checksum
How to use checksums
ac07a71e5039a2f31b28064e8670b6a3a57fd3015d27d7cd8887836f2414b55c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0.1

2 release files

1.0.0

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

This release

0.2.2 This release

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