Skip to main content

Minimal PostgreSQL utility with psycopg2

Project description

postg.py

https://pypi.org/project/postg-q/0.1.0/

A minimal PostgreSQL database utility class using psycopg2 with basic methods for interacting with a PostgreSQL database.

Features

  • Connect to PostgreSQL
  • Create tables
  • Insert records
  • Select records (with optional filters)
  • Update records (by condition)
  • Delete records (by condition)
  • Count rows
  • Execute raw SQL queries with parameters

Requirements

  • Python 3.11+
  • psycopg2
  • python-dotenv (optional, for loading env variables)

Installation

pip install postg-q


## Docs

1. Initialize and connect

from postg import DB

db = DB(
    dbname="your_db_name",
    user="your_user",
    password="your_password",
    host="localhost",
    port="5432"
)
db.connect()

2. Create a table

schema = """
CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL
);
"""
db.create_table(schema)

3. Insert data

db.insert("users", {"name": "Alice", "email": "alice@example.com"})

4. Select data

users = db.select("users")
filtered = db.select("users", {"name": "Alice"})


5. Update records

db.update("users", filters={"name": "Alice"}, data={"email": "new@example.com"})

6. Delete records

db.delete("users", {"email": "new@example.com"})

7. Count rows

total = db.count("users")
filtered = db.count("users", {"name": "Bob"})

8. Run raw SQL queries

# Insert
db.query("INSERT INTO users (name, email) VALUES (%s, %s)", ("John", "john@example.com"))

# Select
result = db.query("SELECT * FROM users WHERE name = %s", ("John",))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postg_q-0.1.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postg_q-0.1.2-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file postg_q-0.1.2.tar.gz.

File metadata

  • Download URL: postg_q-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for postg_q-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c13f34a3bb6950e05e4e726c79033870a0583193ef60bab4f3da750808d9c305
MD5 7f8a3cce79b24b906f3ca4b5c91fcade
BLAKE2b-256 e9a89f102f7b39ef3717d5fc2ed246eeff4b27d08b493b150613ce7353e2c05d

See more details on using hashes here.

File details

Details for the file postg_q-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: postg_q-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for postg_q-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3ff72c25881533e9cb3a3232584fbf143c6c4cee52cf760bfa23866cf13c09e
MD5 3cc06a36f1768d453a31e39fab7452b2
BLAKE2b-256 ab539c5dafb7065df73635caeeb43e0b4cdd557eeeb6130dc3e10678189942f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page