A modern Python client for the NSD (Name Server Daemon) control interface, providing type-safe access to NSD's control API.
- 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
pip install pynsdimport pynsd
# Basic connection with default settings (localhost:8953)
with pynsd.Client(
client_cert='/etc/nsd/nsd_control.pem',
client_key='/etc/nsd/nsd_control.key',
host='127.0.0.1',
port=8953
) as client:
# ...
# For self-signed certificates without hostname verification
with pynsd.Client(
client_cert='/etc/nsd/nsd_control.pem',
client_key='/etc/nsd/nsd_control.key',
host='nsd.example.com',
port=8953,
ssl_verify=False # Disable SSL certificate verification
) as client:
# Get server status
status = client.status()
print(f"NSD is running with {status.data.get('num_zones', 0)} zones")# 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)}")from pynsd 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}")# Using raw command API
response = client.request('addzone', ('example.org.', 'example.org.zone'))
if response.is_success():
print("Zone added successfully")# Set custom timeout for operations (in seconds)
client = pynsd.Client(
client_cert='cert.pem',
client_key='key.pem',
timeout=10.0
)-
Clone the repository:
git clone https://github.com/greensec/pynsd.git cd pynsd -
Install development dependencies:
pip install -e .[dev]
make testmake validate # Runs formatting, linting, and type checkingContributions are welcome! Please open an issue or submit a pull request.