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.
Metadata
Release files for python-datadis 0.0.1
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 |
|---|---|---|---|---|
| python_datadis-0.0.1.tar.gz | 9.3 kB | With provenance | Details for python_datadis-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_datadis-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for python_datadis-0.0.1-py3-none-any.whl |
Total release size: 17.1 kB
Release files / python_datadis-0.0.1.tar.gz
| Download URL | python_datadis-0.0.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3780f9a4062e93840fb61989d2783d268a889850ea5b4812826075c0badeb1ed
|
|
BLAKE2b-256 checksum How to use checksums |
8bc9a2cea55418be16dcccdc98ce8de2b02e23d2b71aa6f55022fccd427d1e66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2025.
Transparency logRelease files / python_datadis-0.0.1-py3-none-any.whl
| Download URL | python_datadis-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
755502beabed0d476533864502d1b55e7c60358a944b52e67f1880420fcf4c50
|
|
BLAKE2b-256 checksum How to use checksums |
b1f8f325a2ee1da8cccd5b9b0b8f98c4631090c1d746e8c395c9ba6dda1a5b3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2025.
Transparency logSecurity for python-datadis 0.0.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for python_datadis-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 17, 2025.
Transparency logA 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.