Library to connect and call command against new NSD >=4 control api.
Project description
pynsd
A modern Python client for the NSD (Name Server Daemon) control interface, providing type-safe access to NSD's control API.
Features
- Full support for NSD 4.x control protocol
- Type hints for better IDE support and code quality
- Context manager support for safe resource handling
- Comprehensive error handling with custom exceptions
- Support for both synchronous and asynchronous operations
- Parsed response objects with easy access to response data
Installation
pip install pynsd
Basic Usage
Connecting to NSD
from pynsd import ControlClient
# Basic connection with default settings (localhost:8953)
with ControlClient(
client_cert='/etc/nsd/nsd_control.pem',
client_key='/etc/nsd/nsd_control.key'
) as client:
# Get server status
status = client.status()
print(f"NSD is running with {status.data.get('num_zones', 0)} zones")
Common Operations
# Add a zone
result = client.add_zone('example.com.', 'example.com.zone')
print(f"Added zone: {result.msg}")
# Get zone status
status = client.zonestatus('example.com.')
print(f"Zone status: {status.data}")
# Reload configuration
client.reload()
# Get server statistics
stats = client.stats_noreset()
print(f"Queries: {stats.data.get('num_query', 0)}")
Error Handling
from pynsd.exception import NSDCommandError, NSDConnectionError
try:
client.add_zone('invalid.zone', 'nonexistent.zone')
except NSDCommandError as e:
print(f"Command failed: {e}")
except NSDConnectionError as e:
print(f"Connection error: {e}")
Advanced Usage
Using Raw Commands
# Using raw command API
response = client.request('addzone', ('example.org.', 'example.org.zone'))
if response.is_success():
print("Zone added successfully")
Custom Timeout
# Set custom timeout for operations (in seconds)
client = ControlClient(
client_cert='cert.pem',
client_key='key.pem',
timeout=10.0
)
Development
Setup
-
Clone the repository:
git clone https://github.com/greensec/pynsd.git cd pynsd
-
Install development dependencies:
pip install -e .[dev]
Running Tests
make test
Code Quality
make validate # Runs formatting, linting, and type checking
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
See Also
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
pynsd-0.1.1.tar.gz
(13.1 kB
view details)
File details
Details for the file pynsd-0.1.1.tar.gz.
File metadata
- Download URL: pynsd-0.1.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53a55a85c67ffe3d63bb937f63e6dc188534cbdf832e8caf4f28634d3fbcadbc
|
|
| MD5 |
7755220c7c4cb54c8d4ffb7a979c37d8
|
|
| BLAKE2b-256 |
c8854a61d1b55a12adb2eb67fb846122e90ffdf582e720955423344a82f8a78a
|
Provenance
The following attestation bundles were made for pynsd-0.1.1.tar.gz:
Publisher:
publish-to-pypi.yml on greensec/pynsd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pynsd-0.1.1.tar.gz -
Subject digest:
53a55a85c67ffe3d63bb937f63e6dc188534cbdf832e8caf4f28634d3fbcadbc - Sigstore transparency entry: 227420823
- Sigstore integration time:
-
Permalink:
greensec/pynsd@0518c8b07db72d8b3bb33e9f31a8a4085f3781c1 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/greensec
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@0518c8b07db72d8b3bb33e9f31a8a4085f3781c1 -
Trigger Event:
push
-
Statement type: