nrgkick-api
Async Python client for NRGkick Gen2 EV charger local REST API.
Overview
This library provides an async Python interface for communicating with NRGkick Gen2 EV chargers via their local REST JSON API. It powers the NRGkick integration in Home Assistant but can be used standalone in any async Python application.
Features
- Async/await support - Built on aiohttp for efficient async I/O
- Automatic retry logic - Handles transient network errors with exponential backoff
- Authentication support - Optional HTTP Basic Auth
- Type hints - Full type annotation for better IDE support
- Enums for numeric codes -
IntEnumtypes for status, connector type, errors, etc. - Minimal dependencies - Only requires aiohttp
Installation
pip install nrgkick-api
Quick Start
import asyncio
import aiohttp
from nrgkick_api import NRGkickAPI
async def main():
async with aiohttp.ClientSession() as session:
api = NRGkickAPI(
host="192.168.1.100",
username="admin", # Optional
password="secret", # Optional
session=session,
)
# Get device information
info = await api.get_info()
print(f"Device: {info['general']['device_name']}")
print(f"Serial: {info['general']['serial_number']}")
# Get current values
values = await api.get_values()
print(f"Power: {values['powerflow']['total_active_power']}W")
# Control charging
await api.set_current(16.0) # Set to 16A
await api.set_charge_pause(True) # Pause charging
asyncio.run(main())
API Reference
NRGkickAPI
The main client class for communicating with NRGkick devices.
Constructor
NRGkickAPI(
host: str,
username: str | None = None,
password: str | None = None,
session: aiohttp.ClientSession | None = None,
)
host: IP address or hostname of the NRGkick deviceusername: Optional username for HTTP Basic Authpassword: Optional password for HTTP Basic Authsession: aiohttp ClientSession (required for making requests)
Methods
| Method | Description |
|---|---|
get_info(sections=None, *, raw=False) |
Get device information |
get_control() |
Get current control parameters |
get_values(sections=None, *, raw=False) |
Get real-time telemetry data |
set_current(current) |
Set charging current (6.0-32.0A) |
set_charge_pause(pause) |
Pause/resume charging |
set_energy_limit(limit) |
Set energy limit in Wh (0=unlimited) |
set_phase_count(phases) |
Set phase count (1-3) |
test_connection() |
Test device connectivity |
Raw Mode
The get_info() and get_values() methods support a raw parameter. When raw=True, the API returns raw numeric values instead of human-readable strings for certain fields:
# Normal mode (default) - returns strings
info = await api.get_info()
print(info["connector"]["type"]) # "CEE"
print(info["grid"]["phases"]) # "L1, L2, L3"
# Raw mode - returns numeric values
info = await api.get_info(raw=True)
print(info["connector"]["type"]) # 1
print(info["grid"]["phases"]) # 7
# Convert raw numeric values to enums (enums are exported from the package)
from nrgkick_api import ChargingStatus, ConnectorType, GridPhases
info = await api.get_info(["connector", "grid"], raw=True)
connector_type = ConnectorType(info["connector"]["type"])
grid_phases = GridPhases(info["grid"]["phases"])
print(connector_type) # ConnectorType.CEE
print(grid_phases) # GridPhases.L1_L2_L3
values = await api.get_values(["general"], raw=True)
charging_status = ChargingStatus(values["general"]["status"])
if charging_status is ChargingStatus.CHARGING:
print("Charging")
# If you want to be defensive about new/unknown codes, catch ValueError
try:
charging_status = ChargingStatus(values["general"]["status"])
except ValueError:
charging_status = ChargingStatus.UNKNOWN
# Can be combined with sections
info = await api.get_info(["connector", "grid"], raw=True)
values = await api.get_values(["general"], raw=True)
Exceptions
All exceptions inherit from NRGkickError.
NRGkickError
├── NRGkickConnectionError
│ ├── NRGkickTimeoutError
│ ├── NRGkickUnreachableError
│ └── NRGkickHTTPError
├── NRGkickAuthenticationError
├── NRGkickAPIDisabledError
├── NRGkickCommandRejectedError
└── NRGkickInvalidResponseError
| Exception | Description |
|---|---|
NRGkickError |
Base exception for all NRGkick errors |
NRGkickConnectionError |
Network/communication errors (base class; also raised for e.g. a connection reset) |
NRGkickTimeoutError |
The device did not respond in time |
NRGkickUnreachableError |
No connection could be established (connection refused, DNS failure, no route) |
NRGkickHTTPError |
The device answered with an HTTP error status; the code is in status: int |
NRGkickAuthenticationError |
Authentication failures (401/403) |
NRGkickAPIDisabledError |
Device JSON API is disabled |
NRGkickCommandRejectedError |
Device explicitly rejected a command (reason is user-facing) |
NRGkickInvalidResponseError |
Unexpected/malformed payload (invalid JSON, not an object, missing keys, wrong type) |
Transient errors (timeouts, network errors, HTTP 5xx) are retried up to MAX_RETRIES times before an exception is raised.
Connection errors
The exception type (plus status for NRGkickHTTPError) tells you what went wrong, so you can build your own, e.g. translated, message. The exception text is English and intended for logs; it may include the device URL.
from nrgkick_api import (
NRGkickConnectionError,
NRGkickHTTPError,
NRGkickTimeoutError,
NRGkickUnreachableError,
)
try:
values = await api.get_values()
except NRGkickTimeoutError:
... # The charger did not respond in time
except NRGkickUnreachableError:
... # The charger could not be reached
except NRGkickHTTPError as err:
... # The charger answered with HTTP error err.status
except NRGkickConnectionError:
... # Any other communication error
Because the specific types are subclasses of NRGkickConnectionError, code that only catches NRGkickConnectionError keeps working.
Command rejections vs invalid responses
NRGkickCommandRejectedError: The device accepted the HTTP request but refused to apply the command. Thereasonstring is safe to display to users.NRGkickInvalidResponseError: The device (or protocol) returned an unexpected payload shape/type (e.g., a body that is not valid JSON, missing expected key, wrong type that cannot be coerced).
Note: The device may also return HTTP errors like 406 Not Acceptable for invalid command inputs, but still include a JSON payload with a Response string. This library treats that as a device command rejection and raises NRGkickCommandRejectedError.
API Endpoints
The library communicates with three main endpoints:
/info- Device information (serial, model, versions, etc.)/control- Control parameters (current, pause, limits)/values- Real-time telemetry (power, energy, temperatures)
Requirements
- Python 3.14+
- aiohttp 3.14.5+
- NRGkick Gen2 with JSON API enabled
Enabling the JSON API
The local REST API must be enabled in the NRGkick mobile app:
- Open the NRGkick app
- Connect to your device
- Navigate to Settings → JSON API
- Enable the API
- Optionally configure authentication
If the JSON API is disabled, the device may respond with {"Response":"API must be enabled within the NRGkick App"}.
In that case, this library raises NRGkickAPIDisabledError.
Development
The project uses uv. To create the virtual environment (.venv) with all development dependencies and run the checks:
uv sync
./validate.sh
Single tools can be run with uv run, e.g. uv run pytest or uv run mypy src/nrgkick_api.
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related Projects
- NRGkick integration for Home Assistant - Home Assistant core integration using this library (source)
Changelog
See CHANGELOG.md for notable changes.
Metadata
Release files for nrgkick-api 1.8.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 |
|---|---|---|---|---|
| nrgkick_api-1.8.1.tar.gz | 25.1 kB | Without provenance | Details for nrgkick_api-1.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nrgkick_api-1.8.1-py3-none-any.whl | Python 3 | none | any | Details for nrgkick_api-1.8.1-py3-none-any.whl |
Total release size: 41.5 kB
Release files / nrgkick_api-1.8.1.tar.gz
| Download URL | nrgkick_api-1.8.1.tar.gz |
|---|---|
| Size | 25.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e863bc47fc492d70946ae4a675d519661cfa192a95e159ba5dd392da1cf61bad
|
|
BLAKE2b-256 checksum How to use checksums |
768a11642d941edeb03e393a20b891f3fc2966a52aed0334b2b5b650d8110d80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / nrgkick_api-1.8.1-py3-none-any.whl
| Download URL | nrgkick_api-1.8.1-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e11eb38f80a6c4536af15d085ead3837e08839b63a90ec334b46ab5ac97dd678
|
|
BLAKE2b-256 checksum How to use checksums |
c8acb3fd4cd97f2daee9d95177c0360d3453ed347cabda197bf40236f2c7fe32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for nrgkick-api 1.8.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.
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.