Skip to main content

Python SDK to communicate with ANA's HidroWeb API for hydrological and pluviometric data

Project description

HidroWebSDK

PyPI version License: MIT

⚠️ 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 httpx for 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

  • Brazilian National Water Agency (ANA) for providing the HidroWeb API
  • Built with httpx for async HTTP requests
  • Built with pandas for data manipulation
  • Built with pytest for testing

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

hidrowebsdk-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hidrowebsdk-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for hidrowebsdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f96babf3ba9eb0f767e0e61913704c85835288da84009e3b38497a6b29681db
MD5 1822c9f75f06eefd9753ea38fd381223
BLAKE2b-256 c264a099bee0de9efb3d11c1eed64f39ce01ee0048fec8e25ecda17af7f7c62e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hidrowebsdk-0.1.0.tar.gz:

Publisher: pypi.yml on NVXtech/hidrowebsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for hidrowebsdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc3aee923db458f188a326b94fe07e82be3b8933531742fcbd766afc3936cf2f
MD5 6c82127eebc3822c244ce26ac5db766a
BLAKE2b-256 ee20b23a484f0fb342d77c43e96ab3295057be7037e21cdaab75a28af7f4bf6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hidrowebsdk-0.1.0-py3-none-any.whl:

Publisher: pypi.yml on NVXtech/hidrowebsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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