Asynchronous Python API for TNS-Energo
Project description
aioTNSE
Asynchronous Python API for TNS-Energo.
Installation
Use pip to install the library:
pip install aiotnse
Usage
import asyncio
from pprint import pprint
import aiohttp
from aiotnse import SimpleTNSEAuth, TNSEApi
async def main(email: str, password: str, region: str) -> None:
"""Create the aiohttp session and run the example."""
async with aiohttp.ClientSession() as session:
auth = SimpleTNSEAuth(
session,
region=region,
email=email,
password=password,
)
# Login first
await auth.async_login()
api = TNSEApi(auth)
# Get user accounts
accounts = await api.async_get_accounts()
pprint(accounts)
# Get counters for an account
account_number = accounts["data"][0]["number"]
counters = await api.async_get_counters(account_number)
pprint(counters)
if __name__ == "__main__":
_email = input("Email: ")
_password = input("Password: ")
_region = input("Region (e.g. rostov, penza, yar): ")
asyncio.run(main(_email, _password, _region))
You can also restore a session with saved tokens. The async_get_access_token() method
automatically refreshes expired tokens or re-authenticates when needed:
from datetime import datetime
def on_token_update(token_data: dict) -> None:
"""Called after login or token refresh — persist the new tokens."""
save_to_storage(token_data)
auth = SimpleTNSEAuth(
session,
region="rostov",
email=email,
password=password,
access_token="saved_access_token",
refresh_token="saved_refresh_token",
access_token_expires=datetime.fromisoformat("2026-06-09T19:42:16"),
refresh_token_expires=datetime.fromisoformat("2026-10-09T19:42:16"),
token_update_callback=on_token_update,
)
# No need to call async_login() — tokens will be refreshed automatically on first API call
Contributors
- Sergei Mikheev (@Muxee4ka) — research and documentation of the new mobile API
Timeouts
aiotnse does not specify any timeouts for any requests. You will need to specify them in your own code. We recommend the timeout from asyncio package:
import asyncio
async with asyncio.timeout(10):
data = await api.async_get_counters(account)
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 aiotnse-2.0.2.tar.gz.
File metadata
- Download URL: aiotnse-2.0.2.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b037d1d439b76e3d31168b77efc579886ba796df6034ab92526687ae76587b
|
|
| MD5 |
1c284474a37665cd7f279d4664a05466
|
|
| BLAKE2b-256 |
62cda8c205b472dc6ae3044de40c74642689a8ae240acac11317744e2f14c4d5
|
Provenance
The following attestation bundles were made for aiotnse-2.0.2.tar.gz:
Publisher:
publish.yml on lizardsystems/aiotnse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotnse-2.0.2.tar.gz -
Subject digest:
61b037d1d439b76e3d31168b77efc579886ba796df6034ab92526687ae76587b - Sigstore transparency entry: 943918508
- Sigstore integration time:
-
Permalink:
lizardsystems/aiotnse@7272ec4dd43e9c643cbc9752b084114168802c81 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/lizardsystems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7272ec4dd43e9c643cbc9752b084114168802c81 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiotnse-2.0.2-py3-none-any.whl.
File metadata
- Download URL: aiotnse-2.0.2-py3-none-any.whl
- Upload date:
- Size: 12.6 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 |
8a233992147eb739cad7bf8b56630d71c03531529322542cdc1e4c5f2493f386
|
|
| MD5 |
3d631ba7aaa581bfb0ca8a63bdac9167
|
|
| BLAKE2b-256 |
688fa84945a9925c3620a710498e0bf29539614d3e72b769a84db1cbdbfe6929
|
Provenance
The following attestation bundles were made for aiotnse-2.0.2-py3-none-any.whl:
Publisher:
publish.yml on lizardsystems/aiotnse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotnse-2.0.2-py3-none-any.whl -
Subject digest:
8a233992147eb739cad7bf8b56630d71c03531529322542cdc1e4c5f2493f386 - Sigstore transparency entry: 943918510
- Sigstore integration time:
-
Permalink:
lizardsystems/aiotnse@7272ec4dd43e9c643cbc9752b084114168802c81 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/lizardsystems
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7272ec4dd43e9c643cbc9752b084114168802c81 -
Trigger Event:
release
-
Statement type: