Python SDK to communicate with ANA's HidroWeb API for hydrological and pluviometric data
Project description
HidroWebSDK
⚠️ Warning: This project is under active development and is in alpha stage. APIs may change without notice.
HidroWebSDK is a Python SDK to simplify and automate the downloading of hydrological data from the Brazilian National Water Agency (ANA) monitoring stations via its official API (HidroWeb).
Features
- Asynchronous HTTP requests using
httpxfor better performance - Automatic OAuth token refresh
- Easy-to-use methods for fetching basins, entities, and stations data
- Returns data as Pandas DataFrames for easy analysis
- Comprehensive test suite
Installation
Install HidroWebSDK using pip:
pip install hidrowebsdk
For development, clone the repository and install with dev dependencies:
git clone https://github.com/yourusername/hidrowebsdk.git
cd hidrowebsdk
pip install -e ".[dev]"
Usage
Basic Usage
import asyncio
from hidrowebsdk import Client
async def main():
# Initialize the client
client = Client(user="your_user", password="your_password")
# Authenticate (optional, done automatically on first request)
await client.authenticate()
# Fetch all basins
basins = await client.bacias()
print(basins.head())
# Fetch entities with filters
from datetime import datetime
entities = await client.entidades(
last_update_start=datetime(2023, 1, 1),
last_update_end=datetime(2023, 12, 31)
)
print(entities.head())
# Fetch stations
stations = await client.estacoes(state="SP")
print(stations.head())
# Close the client
await client.close()
# Run the async function
asyncio.run(main())
Environment Variables
You can set your credentials using environment variables:
export HIDROWEB_USER="your_user"
export HIDROWEB_PASSWORD="your_password"
Then, initialize the client without parameters:
client = Client()
API Reference
Client
__init__(user=None, password=None)
Initialize the client with user credentials.
authenticate()
Authenticate with the HidroWeb API and obtain an access token.
bacias(codigo=None, last_update_start=None, last_update_end=None)
Fetch basin data.
codigo: Basin code (int)last_update_start: Start date for last update filter (datetime)last_update_end: End date for last update filter (datetime)
Returns: Pandas DataFrame
entidades(codigo=None, last_update_start=None, last_update_end=None)
Fetch entity data.
codigo: Entity code (int)last_update_start: Start date for last update filter (datetime)last_update_end: End date for last update filter (datetime)
Returns: Pandas DataFrame
estacoes(codigo=None, last_update_start=None, last_update_end=None, state=None, basin_code=None)
Fetch station data.
codigo: Station code (int)last_update_start: Start date for last update filter (datetime)last_update_end: End date for last update filter (datetime)state: State abbreviation (str)basin_code: Basin code (int)
Returns: Pandas DataFrame
close()
Close the HTTP client connection.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Testing
Run the test suite:
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hidrowebsdk-0.1.0.tar.gz.
File metadata
- Download URL: hidrowebsdk-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f96babf3ba9eb0f767e0e61913704c85835288da84009e3b38497a6b29681db
|
|
| MD5 |
1822c9f75f06eefd9753ea38fd381223
|
|
| BLAKE2b-256 |
c264a099bee0de9efb3d11c1eed64f39ce01ee0048fec8e25ecda17af7f7c62e
|
Provenance
The following attestation bundles were made for hidrowebsdk-0.1.0.tar.gz:
Publisher:
pypi.yml on NVXtech/hidrowebsdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hidrowebsdk-0.1.0.tar.gz -
Subject digest:
3f96babf3ba9eb0f767e0e61913704c85835288da84009e3b38497a6b29681db - Sigstore transparency entry: 566145444
- Sigstore integration time:
-
Permalink:
NVXtech/hidrowebsdk@981a72e191febc00c0c6c2ee2bfcd83ca948a3a3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/NVXtech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@981a72e191febc00c0c6c2ee2bfcd83ca948a3a3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hidrowebsdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hidrowebsdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc3aee923db458f188a326b94fe07e82be3b8933531742fcbd766afc3936cf2f
|
|
| MD5 |
6c82127eebc3822c244ce26ac5db766a
|
|
| BLAKE2b-256 |
ee20b23a484f0fb342d77c43e96ab3295057be7037e21cdaab75a28af7f4bf6d
|
Provenance
The following attestation bundles were made for hidrowebsdk-0.1.0-py3-none-any.whl:
Publisher:
pypi.yml on NVXtech/hidrowebsdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hidrowebsdk-0.1.0-py3-none-any.whl -
Subject digest:
fc3aee923db458f188a326b94fe07e82be3b8933531742fcbd766afc3936cf2f - Sigstore transparency entry: 566145449
- Sigstore integration time:
-
Permalink:
NVXtech/hidrowebsdk@981a72e191febc00c0c6c2ee2bfcd83ca948a3a3 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/NVXtech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@981a72e191febc00c0c6c2ee2bfcd83ca948a3a3 -
Trigger Event:
release
-
Statement type: