Skip to content
A wrapper around asyncpg for use with sqlalchemy
Branch: master
Clone or download
arusahni and nhumrich Add set_database_results() to the MockConnection class. (#99)
* Minor whitespace cleanup.

on-behalf-of: @sparkmeter <aru.sahni@sparkmeter.io>

* Fix bad indentation in the mock connection object.

on-behalf-of: @sparkmeter <aru.sahni@sparkmeter.io>

* Use the connection getter instead of an explcitly declared method.

on-behalf-of: @sparkmeter <aru.sahni@sparkmeter.io>

* Add set_database_results to the MockConnection class.

This improves symmetry with MockPGSingleton. It also prevents the
asyncio.Queue implementation from leaking to callers.

on-behalf-of: @sparkmeter <aru.sahni@sparkmeter.io>
Latest commit 2607565 May 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
asyncpgsa Add set_database_results() to the MockConnection class. (#99) May 21, 2019
docs Added `get_dialect` function (#84) May 16, 2018
tests Add sequence support (#97) Feb 11, 2019
.gitignore Added `get_dialect` function (#84) May 16, 2018
.travis.yml
Dockerfile bump versions and add test matrix (#91) Jul 30, 2018
LICENSE Initial commit Jul 22, 2016
MANIFEST Initial implementation Jul 27, 2016
README.md Add link to the docs in README (#95) Dec 20, 2018
contributing.md Run tests with docker-compose (#62) Jan 2, 2018
dev-requirements.txt bump versions and add test matrix (#91) Jul 30, 2018
docker-compose.yml bump versions and add test matrix (#91) Jul 30, 2018
setup.py bump versions and add test matrix (#91) Jul 30, 2018

README.md

Documentation Status

asyncpgsa

A python library wrapper around asyncpg for use with sqlalchemy

Backwards incompatibility notice

Since this library is still in pre 1.0 world, the api might change. I will do my best to minimize changes, and any changes that get added, I will mention here. You should lock the version for production apps.

  1. 0.9.0 changed the dialect from psycopg2 to pypostgres. This should be mostly backwards compatible, but if you notice weird issues, this is why. You can now plug-in your own dialect using pg.init(..., dialect=my_dialect), or setting the dialect on the pool. See the top of the connection file for an example of creating a dialect. Please let me know if the change from psycopg2 to pypostgres broke you. If this happens enough, I might make psycopg2 the default.

  2. 0.18.0 Removes the Record Proxy objects that would wrap asyncpg's records. Now asyncpgsa just returns whatever asyncpg would return. This is a HUGE backwards incompatible change but most people just used record._data to get the object directly anyways. This means dot notation for columns is no longer possible and you need to access columns using exact names with dictionary notation.

  3. 0.18.0 Removed the insert method. We found this method was just confusing, and useless as SqlAlchemy can do it for you by defining your table with a primary key.

sqlalchemy ORM

Currently this repo does not support SA ORM, only SA Core.

As we at canopy do not use the ORM, if you would like to have ORM support feel free to PR it. You would need to create an "engine" interface, and that should be it. Then you can bind your sessions to the engine.

sqlalchemy Core

This repo supports sqlalchemy core. Go here for examples.

Docs

Go here for docs.

Examples

Go here for examples.

install

pip install asyncpgsa

Note: You should not have asyncpg in your requirements at all. This lib will pull down the correct version of asyncpg for you. If you have asyncpg in your requirements, you could get a version newer than this one supports.

Contributing

To contribute or build this locally see contributing.md

FAQ

Does SQLAlchemy integration defeat the point of using asyncpg as a backend (performance)?

I dont think so. asyncpgsa is written in a way where any query can be a string instead of an SA object, then you will get near asyncpg speeds, as no SA code is ran.

However, when running SA queries, comparing this to aiopg, it still seams to work faster. Here is a very basic timeit test comparing the two. https://gist.github.com/nhumrich/3470f075ae1d868f663b162d01a07838

aiopg.sa: 9.541276566000306
asyncpsa: 6.747777451004367

So, seems like its still faster using asyncpg, or in otherwords, this library doesnt add any overhead that is not in aiopg.sa.

You can’t perform that action at this time.