Tentaclio PostgreSQL Connector

0.0.1 · active · verified Wed Apr 15

Tentaclio-postgres is a Python package that provides the necessary dependencies and extends the core Tentaclio library to enable seamless connections to PostgreSQL databases. It acts as a connector, allowing users to interact with PostgreSQL via Tentaclio's unified URL-based interface for data streams and database clients. The current version is 0.0.1. It is part of the broader Tentaclio ecosystem, which shows active development and updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a PostgreSQL database using `tentaclio.db()`. It highlights the use of a PostgreSQL URL and shows how to execute a simple query. Credentials can be provided directly in the URL or automatically injected from environment variables, prefixed with `TENTACLIO__CONN__`.

import os
import tentaclio

# Configure a PostgreSQL connection string (replace with your actual URL)
# For local testing, you might use 'postgresql://user:password@localhost:5432/mydatabase'
# Credentials can also be injected via environment variables (e.g., TENTACLIO__CONN__MYDB_PG_URL)
# For this example, we'll use a placeholder and demonstrate env var usage for a real setup.
# os.environ['TENTACLIO__CONN__EXAMPLE_PG'] = 'postgresql://user:password@host:port/database'

pg_url = os.environ.get('TENTACLIO__CONN__EXAMPLE_PG', 'postgresql://user:password@localhost:5432/testdb')

try:
    with tentaclio.db(pg_url) as client:
        print(f"Successfully connected to PostgreSQL via Tentaclio using URL: {pg_url}")
        # Execute a simple query
        result = client.query("SELECT 1 as test_column")
        print(f"Query result: {result.fetchone()}")
except Exception as e:
    print(f"Could not connect to PostgreSQL or execute query: {e}")
    print("Please ensure a PostgreSQL database is running and the connection string is valid.")

view raw JSON →