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.1.tar.gz (22.7 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.1-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: eco_back-0.2.1.tar.gz
  • Upload date:
  • Size: 22.7 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.1.tar.gz
Algorithm Hash digest
SHA256 d3b7ad3f9b0c8c85c153fd400ddbe37b1bfa7c65dd5009bef3400dec41618435
MD5 924c2dc757be2dd8ce10f26a25fa3011
BLAKE2b-256 41696acb1b79dd34b68146bb5f92e5d8d9ffeaaf3581acbabf105ff8d67b0e53

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eco_back-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 20.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4600af3107238dde0a6ed33a60ba95d678a155dfc3253ea8d1a0dbf991ab6c3e
MD5 22851d3cf633a79bbe81481f4c987b6e
BLAKE2b-256 554c49ef8f8778d345885fbde1a9942fe28a3b032d15ee5aed25b52f36e82bfc

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