Driver for PostgreSQL written fully in Rust and exposed to Python. Main goals of the library is speed and type safety.
You can find full documentation here - PSQLPy documentation
You can install package with pip
or poetry
.
poetry:
> poetry add psqlpy
pip:
> pip install psqlpy
Or you can build it by yourself. To do it, install stable rust and maturin.
> maturin develop --release
Usage is as easy as possible. Create new instance of ConnectionPool and start querying 87C5 . You don't need to startup connection pool, the connection pool will create connections as needed.
from typing import Any
from psqlpy import ConnectionPool, QueryResult
async def main() -> None:
db_pool = ConnectionPool(
username="postgres",
password="pg_password",
host="localhost",
port=5432,
db_name="postgres",
max_db_pool_size=2,
)
res: QueryResult = await db_pool.execute(
"SELECT * FROM users",
)
print(res.result())
db_pool.close()
We have made some benchmark to compare PSQLPy
, AsyncPG
, Psycopg3
.
Main idea is do not compare clear drivers because there are a few situations in which you need to use only driver without any other dependencies.
So infrastructure consists of:
- AioHTTP
- PostgreSQL driver (
PSQLPy
,AsyncPG
,Psycopg3
) - PostgreSQL v15. Server is located in other part of the world, because we want to simulate network problems.
- Grafana (dashboards)
- InfluxDB
- JMeter (for load testing)
The results are very promising! PSQLPy
is faster than AsyncPG
at best by 2 times, at worst by 45%. PsycoPG
is 3.5 times slower than PSQLPy
in the worst case, 60% in the best case.