Skip to main content

tX.tDataStore PostgreSQL helper package for common database operations.

Project description

ticrobe.pgsql

Python package for PostgreSQL database operations.

Published package name: ticrobe.pgsql

Version: 26.4.2

Install

pip install ticrobe.pgsql

For local development from this workspace:

pip install -e .

Build and upload to PyPI

Build from inside src/tX.tPgSql:

python -m pip install --upgrade pip build twine
python -m build
python -m twine check dist/*

Upload using a PyPI API token:

python -m twine upload -u __token__ -p pypi-YOUR_API_TOKEN dist/*

Important:

  • In twine, the "password" is your PyPI API token
  • The username should be exactly __token__
  • The package files are generated in src/tX.tPgSql/dist/

Quick start

import asyncio

from ticrobe.pgsql import DatabaseConfig, PostgresDB

async def main() -> None:
    config = DatabaseConfig(
        host="localhost",
        port=5432,
        database="mydb",
        schema="public",
        user="postgres",
        password="secret",
    )

    db = PostgresDB()
    await db.connect(config)
    await db.create_table(
        {
            "table_name": "users",
            "columns": {
            "id": "SERIAL PRIMARY KEY",
            "name": "VARCHAR(100) NOT NULL",
            "email": "VARCHAR(255) UNIQUE NOT NULL",
            "created_at": "TIMESTAMP DEFAULT CURRENT_TIMESTAMP",
        },
        },
    )

    user = await db.insert(
        {
            "name": "Asha",
            "email": "asha@example.com",
        },
        returning=("id", "name", "email"),
    )
    if user is None:
        raise RuntimeError("Insert failed")

    await db.update(
        user["id"],
        {"name": "Asha R"},
        returning=("id", "name", "email"),
    )
    rows = await db.fetch_all("SELECT * FROM users ORDER BY id")
    await db.delete(user["id"])
    await db.disconnect(config)


asyncio.run(main())

You can also load connection settings from PostgreSQL environment variables:

config = DatabaseConfig.from_env()

Supported environment variables include PGHOST, PGPORT, PGDATABASE, PGSCHEMA, PGUSER, PGPASSWORD, and PGCONNECT_TIMEOUT.

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

ticrobe_pgsql-26.4.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

ticrobe_pgsql-26.4.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file ticrobe_pgsql-26.4.2.tar.gz.

File metadata

  • Download URL: ticrobe_pgsql-26.4.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ticrobe_pgsql-26.4.2.tar.gz
Algorithm Hash digest
SHA256 3102fda93ca22b7a6852c7b5099309fc9a59c983a5726274c45f17a0a2465116
MD5 bc4c3d6cd5e7d2404461f8eb604420fc
BLAKE2b-256 79092edecc11afbfb43a207315e01803b5c2190d7e4d31d9d9044ed9bacf95fc

See more details on using hashes here.

File details

Details for the file ticrobe_pgsql-26.4.2-py3-none-any.whl.

File metadata

  • Download URL: ticrobe_pgsql-26.4.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ticrobe_pgsql-26.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f056ac0c97e956facb789d2f0025b80de49e634f58e5afdbe08a90e1894a645e
MD5 46a6c048fc652be20d918f1a030ddfa0
BLAKE2b-256 b8680c6d0a608f866101b9bf6b341457388dda93a11a4a49d9dc921cce1b322c

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