Skip to main content

pynsd

PyPI License Python Version Code style: black

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

import pynsd

# Basic connection with default settings (localhost:8952)
with pynsd.Client(
    client_cert='/etc/nsd/nsd_control.pem',
    client_key='/etc/nsd/nsd_control.key',
    host='127.0.0.1',
    port=8952
) 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=8952,
    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")

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 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 = pynsd.Client(
    client_cert='cert.pem',
    client_key='key.pem',
    timeout=10.0
)

Development

Setup

  1. Clone the repository:

    git clone https://github.com/greensec/pynsd.git
    cd pynsd
    
  2. 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

Metadata

Release files for pynsd 0.1.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynsd 0.1.2.5
File Size Uploaded
pynsd-0.1.2.5.tar.gz 22.7 kB Details

Release files / pynsd-0.1.2.5.tar.gz

Download URL pynsd-0.1.2.5.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a488eec8dec2706117a67d6d942537ba454bf4fc226e4dad9baa6116a31cd414
BLAKE2b-256 checksum
How to use checksums
472d1e0deddbaab67b0f2c21d197f926ef5e0a236dfa40c970930c049cd9c4fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2.5 This release

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page