Skip to main content

Librería simple para interactuar con PostgreSQL usando SQL puro

Project description

🐘 tkla_postgres_client

Librería ligera y poderosa para trabajar con PostgreSQL usando SQL puro, sin complicaciones y sin ORM.

Ideal para proyectos rápidos, microservicios, APIs y sistemas donde prefieres control total sobre tus consultas SQL.


🚀 Características

  • 🔌 Conexión automática usando DATABASE_URL
  • 🛠️ Creación de tablas desde un dict estilo schema JSON
  • 🔄 Soporte completo a operaciones CRUD: SELECT, INSERT, UPDATE, DELETE
  • 🧠 Métodos utilitarios: exists(), count()
  • 🧾 Retorno estandarizado en todos los métodos (dict con success, data, message)
  • 🧱 Seguridad por defecto: no se permiten UPDATE o DELETE sin condiciones
  • 🚫 Sin dependencias de ORM (como SQLAlchemy)
  • 📋 Logging centralizado, sin interrupciones por errores
  • 🔁 Compatible con frameworks como Flask, FastAPI, etc.

📦 Instalación

Instalación desde PyPI:

pip install tkla_postgres_client

O desde el código fuente:

git clone https://github.com/LOVENXON/tkla_postgres_client.git
cd tkla_postgres_client
pip install -e .

⚙️ Uso Básico

1️⃣ Conexión

from tkla_postgres_client.core import PostgresClient

db = PostgresClient("postgresql://user:pass@host:port/dbname")

2️⃣ Crear Tablas

from tkla_postgres_client.builder import create_tables

schema = {
    "users": {
        "id": {"data_type": "serial", "primary_key": True},
        "name": {"data_type": "varchar", "length": 100, "nullable": False},
        "email": {"data_type": "varchar", "length": 100, "unique": True}
    }
}

create_tables(schema, db)

3️⃣ Operaciones CRUD

➕ Insertar

db.insert_data({
    "users": {"name": "Ana", "email": "ana@example.com"}
})

🔍 Consultar

db.select_data({
    "users": {
        "conditions": {"email": "ana@example.com"},
        "columns": ["id", "name"],
        "order_by": ["created_at DESC"],
        "limit": 1
    }
})

📝 Actualizar

db.update_data({
    "users": {
        "values": {"name": "Ana Actualizada"},
        "conditions": {"email": "ana@example.com"}
    }
})

❌ Eliminar

db.delete_data({
    "users": {"conditions": {"email": "ana@example.com"}}
})

🔍 Métodos Útiles

¿Existe un registro?

db.exists({
    "users": {"conditions": {"email": "ana@example.com"}}
})  # True / False

¿Cuántos registros hay?

db.count({
    "users": {"conditions": {"active": True}}
})  # int

🧹 Buenas Prácticas

✅ Usa una sola conexión por request (por ejemplo, con Flask.g)
✅ Siempre cierra la conexión con db.close() al final del ciclo
✅ Valida campos requeridos antes de realizar inserciones o actualizaciones


📄 Licencia

MIT – Libre para uso personal y comercial.


✨ Autor

Lovenson Pierre
📧 lovesonpierre25@gmail.com
🐙 GitHub: LOVENXON

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

tkla_postgres_client-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

tkla_postgres_client-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file tkla_postgres_client-0.1.0.tar.gz.

File metadata

  • Download URL: tkla_postgres_client-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for tkla_postgres_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f98129646b8205e34bc1aa2549660bd72dc74948bcbe026d6a1cba899b054b2c
MD5 6bb59d983f5c1bc0edaa325b00a54b31
BLAKE2b-256 da528c0bf20c515ed83bff8caea3a4980d54381e7aee124cbb5a1cc29ee7206d

See more details on using hashes here.

File details

Details for the file tkla_postgres_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tkla_postgres_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ae21d38a599d1bd4641f4fc2ac046f209682a626dac6f5dc06cc4b0627ba60
MD5 17c01b0c52aa001faef75c040f42c07f
BLAKE2b-256 fc30de9741011463bf496aa1e7c71d203290d5ede48134938c29ed68ee54754a

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