{"library":"postgres","title":"Postgres.py - A PostgreSQL Client Abstraction","description":"postgres is a high-value abstraction over the psycopg2 database driver, simplifying interactions with PostgreSQL databases. Currently at version 4.0, the library offers a more Pythonic API, an Object-Relational Mapper (ORM), and improved cursor management. Releases are made as needed, focusing on usability and PostgreSQL-specific features.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install postgres"],"cli":null},"imports":["from postgres import Postgres"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom postgres import Postgres\n\n# Ensure PostgreSQL is running and accessible, e.g., on localhost:5432\n# and 'test_db' exists with user 'postgres' and no password (or configure as needed).\n# For production, use environment variables or a configuration management system.\n\ndb_url = os.environ.get('POSTGRES_URL', 'postgres://postgres:@localhost:5432/test_db')\n\ntry:\n    db = Postgres(db_url)\n    \n    # Run SQL statements\n    db.run(\"DROP TABLE IF EXISTS foo\")\n    db.run(\"CREATE TABLE foo (bar TEXT, baz INT)\")\n    db.run(\"INSERT INTO foo (bar, baz) VALUES ('buz', 42)\")\n    db.run(\"INSERT INTO foo (bar, baz) VALUES ('bit', 537)\")\n    print(\"Table 'foo' created and data inserted.\")\n\n    # Fetch a single result or None\n    result_one = db.one(\"SELECT * FROM foo WHERE bar='buz'\")\n    print(f\"Single result for 'buz': {result_one}\")\n\n    # Fetch all results\n    results_all = db.all(\"SELECT * FROM foo ORDER BY bar\")\n    print(f\"All results, ordered: {results_all}\")\n    \n    # Using bind parameters to prevent SQL injection\n    param_value = 'buz'\n    result_param = db.one(\"SELECT baz FROM foo WHERE bar=%(value)s\", value=param_value)\n    print(f\"Result using bind parameter for 'buz' baz: {result_param}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your PostgreSQL server is running and the connection details are correct.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to a PostgreSQL database using `postgres.py`, create a table, insert data, and fetch results using `run()`, `one()`, and `all()` methods. It also illustrates the use of bind parameters for safe query execution.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"4.0","pypi_latest":"4.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.8,"avg_import_s":0.1,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.07,"mem_mb":3.7,"disk_size":"26.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.05,"mem_mb":3.7,"disk_size":"30M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.13,"mem_mb":4.2,"disk_size":"28.5M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.13,"mem_mb":4.2,"disk_size":"32M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.11,"mem_mb":4,"disk_size":"20.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.11,"mem_mb":4,"disk_size":"24M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.11,"mem_mb":4.8,"disk_size":"20.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.12,"mem_mb":4.8,"disk_size":"23M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.07,"mem_mb":3.8,"disk_size":"26.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"postgres","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.06,"mem_mb":3.8,"disk_size":"29M"}]}}