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
dictestilo schema JSON - 🔄 Soporte completo a operaciones CRUD:
SELECT,INSERT,UPDATE,DELETE - 🧠 Métodos utilitarios:
exists(),count() - 🧾 Retorno estandarizado en todos los métodos (
dictconsuccess,data,message) - 🧱 Seguridad por defecto: no se permiten
UPDATEoDELETEsin 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f98129646b8205e34bc1aa2549660bd72dc74948bcbe026d6a1cba899b054b2c
|
|
| MD5 |
6bb59d983f5c1bc0edaa325b00a54b31
|
|
| BLAKE2b-256 |
da528c0bf20c515ed83bff8caea3a4980d54381e7aee124cbb5a1cc29ee7206d
|
File details
Details for the file tkla_postgres_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tkla_postgres_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9ae21d38a599d1bd4641f4fc2ac046f209682a626dac6f5dc06cc4b0627ba60
|
|
| MD5 |
17c01b0c52aa001faef75c040f42c07f
|
|
| BLAKE2b-256 |
fc30de9741011463bf496aa1e7c71d203290d5ede48134938c29ed68ee54754a
|