{"id":10030,"library":"pgdb","title":"PostgreSQL Database Wrapper","description":"pgdb is a lightweight Python wrapper around `psycopg2-binary` designed to simplify basic interactions with PostgreSQL databases. It provides a simple API for connecting, executing queries, and fetching results. The library, currently at version 0.0.11, appears to be in maintenance mode with its last update over two years ago.","status":"maintenance","version":"0.0.11","language":"en","source_language":"en","source_url":"https://github.com/KehaoWu/pgdb","tags":["database","postgresql","wrapper","psycopg2"],"install":[{"cmd":"pip install pgdb","lang":"bash","label":"Install pgdb"}],"dependencies":[{"reason":"pgdb is a wrapper around psycopg2, which provides the underlying PostgreSQL driver.","package":"psycopg2-binary","optional":false}],"imports":[{"note":"The `connect` function is directly accessible as `pgdb.connect` after importing the `pgdb` module.","symbol":"connect","correct":"import pgdb"}],"quickstart":{"code":"import pgdb\nimport os\n\nDB_HOST = os.environ.get('PGDB_HOST', 'localhost')\nDB_NAME = os.environ.get('PGDB_DATABASE', 'test_db')\nDB_USER = os.environ.get('PGDB_USER', 'postgres')\nDB_PASS = os.environ.get('PGDB_PASSWORD', 'mysecretpassword') # REMEMBER to change in prod\n\nconn = None\ntry:\n    conn = pgdb.connect(host=DB_HOST, database=DB_NAME, user=DB_USER, password=DB_PASS)\n    cursor = conn.cursor()\n\n    # Cleanup for re-runs and create table\n    cursor.execute(\"DROP TABLE IF EXISTS example_data;\")\n    cursor.execute(\"CREATE TABLE example_data (id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL);\")\n    conn.commit()\n\n    # Insert data\n    cursor.execute(\"INSERT INTO example_data (name) VALUES ('Alice'), ('Bob'), ('Charlie');\")\n    conn.commit()\n\n    # Fetch and print data\n    cursor.execute(\"SELECT id, name FROM example_data;\")\n    print(\"Fetched data:\")\n    for row in cursor.fetchall():\n        print(row)\n\nexcept pgdb.Error as e:\n    print(f\"Database error: {e}\")\n    if conn:\n        conn.rollback() # Rollback on error\nfinally:\n    if conn:\n        conn.close()","lang":"python","description":"This quickstart demonstrates how to establish a connection, create a table, insert data, and fetch results using `pgdb`. It utilizes environment variables for database credentials, falling back to common defaults for local testing. It also includes basic error handling and resource cleanup."},"warnings":[{"fix":"Ensure `psycopg2-binary` is installed: `pip install psycopg2-binary`. If you have `psycopg2` and encounter issues, consider uninstalling it before installing `pgdb`.","message":"`pgdb` specifically requires `psycopg2-binary`. If you have `psycopg2` installed, `pgdb` might attempt to use it, but its `setup.py` explicitly lists `psycopg2-binary`.","severity":"gotcha","affected_versions":"0.0.1 and later"},{"fix":"Evaluate your project's needs. For complex applications requiring advanced features, consider using `psycopg2` directly or a more comprehensive ORM/database client library.","message":"As a simple wrapper, `pgdb` offers basic database interaction but lacks advanced features like ORM capabilities, sophisticated connection pooling, or asynchronous operations found in larger, more actively maintained libraries (e.g., SQLAlchemy, asyncpg).","severity":"gotcha","affected_versions":"All versions"},{"fix":"For new projects or long-term critical applications, consider using more actively maintained PostgreSQL libraries like `psycopg2` (or `psycopg` for Python 3.7+), `psycopg2-binary`, or ORMs like SQLAlchemy that have robust community support and regular updates.","message":"The `pgdb` library has not been updated since February 2022, indicating a lack of active development or maintenance. This could lead to compatibility issues with newer Python versions or PostgreSQL features.","severity":"deprecated","affected_versions":"All versions (due to inactivity)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install pgdb`","cause":"The `pgdb` library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'pgdb'"},{"fix":"Double-check the `host`, `database`, `user`, and `password` arguments passed to `pgdb.connect()`. Ensure your PostgreSQL server is running and accessible from your application's environment.","cause":"Incorrect database connection parameters (host, port, database name, user, or password) or the PostgreSQL server is not running/accessible.","error":"psycopg2.OperationalError: connection to server at \"localhost\" (::1), port 5432 failed: FATAL: password authentication failed for user \"postgres\""},{"fix":"Always import `pgdb` as a module (`import pgdb`) and then call the function via the module namespace (`pgdb.connect(...)`). Ensure no other file or module named `pgdb.py` is in your Python path that might shadow the installed library.","cause":"This error can occur if you attempt to access `connect` incorrectly, for example, after a `from pgdb import *` or if the module itself is shadowed.","error":"AttributeError: 'module' object has no attribute 'connect'"}]}