Python SDK for NanoLink monitoring system
Project description
NanoLink Python SDK
Python SDK for NanoLink monitoring system.
Installation
pip install kkape-nanolink
Or install from source:
cd sdk/python
pip install -e .
Quick Start
import asyncio
from nanolink import NanoLinkServer, ServerConfig, Metrics, AgentConnection
async def main():
# Create server
server = NanoLinkServer(ServerConfig(port=9100))
# Handle agent connections
@server.on_agent_connect
async def handle_connect(agent: AgentConnection):
print(f"Agent connected: {agent.hostname}")
print(f" OS: {agent.os}/{agent.arch}")
print(f" Version: {agent.version}")
# Handle agent disconnections
@server.on_agent_disconnect
async def handle_disconnect(agent: AgentConnection):
print(f"Agent disconnected: {agent.hostname}")
# Handle metrics
@server.on_metrics
async def handle_metrics(metrics: Metrics):
if metrics.cpu:
print(f"CPU: {metrics.cpu.usage_percent:.1f}%")
if metrics.cpu.model:
print(f" Model: {metrics.cpu.model}")
if metrics.memory:
print(f"Memory: {metrics.memory.usage_percent:.1f}%")
for gpu in metrics.gpus:
print(f"GPU: {gpu.name} - {gpu.usage_percent:.1f}%")
# Start server
await server.run_forever()
if __name__ == "__main__":
asyncio.run(main())
Token Validation
from nanolink import NanoLinkServer, ServerConfig, ValidationResult
def my_token_validator(token: str) -> ValidationResult:
if token == "admin-token":
return ValidationResult(valid=True, permission_level=3)
elif token == "read-token":
return ValidationResult(valid=True, permission_level=0)
else:
return ValidationResult(valid=False, error_message="Invalid token")
config = ServerConfig(
port=9100,
token_validator=my_token_validator,
)
server = NanoLinkServer(config)
Sending Commands
from nanolink import Command
# Get agent
agent = server.get_agent_by_hostname("my-server")
# List processes
result = await agent.send_command(Command.process_list())
print(result.output)
# Restart a service
result = await agent.send_command(Command.service_restart("nginx"))
if result.success:
print("Service restarted successfully")
else:
print(f"Error: {result.error}")
# Execute shell command (requires SuperToken)
result = await agent.send_command(
Command.shell_execute("df -h", super_token="your-super-token")
)
Permission Levels
| Level | Name | Allowed Operations |
|---|---|---|
| 0 | READ_ONLY | View metrics, process list, logs |
| 1 | BASIC_WRITE | Download files, clear temp files |
| 2 | SERVICE_CONTROL | Restart services, Docker containers, kill processes |
| 3 | SYSTEM_ADMIN | System reboot, execute shell commands |
TLS Configuration
config = ServerConfig(
port=9100,
tls_cert_path="/path/to/cert.pem",
tls_key_path="/path/to/key.pem",
)
server = NanoLinkServer(config)
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check .
black --check .
mypy .
License
Apache 2.0 License - see LICENSE 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 kkape_nanolink-0.2.6.tar.gz.
File metadata
- Download URL: kkape_nanolink-0.2.6.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ceba51afddf29ae6d62e5b27379238007213475fef3fc99617d02a290172deb
|
|
| MD5 |
8ba1da8cc650a58bb05779f468c552c3
|
|
| BLAKE2b-256 |
aa405019d91cd2d92c47e931d4d4714bd9efa0cb03266a5ee7655bb0dcc8be3d
|
Provenance
The following attestation bundles were made for kkape_nanolink-0.2.6.tar.gz:
Publisher:
sdk-release.yml on chenqi92/NanoLink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kkape_nanolink-0.2.6.tar.gz -
Subject digest:
1ceba51afddf29ae6d62e5b27379238007213475fef3fc99617d02a290172deb - Sigstore transparency entry: 774938379
- Sigstore integration time:
-
Permalink:
chenqi92/NanoLink@7969b8b7ea8f14ea21f67db28d15793ad7c5831d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chenqi92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-release.yml@7969b8b7ea8f14ea21f67db28d15793ad7c5831d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file kkape_nanolink-0.2.6-py3-none-any.whl.
File metadata
- Download URL: kkape_nanolink-0.2.6-py3-none-any.whl
- Upload date:
- Size: 34.1 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 |
efc73be02e9f771079a4369a1a4e0346d486957941d8c3ab804c2419ad708f5b
|
|
| MD5 |
6c603bccd6e9c636d82af9cc965b3c71
|
|
| BLAKE2b-256 |
da6cfd618533d56d205bc7177a3fce741cd9ed2b90b158d29e0cc4cdada1e233
|
Provenance
The following attestation bundles were made for kkape_nanolink-0.2.6-py3-none-any.whl:
Publisher:
sdk-release.yml on chenqi92/NanoLink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kkape_nanolink-0.2.6-py3-none-any.whl -
Subject digest:
efc73be02e9f771079a4369a1a4e0346d486957941d8c3ab804c2419ad708f5b - Sigstore transparency entry: 774938381
- Sigstore integration time:
-
Permalink:
chenqi92/NanoLink@7969b8b7ea8f14ea21f67db28d15793ad7c5831d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chenqi92
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-release.yml@7969b8b7ea8f14ea21f67db28d15793ad7c5831d -
Trigger Event:
workflow_dispatch
-
Statement type: