Skip to main content

Librería Python eco-back

Project description

eco-back

Librería Python para backend con soporte para PostgreSQL/PostGIS y clientes API

Características

  • Base de datos: Conexión y operaciones con PostgreSQL
  • PostGIS: Operaciones geoespaciales (puntos, polígonos, búsquedas por proximidad)
  • Cliente API: Cliente HTTP genérico y cliente específico UNP
  • Patrón Repository: Implementación de patrones de diseño para acceso a datos

Descripción

eco-back es una librería modular que facilita el desarrollo de aplicaciones backend, proporcionando abstracciones para bases de datos geoespaciales y consumo de APIs REST.

Instalación

Desde PyPI

pip install eco-back

Desde el código fuente

pip install -e .

Para desarrollo

pip install -e ".[dev]"

Uso

Cliente de Consecutivos (UNP)

from eco_back.api import Consecutivo

# Crear cliente
client = Consecutivo(base_url="https://api.unp.example.com")

# Obtener consecutivo
consecutivo = client.obtener(origen=1)
if consecutivo:
    print(f"Consecutivo: {consecutivo}")

client.close()

# Forma recomendada: usar context manager
with Consecutivo(base_url="https://api.unp.example.com") as client:
    consecutivo = client.obtener(origen=1)
    # Usar el consecutivo...

Cliente API Genérico

from eco_back.api import APIConfig, APIClient

config = APIConfig(
    base_url="https://api.example.com",
    timeout=30,
    headers={"Authorization": "Bearer token"}
)

with APIClient(config) as client:
    # GET request
    data = client.get("/endpoint")
    
    # POST request
    result = client.post("/endpoint", json={"key": "value"})

Conexión básica a PostgreSQL

from eco_back.database import DatabaseConfig, DatabaseConnection

config = DatabaseConfig(
    host="localhost",
    port=5432,
    database="mi_base_datos",
    user="usuario",
    password="password"
)

with DatabaseConnection(config) as db:
    resultados = db.execute_query("SELECT * FROM tabla")
    for row in resultados:
        print(row)

Uso de PostGIS

from eco_back.database import DatabaseConfig, DatabaseConnection, PostGISHelper

config = DatabaseConfig(
    host="localhost",
    port=5432,
    database="mi_db_geo",
    user="postgres",
    password="password"
)

with DatabaseConnection(config) as db:
    postgis = PostGISHelper(db)
    
    # Habilitar PostGIS
    postgis.enable_postgis()
    
    # Insertar un punto geográfico
    punto_id = postgis.insert_point(
        table_name="ubicaciones",
        lat=40.4168,
        lon=-3.7038,
        data={"nombre": "Madrid", "tipo": "ciudad"}
    )
    
    # Buscar puntos cercanos (5km)
    cercanos = postgis.find_within_distance(
        table_name="ubicaciones",
        lat=40.4168,
        lon=-3.7038,
        distance_meters=5000
    )

Desarrollo

Ejecutar tests

pytest

Formatear código

black src/ tests/

Linting

flake8 src/ tests/

Type checking

mypy src/

Licencia

MIT

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

eco_back-0.2.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

eco_back-0.2.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file eco_back-0.2.0.tar.gz.

File metadata

  • Download URL: eco_back-0.2.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for eco_back-0.2.0.tar.gz
Algorithm Hash digest
SHA256 016cf164282b9225484afe584252bef8d6385d65940c795bde9073e680385be5
MD5 4f3631853b2aff1ce2098449afd571bf
BLAKE2b-256 f2969992616aac6abf0413fc85dc53797522395a65cbe840dd29aba75e46608e

See more details on using hashes here.

File details

Details for the file eco_back-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: eco_back-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for eco_back-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 faa1e2e5d9726f95b149cd8782b0b91e2f0cd5e21df6da507b538d236b1a0dbd
MD5 e25e983d4de1b92fb27be5f2fe85561e
BLAKE2b-256 fa0e85ea2cb7dfd7840b117fbb79b56156adce7a248b119cb915d44fcf714bd7

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