Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
build_error
glibcpy 3.10–3.940 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Session
✓ from queries import Session
TornadoSession
✓ from queries import TornadoSession
Used for asynchronous operations with the Tornado web framework.
This quickstart demonstrates how to connect to a PostgreSQL database using `queries.Session`, create a table, insert data, and retrieve results. It utilizes environment variables for the database URI for flexible configuration.
import os
from queries import Session
# Configure your PostgreSQL connection URI
# Example: "postgresql://user:password@host:port/database_name"
# If omitted, defaults to "postgresql://<current_os_user>@localhost:5432/<current_os_user>"
DB_URI = os.environ.get('POSTGRES_URI', 'postgresql://postgres@localhost:5432/postgres')
def main():
try:
with Session(DB_URI) as session:
# Create a table
session.query("CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR(255))")
print("Table 'users' ensured.")
# Insert data
result = session.query("INSERT INTO users (name) VALUES (%s) RETURNING id", ('Alice',))
new_id = result.scalar()
print(f"Inserted user Alice with ID: {new_id}")
# Query data
results = session.query("SELECT id, name FROM users")
print("Current users:")
for row in results:
print(f" ID: {row.id}, Name: {row.name}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == '__main__':
main()
Upgrade
Version history
2.1.1latest on PyPI · released Nov 16, 2021
Audit
Dependencies
psycopg2requiredCore PostgreSQL adapter; `queries` is a wrapper around it.
psycopg2-binaryoptionalA pre-compiled binary version of `psycopg2` for easier installation, especially on Windows or without build tools.
tornadooptionalRequired for `TornadoSession` and asynchronous PostgreSQL operations.