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.3.tar.gz (5.8 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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ticrobe_pgsql-26.4.3.tar.gz
  • Upload date:
  • Size: 5.8 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.3.tar.gz
Algorithm Hash digest
SHA256 9d239c6be4e3ed57cf770748aa82cc6375daf2343b21ca1752aa9b9ce7d523dc
MD5 a35cb8a074f9d4a093da573f178808fe
BLAKE2b-256 50c74bb9871d3f9d74ec930014c72f398ea9188b278abee3374b5c609bbe2eb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ticrobe_pgsql-26.4.3-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aabab1e8f8e24fd2b4f759020b245facf186febb2ede3cf0b612ceed34b39075
MD5 5ed94a47c55dbf94bd21e39c3bf16052
BLAKE2b-256 ac67f6d7287e4c5dcb420f6596101971b22a6ab9c037762f128fe75d1cc56781

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