A Python client for the Datadis API.
Project description
Python Datadis API Client
A Python client library to interact with the Datadis API.
Datadis is the Spanish electricity distributor's data access platform that allows users to retrieve information about their electricity consumption and contracts.
Installation
pip install datadis-client
Usage
Authentication
from datadis_client import create_client
# Method 1: Create the client and authenticate in one step
client = create_client(username="YOUR_NIF", password="YOUR_PASSWORD")
# Method 2: Create the client and authenticate separately
from datadis_client import DatadisClient
client = DatadisClient(username="YOUR_NIF", password="YOUR_PASSWORD")
client.authenticate()
Getting supplies
# Get all supplies associated with your account
supplies = client.get_supplies()
# Get supplies for a specific distributor
supplies = client.get_supplies(distributor_code="0123")
# Get supplies for an authorized NIF
supplies = client.get_supplies(authorized_nif="AUTHORIZED_NIF")
Getting contract details
# Get contract details for a specific CUPS
contract = client.get_contract_detail(
cups="ES0021000000000000AA1F",
distributor_code="0123"
)
Getting consumption data
# Get hourly consumption data for a specific period
consumption = client.get_consumption_data(
cups="ES0021000000000000AA1F",
distributor_code="0123",
start_date="2023/01",
end_date="2023/02",
measurement_type="0", # 0 for hourly, 1 for quarter-hourly
point_type="5"
)
# Access consumption readings
for reading in consumption.get('timeCurve', []):
date = reading.get('date')
time = reading.get('time')
consumption_kwh = reading.get('consumptionKWh')
print(f"{date} {time}: {consumption_kwh} kWh")
Other available methods
The client provides access to all Datadis API endpoints:
get_max_power- Get maximum power dataget_reactive_data- Get reactive energy dataget_distributors_with_supplies- Get distributors with suppliesapi_search- Search for consumption data by parametersapi_sum_search- Search for summarized consumption dataapi_search_auto- Search for auto-consumption data
Examples
Check the examples directory for complete usage examples.
Development
Setting up a development environment
Clone the repository and install development dependencies:
git clone https://github.com/agaliste/python-datadis.git
cd python-datadis
pip install -e ".[dev]"
Running tests
Run the unit tests with pytest:
pytest tests/test_auth.py tests/test_consumption.py tests/test_supplies.py tests/test_search.py
Run tests with coverage:
pytest --cov=datadis_client
Generate coverage reports:
pytest --cov=datadis_client --cov-report=html
Running integration tests
Integration tests make actual API calls to Datadis and require valid credentials. These tests verify that the client works correctly with the real Datadis API.
-
Create a
.envfile in the project root with your Datadis credentials:# Datadis API credentials (required) DATADIS_USERNAME=your_nif_here DATADIS_PASSWORD=your_password_here # Test data (optional) # If not provided, tests will auto-discover a CUPS from your account TEST_CUPS=ES0021000000000000XXXX TEST_DISTRIBUTOR_CODE=0000 TEST_POINT_TYPE=5 -
Run the integration tests using the provided scripts:
# Unix/macOS ./run_tests.sh # Windows run_tests.bat
Or run them directly:
pytest tests/test_integration.py -v
If you don't provide specific TEST_CUPS values, the integration tests will automatically use the first CUPS found in your account.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 python_datadis-0.0.1.tar.gz.
File metadata
- Download URL: python_datadis-0.0.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3780f9a4062e93840fb61989d2783d268a889850ea5b4812826075c0badeb1ed
|
|
| MD5 |
17000558af2e44a98b2991a5318728a4
|
|
| BLAKE2b-256 |
8bc9a2cea55418be16dcccdc98ce8de2b02e23d2b71aa6f55022fccd427d1e66
|
Provenance
The following attestation bundles were made for python_datadis-0.0.1.tar.gz:
Publisher:
build_and_publish_package.yaml on agaliste/python-datadis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_datadis-0.0.1.tar.gz -
Subject digest:
3780f9a4062e93840fb61989d2783d268a889850ea5b4812826075c0badeb1ed - Sigstore transparency entry: 214572608
- Sigstore integration time:
-
Permalink:
agaliste/python-datadis@cc5f50e49f5e8d6c22540acd45fa06de10a89efc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/agaliste
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_publish_package.yaml@cc5f50e49f5e8d6c22540acd45fa06de10a89efc -
Trigger Event:
release
-
Statement type:
File details
Details for the file python_datadis-0.0.1-py3-none-any.whl.
File metadata
- Download URL: python_datadis-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
755502beabed0d476533864502d1b55e7c60358a944b52e67f1880420fcf4c50
|
|
| MD5 |
6318ca65fae8e9ca548d06104ab18a20
|
|
| BLAKE2b-256 |
b1f8f325a2ee1da8cccd5b9b0b8f98c4631090c1d746e8c395c9ba6dda1a5b3d
|
Provenance
The following attestation bundles were made for python_datadis-0.0.1-py3-none-any.whl:
Publisher:
build_and_publish_package.yaml on agaliste/python-datadis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_datadis-0.0.1-py3-none-any.whl -
Subject digest:
755502beabed0d476533864502d1b55e7c60358a944b52e67f1880420fcf4c50 - Sigstore transparency entry: 214572609
- Sigstore integration time:
-
Permalink:
agaliste/python-datadis@cc5f50e49f5e8d6c22540acd45fa06de10a89efc -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/agaliste
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_publish_package.yaml@cc5f50e49f5e8d6c22540acd45fa06de10a89efc -
Trigger Event:
release
-
Statement type: