Registry / database / queries

queries

JSON →
library2.1.1pypypiunverified

Queries is a BSD licensed opinionated wrapper of the `psycopg2` library for interacting with PostgreSQL. It aims to reduce the complexity of `psycopg2` while adding features like a simplified API, connection pooling, and asynchronous support for Tornado. The library supports Python 2.7+ and 3.4+ and is currently at version 2.1.1.

pip install queries psycopg2-binary
INSTALL
IMPORT
SIG · QUERIES
Q
queries
databasepythonv2.1.1
Install
—
Import
—
Disk
—
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.9–3.13
musl
3.9–3.13
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
musl
py 3.10–3.940 runs
build_error
glibc
py 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()
Debug
Known issues
breakingVersion 2.0.0 removed official support for Python 2.6. Users on Python 2.6 must remain on `queries < 2.0.0` or upgrade their Python version.
fix
Upgrade to Python 2.7 or Python 3.4+.
affects: >=2.0.0
gotchaWhen using `psycopg2-binary` (the easier-to-install dependency), be aware that it includes its own C libraries (like `libpq` and `libssl`). For production environments, it is often recommended to install `psycopg2` from source to ensure it links against system libraries, providing better control over updates and avoiding potential conflicts.
fix
For production, `pip install queries psycopg2` and ensure necessary system build tools and `libpq-dev` are installed.
affects: All
gotchaPrior to version 2.0.0, a CPU pegging bug could occur in `TornadoSession` on connection errors due to improper cleanup of the IOLoop. This was fixed in `queries` 2.0.0.
fix
Upgrade to `queries` 2.0.0 or later to ensure proper `TornadoSession` cleanup.
affects: <2.0.0
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.
Agent activity
15 hits · last 30 days
node
12
Meta
1
Resources
queries — pip install queries · libregistry