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 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.1.0.tar.gz (15.6 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.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for eco_back-0.1.0.tar.gz
Algorithm Hash digest
SHA256 499388ba1dc1f38ab5f8e11209674ee570347d984eccd5ddfbd972f0f9e882dd
MD5 81ec4b560ed590246199e79d527720e2
BLAKE2b-256 71e073524996aecd5a9717575af1142aa5689c5b93f57d70f8898177b417ac39

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for eco_back-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ade79c350ccce2de4dae1d78814d15709b3c8851345e7b6e19127c1a9dbdbf3
MD5 5899a3f328870a01eeccfe6e99bd5a2c
BLAKE2b-256 834e97f2417f28e433c0fcd910c9b1d28289963758a983a84def8ff894ab5f98

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