sqlalchemy-triopg
A thin Trio-backed wrapper for SQLAlchemy's asyncpg PostgreSQL driver.
This wrapper is named after the existing raw asyncpg wrapper triopg, but does not actually use it. If you want to use asyncpg directly, use that package instead.
$ pdm add sqlalchemy-triopg
# or
$ pip install --user sqlalchemy-triopg
Usage
SQLAlchemy is able to automatically discover the dialect available through this package as soon as you install it. When creating your engine, just pass the triopg driver like so:
engine = create_async_engine("triopg://postgres:password@db/postgres")
Requisites
This package uses the trio-asyncio package to provide a compatibility layer with asyncio; it is what enables the "wrapping" in favor of just a re-implementation. However it also means that your program needs to ensure the Trio event loop is running, either via manually calling your program with trio_asyncio.run or by wrapping your main coroutine definition in trio_asyncio.open_loop.
For many projects like web apps, the terminal command for starting the application does not let you change how to start the ASGI server. Aside from creating a custom worker class and specifying it (like a custom Hypercorn or Gunicorn worker), you'll need to create a bootstrapping script where you can manually call trio_asyncio.run to your server's API.
This is because, unfortunately, binding an async context manager to the lifecycle of your application (a feature supported by both BlackSheep and FastAPI) in which you call trio_asyncio.open_loop doesn't seem to work.
Using Hypercorn's API, an example boot.py script could look like this:
#!/bin/python
import trio_asyncio
from hypercorn.config import Config
from hypercorn.trio import serve
from application import app
if __name__ == "__main__":
trio_asyncio.run(serve, app, Config.from_toml("application.toml"))
Considerations
This package uses trio-asyncio, and you'll need to take that into account if you're combining Trio and existing asyncio tooling. If those tools do not use a bridge library like anyio, it's very likely that you'll need to extend them the coroutines by wrapping them in trio_asyncio.aio_as_trio (or using it as a decorator on your own coroutine functions).
This is an intentional anti-feature of trio-asyncio.
License
This package makes use of SQLAlchemy and Trio-Asyncio, both of which are licensed under MIT.
This package is licensed under the BSD 3-Clause Clear License.
This package is Treeware. If you use it in production, consider buying the world a tree to thank me for my work. By contributing to my forest, you’ll be creating employment for local families and restoring wildlife habitats.
Metadata
Release files for sqlalchemy-triopg 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlalchemy_triopg-1.0.1.tar.gz | 6.4 kB | Without provenance | Details for sqlalchemy_triopg-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlalchemy_triopg-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for sqlalchemy_triopg-1.0.1-py3-none-any.whl |
Total release size: 12.1 kB
Release files / sqlalchemy_triopg-1.0.1.tar.gz
| Download URL | sqlalchemy_triopg-1.0.1.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26846a1f5f47d9b0de68d683ada33f8eb73549bd3ad2fa24999b82c2a0d15883
|
|
BLAKE2b-256 checksum How to use checksums |
726e9a8e21e8ce5dd9de6cd7448dfc6b87d0dc6b82f100fe1e9385376158b27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.12.4 Windows/10
|
Release files / sqlalchemy_triopg-1.0.1-py3-none-any.whl
| Download URL | sqlalchemy_triopg-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce3d983eb66cee20e970868ccbc684cfb01349c963501c534f8699ad71a641b1
|
|
BLAKE2b-256 checksum How to use checksums |
88e7652521d0c4de6e257c9cc4ed237f110351e30abe1814e43f1b4719df1ed5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.12.4 Windows/10
|
Security for sqlalchemy-triopg 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.