a5 api client library
This is a Python client library to work against a alerta5DBIO API instance developed by Instituto Nacional del Agua, such as the one deployed here.
Installation
# set environment
python3 -m venv .
source bin/activate
## Install from pip
pip install a5-client
## Or clone git repo
clone https://github.com/jbianchi81/a5client.git
cd a5client
pip install .
Config file location
- Linux: $HOME/.a5client.ini
- Windows: %USERPROFILE%/.a5client.ini
- MacOS: $HOME/.a5client.ini
Default log file location (may be changed in config file)
- Linux: $HOME/.local/share/a5client/logs/a5client.log
- Windows: %LOCALAPPDATA%/a5client/logs/a5client.log
- MacOS: $HOME/Library/Logs/a5client/a5client.log
Config file example
[log]
filename = /var/log/a5client.log
[server]
url = http://localhost:3005
token = my.access.token
Use
from datetime import datetime, timedelta
from a5client import Crud
# Instantiate client
client = Crud(url="A5_API_ENDPOINT_URL", token="YOUR_PERSONAL_TOKEN")
Methods
# READ actions
# Retrieve observations metadata
series = client.readSeries(
var_id=2
)
# retrieve stations metadata
stations = client.readEstaciones()
# retrieve area metadata
area = client.readArea(1)
# retrieve variable metadata
var = client.readVar(2)
# retrieve observations data
serie = client.readSerie(
series_id=29,
timestart="2020-01-01T03:00:00.000Z",
timeend="2021-01-01T03:00:00.000Z"
)
# retrieve simulation configuration
calibrado = client.readCalibrado(289)
# retrieve forecast metadata
corridas = client.readCorridas(289)
# retrieve forecast data, only last run
serie_forecast = client.readSerieProno(
cal_id=289,
series_id=3526
)
# retrieve forecast data, concatenate runs
serie_forecast = client.readSeriePronoConcat(
cal_id=289,
series_id=3526,
forecast_timestart = datetime.now() - timedelta(days=20)
)
# WRITE actions
# create sites (stations, areas, scenes)
created_sites = client.createSites(
[
{
"nombre": "my_station_name",
"id": 11111111,
"geom": {
"type": "Point",
"coordinates": [ -55.55, -33.33 ]
},
"tabla": "alturas_varios"
}
],
tipo="estaciones",
format="json"
)
# create series
created_series = client.createSeries(
[
{
"tipo": "puntual",
"id": 22222222,
"estacion": created_sites[0],
"var": {"id": 2},
"procedimiento": {"id": 1},
"unidades": {"id": 11}
}
]
)
# create observations
import pandas as pd
observations = pd.DataFrame({
"valor": [1.11, 2.22, 3.33]
},
index = pd.date_range(start="2024-01-01 00:00", periods=3, freq='h', tz="UTC")
)
created_observations = client.createObservaciones(
observations,
series_id = created_series[0]["id"],
tipo="puntual"
)
# Create simulation run
from a5client import observacionesDataFrameToList
forecasts = pd.DataFrame({
"valor": [1.21, 2.32, 3.43]
},
index = pd.date_range(start="2024-01-01 00:00", periods=3, freq='h', tz="UTC")
)
forecast_run = {
"forecast_date": "2024-01-01 00:00",
"series": [
{
"series_table": "series",
"series_id": created_series[0]["id"],
"pronosticos": observacionesDataFrameToList(forecasts, series_id=created_series[0]["id"])
}
]
}
created_run = client.createCorrida(
forecast_run,
cal_id = 507
)
Auxiliary functions
from a5client import observacionesDataFrameToList, observacionesListToDataFrame, geojsonToList
from datetime import datetime
# DataFrame to list of dict (a5 schema)
observaciones = pd.DataFrame({
"valor": [1.21, 2.32, 3.43]
},
index = pd.date_range(start="2024-01-01 00:00", periods=3, freq='h', tz="UTC")
)
df = observacionesDataFrameToList(observaciones, series_id = 3333333)
# list of dict (a5 schema) to DataFrame
df = observacionesListToDataFrame([
{
"timestart": datetime(2024,1,1,0),
"valor": 5.55
},
{
"timestart": datetime(2024,1,1,1),
"valor": 4.44
},
{
"timestart": datetime(2024,1,1,2),
"valor": 3.33
}
])
# GeoJSON dict to list of sites dict (a5 schema)
sites = geojsonToList({
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [-55.55, -33.33]
},
"properties": {
"nombre": "my_station_name",
"id": 555555,
"tabla": "my_provider_name"
}
}
]
})
TO DO
- Update methods
- Delete methods
Metadata
Release files for a5-client 0.1.23
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| a5_client-0.1.23.tar.gz | 44.1 kB | Without provenance | Details for a5_client-0.1.23.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| a5_client-0.1.23-py3-none-any.whl | Python 3 | none | any | Details for a5_client-0.1.23-py3-none-any.whl |
Total release size: 91.5 kB
Release files / a5_client-0.1.23.tar.gz
| Download URL | a5_client-0.1.23.tar.gz |
|---|---|
| Size | 44.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24e8961ffe6a6f1547a6469fef9a1a66ae5384957d0e181961c5fa08685f9db2
|
|
BLAKE2b-256 checksum How to use checksums |
ae9ef19c7828e181b00343c75293d4fd179241513168269cadf64b605382da3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / a5_client-0.1.23-py3-none-any.whl
| Download URL | a5_client-0.1.23-py3-none-any.whl |
|---|---|
| Size | 47.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d143f287070c2f5348ef261af82ba9c99c465f228ebde6dfaf1354a8420ef764
|
|
BLAKE2b-256 checksum How to use checksums |
6bb7929229e787eb6279d8f35e8be4cdabc0a89c26a112d9f0ee6aa6e59d84bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for a5-client 0.1.23
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.