eco-back 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eco_back-0.1.0/LICENSE +21 -0
- eco_back-0.1.0/MANIFEST.in +5 -0
- eco_back-0.1.0/PKG-INFO +191 -0
- eco_back-0.1.0/README.md +155 -0
- eco_back-0.1.0/pyproject.toml +69 -0
- eco_back-0.1.0/setup.cfg +4 -0
- eco_back-0.1.0/src/eco_back/__init__.py +11 -0
- eco_back-0.1.0/src/eco_back/api/__init__.py +9 -0
- eco_back-0.1.0/src/eco_back/api/client.py +278 -0
- eco_back-0.1.0/src/eco_back/api/config.py +58 -0
- eco_back-0.1.0/src/eco_back/api/registro.py +91 -0
- eco_back-0.1.0/src/eco_back/database/__init__.py +9 -0
- eco_back-0.1.0/src/eco_back/database/config.py +58 -0
- eco_back-0.1.0/src/eco_back/database/connection.py +198 -0
- eco_back-0.1.0/src/eco_back/database/models.py +49 -0
- eco_back-0.1.0/src/eco_back/database/postgis.py +350 -0
- eco_back-0.1.0/src/eco_back/database/repository.py +152 -0
- eco_back-0.1.0/src/eco_back.egg-info/PKG-INFO +191 -0
- eco_back-0.1.0/src/eco_back.egg-info/SOURCES.txt +24 -0
- eco_back-0.1.0/src/eco_back.egg-info/dependency_links.txt +1 -0
- eco_back-0.1.0/src/eco_back.egg-info/requires.txt +15 -0
- eco_back-0.1.0/src/eco_back.egg-info/top_level.txt +1 -0
- eco_back-0.1.0/tests/test_api.py +163 -0
- eco_back-0.1.0/tests/test_database.py +98 -0
- eco_back-0.1.0/tests/test_example.py +15 -0
- eco_back-0.1.0/tests/test_postgis.py +90 -0
eco_back-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
eco_back-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eco-back
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Librería Python eco-back
|
|
5
|
+
Author-email: EI UNP <ecosistema@unp.gov.co>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tuusuario/eco-back
|
|
8
|
+
Project-URL: Documentation, https://github.com/tuusuario/eco-back
|
|
9
|
+
Project-URL: Repository, https://github.com/tuusuario/eco-back
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: psycopg2-binary>=2.9.0
|
|
23
|
+
Requires-Dist: geoalchemy2>=0.14.0
|
|
24
|
+
Requires-Dist: requests>=2.31.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
28
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
29
|
+
Requires-Dist: flake8>=6.0; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
|
|
32
|
+
Provides-Extra: geo
|
|
33
|
+
Requires-Dist: shapely>=2.0.0; extra == "geo"
|
|
34
|
+
Requires-Dist: geojson>=3.0.0; extra == "geo"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# eco-back
|
|
38
|
+
|
|
39
|
+
Librería Python para backend con soporte para PostgreSQL/PostGIS y clientes API
|
|
40
|
+
|
|
41
|
+
## Características
|
|
42
|
+
|
|
43
|
+
- ✅ **Base de datos**: Conexión y operaciones con PostgreSQL
|
|
44
|
+
- ✅ **PostGIS**: Operaciones geoespaciales (puntos, polígonos, búsquedas por proximidad)
|
|
45
|
+
- ✅ **Cliente API**: Cliente HTTP genérico y cliente específico UNP
|
|
46
|
+
- ✅ **Patrón Repository**: Implementación de patrones de diseño para acceso a datos
|
|
47
|
+
|
|
48
|
+
## Descripción
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
## Instalación
|
|
53
|
+
|
|
54
|
+
### Desde el código fuente
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install -e .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Para desarrollo
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -e ".[dev]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Uso
|
|
67
|
+
|
|
68
|
+
### Cliente de Consecutivos (UNP)
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from eco_back.api import Consecutivo
|
|
72
|
+
|
|
73
|
+
# Crear cliente
|
|
74
|
+
client = Consecutivo(base_url="https://api.unp.example.com")
|
|
75
|
+
|
|
76
|
+
# Obtener consecutivo
|
|
77
|
+
consecutivo = client.obtener(origen=1)
|
|
78
|
+
if consecutivo:
|
|
79
|
+
print(f"Consecutivo: {consecutivo}")
|
|
80
|
+
|
|
81
|
+
client.close()
|
|
82
|
+
|
|
83
|
+
# Forma recomendada: usar context manager
|
|
84
|
+
with Consecutivo(base_url="https://api.unp.example.com") as client:
|
|
85
|
+
consecutivo = client.obtener(origen=1)
|
|
86
|
+
# Usar el consecutivo...
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Cliente API Genérico
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from eco_back.api import APIConfig, APIClient
|
|
93
|
+
|
|
94
|
+
config = APIConfig(
|
|
95
|
+
base_url="https://api.example.com",
|
|
96
|
+
timeout=30,
|
|
97
|
+
headers={"Authorization": "Bearer token"}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
with APIClient(config) as client:
|
|
101
|
+
# GET request
|
|
102
|
+
data = client.get("/endpoint")
|
|
103
|
+
|
|
104
|
+
# POST request
|
|
105
|
+
result = client.post("/endpoint", json={"key": "value"})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Conexión básica a PostgreSQL
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from eco_back.database import DatabaseConfig, DatabaseConnection
|
|
112
|
+
|
|
113
|
+
config = DatabaseConfig(
|
|
114
|
+
host="localhost",
|
|
115
|
+
port=5432,
|
|
116
|
+
database="mi_base_datos",
|
|
117
|
+
user="usuario",
|
|
118
|
+
password="password"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
with DatabaseConnection(config) as db:
|
|
122
|
+
resultados = db.execute_query("SELECT * FROM tabla")
|
|
123
|
+
for row in resultados:
|
|
124
|
+
print(row)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Uso de PostGIS
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from eco_back.database import DatabaseConfig, DatabaseConnection, PostGISHelper
|
|
131
|
+
|
|
132
|
+
config = DatabaseConfig(
|
|
133
|
+
host="localhost",
|
|
134
|
+
port=5432,
|
|
135
|
+
database="mi_db_geo",
|
|
136
|
+
user="postgres",
|
|
137
|
+
password="password"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
with DatabaseConnection(config) as db:
|
|
141
|
+
postgis = PostGISHelper(db)
|
|
142
|
+
|
|
143
|
+
# Habilitar PostGIS
|
|
144
|
+
postgis.enable_postgis()
|
|
145
|
+
|
|
146
|
+
# Insertar un punto geográfico
|
|
147
|
+
punto_id = postgis.insert_point(
|
|
148
|
+
table_name="ubicaciones",
|
|
149
|
+
lat=40.4168,
|
|
150
|
+
lon=-3.7038,
|
|
151
|
+
data={"nombre": "Madrid", "tipo": "ciudad"}
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# Buscar puntos cercanos (5km)
|
|
155
|
+
cercanos = postgis.find_within_distance(
|
|
156
|
+
table_name="ubicaciones",
|
|
157
|
+
lat=40.4168,
|
|
158
|
+
lon=-3.7038,
|
|
159
|
+
distance_meters=5000
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Desarrollo
|
|
164
|
+
|
|
165
|
+
### Ejecutar tests
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pytest
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Formatear código
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
black src/ tests/
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Linting
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
flake8 src/ tests/
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Type checking
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
mypy src/
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Licencia
|
|
190
|
+
|
|
191
|
+
MIT
|
eco_back-0.1.0/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# eco-back
|
|
2
|
+
|
|
3
|
+
Librería Python para backend con soporte para PostgreSQL/PostGIS y clientes API
|
|
4
|
+
|
|
5
|
+
## Características
|
|
6
|
+
|
|
7
|
+
- ✅ **Base de datos**: Conexión y operaciones con PostgreSQL
|
|
8
|
+
- ✅ **PostGIS**: Operaciones geoespaciales (puntos, polígonos, búsquedas por proximidad)
|
|
9
|
+
- ✅ **Cliente API**: Cliente HTTP genérico y cliente específico UNP
|
|
10
|
+
- ✅ **Patrón Repository**: Implementación de patrones de diseño para acceso a datos
|
|
11
|
+
|
|
12
|
+
## Descripción
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
## Instalación
|
|
17
|
+
|
|
18
|
+
### Desde el código fuente
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Para desarrollo
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Uso
|
|
31
|
+
|
|
32
|
+
### Cliente de Consecutivos (UNP)
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from eco_back.api import Consecutivo
|
|
36
|
+
|
|
37
|
+
# Crear cliente
|
|
38
|
+
client = Consecutivo(base_url="https://api.unp.example.com")
|
|
39
|
+
|
|
40
|
+
# Obtener consecutivo
|
|
41
|
+
consecutivo = client.obtener(origen=1)
|
|
42
|
+
if consecutivo:
|
|
43
|
+
print(f"Consecutivo: {consecutivo}")
|
|
44
|
+
|
|
45
|
+
client.close()
|
|
46
|
+
|
|
47
|
+
# Forma recomendada: usar context manager
|
|
48
|
+
with Consecutivo(base_url="https://api.unp.example.com") as client:
|
|
49
|
+
consecutivo = client.obtener(origen=1)
|
|
50
|
+
# Usar el consecutivo...
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Cliente API Genérico
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from eco_back.api import APIConfig, APIClient
|
|
57
|
+
|
|
58
|
+
config = APIConfig(
|
|
59
|
+
base_url="https://api.example.com",
|
|
60
|
+
timeout=30,
|
|
61
|
+
headers={"Authorization": "Bearer token"}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
with APIClient(config) as client:
|
|
65
|
+
# GET request
|
|
66
|
+
data = client.get("/endpoint")
|
|
67
|
+
|
|
68
|
+
# POST request
|
|
69
|
+
result = client.post("/endpoint", json={"key": "value"})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Conexión básica a PostgreSQL
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from eco_back.database import DatabaseConfig, DatabaseConnection
|
|
76
|
+
|
|
77
|
+
config = DatabaseConfig(
|
|
78
|
+
host="localhost",
|
|
79
|
+
port=5432,
|
|
80
|
+
database="mi_base_datos",
|
|
81
|
+
user="usuario",
|
|
82
|
+
password="password"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
with DatabaseConnection(config) as db:
|
|
86
|
+
resultados = db.execute_query("SELECT * FROM tabla")
|
|
87
|
+
for row in resultados:
|
|
88
|
+
print(row)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Uso de PostGIS
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from eco_back.database import DatabaseConfig, DatabaseConnection, PostGISHelper
|
|
95
|
+
|
|
96
|
+
config = DatabaseConfig(
|
|
97
|
+
host="localhost",
|
|
98
|
+
port=5432,
|
|
99
|
+
database="mi_db_geo",
|
|
100
|
+
user="postgres",
|
|
101
|
+
password="password"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
with DatabaseConnection(config) as db:
|
|
105
|
+
postgis = PostGISHelper(db)
|
|
106
|
+
|
|
107
|
+
# Habilitar PostGIS
|
|
108
|
+
postgis.enable_postgis()
|
|
109
|
+
|
|
110
|
+
# Insertar un punto geográfico
|
|
111
|
+
punto_id = postgis.insert_point(
|
|
112
|
+
table_name="ubicaciones",
|
|
113
|
+
lat=40.4168,
|
|
114
|
+
lon=-3.7038,
|
|
115
|
+
data={"nombre": "Madrid", "tipo": "ciudad"}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Buscar puntos cercanos (5km)
|
|
119
|
+
cercanos = postgis.find_within_distance(
|
|
120
|
+
table_name="ubicaciones",
|
|
121
|
+
lat=40.4168,
|
|
122
|
+
lon=-3.7038,
|
|
123
|
+
distance_meters=5000
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Desarrollo
|
|
128
|
+
|
|
129
|
+
### Ejecutar tests
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pytest
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Formatear código
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
black src/ tests/
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Linting
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
flake8 src/ tests/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Type checking
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
mypy src/
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Licencia
|
|
154
|
+
|
|
155
|
+
MIT
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "eco-back"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Librería Python eco-back"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "EI UNP", email = "ecosistema@unp.gov.co"}
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"psycopg2-binary>=2.9.0",
|
|
28
|
+
"geoalchemy2>=0.14.0",
|
|
29
|
+
"requests>=2.31.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=7.0",
|
|
35
|
+
"pytest-cov>=4.0",
|
|
36
|
+
"black>=23.0",
|
|
37
|
+
"flake8>=6.0",
|
|
38
|
+
"mypy>=1.0",
|
|
39
|
+
"pytest-mock>=3.12.0",
|
|
40
|
+
]
|
|
41
|
+
geo = [
|
|
42
|
+
"shapely>=2.0.0",
|
|
43
|
+
"geojson>=3.0.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/tuusuario/eco-back"
|
|
48
|
+
Documentation = "https://github.com/tuusuario/eco-back"
|
|
49
|
+
Repository = "https://github.com/tuusuario/eco-back"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
|
|
54
|
+
[tool.black]
|
|
55
|
+
line-length = 88
|
|
56
|
+
target-version = ['py38']
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
python_files = ["test_*.py"]
|
|
61
|
+
python_classes = ["Test*"]
|
|
62
|
+
python_functions = ["test_*"]
|
|
63
|
+
addopts = "-v --cov=eco_back --cov-report=term-missing"
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
python_version = "3.8"
|
|
67
|
+
warn_return_any = true
|
|
68
|
+
warn_unused_configs = true
|
|
69
|
+
disallow_untyped_defs = true
|
eco_back-0.1.0/setup.cfg
ADDED