Skip to main content

Nyl Python client

nyl is a small Python 3.11+ library for rendering and inspecting Kubernetes manifests. Install it with uv add nyl or pip install nyl.

Install the Nyl CLI separately and put it on PATH, or pass its executable path.

from nyl import NylClient

client = NylClient(project="/path/to/infrastructure", executable="nyl", timeout=120)
manifests = client.render("applications/workloads/web.yaml", target="development")
deployment = manifests.one("Deployment", "web")

assert deployment.namespace == "web"
for container in deployment.containers(include_init=True):
    assert container.security_context["allowPrivilegeEscalation"] is False
    assert container.env.value("PGHOST") == "database-rw"
    assert container.env.secret_ref("PGPASSWORD") == ("database-app", "password")

namespace is the authored namespace. Resources without one return None, even when the Release or Argo CD Application has a destination namespace.

Rendering

NylClient(project, executable="nyl", timeout=120) fixes the invocation directory and requires a positive, finite timeout in seconds. render(source, *, target=None, offline=False, allow_secret_inputs=False) invokes only nyl render. Relative source paths are relative to project; absolute paths are passed through. Calls leave Python's working directory and environment unchanged and use no shell. Timeouts terminate the invocation's process group on POSIX and its process tree with Windows' built-in taskkill; diagnostics are collected after termination.

Rust owns configuration resolution, validation, rendering, and caching. Target-aware Releases use the compiled target's rendering rules. Each call runs the CLI again; Nyl's cache may reuse valid artifacts. Project-configured validation remains enabled according to the CLI's defaults. A validation failure yields an exception even if the CLI emits manifests. offline=True forwards --offline (cached Git references and publication inputs); it is not a universal network prohibition for validators or other external tools. allow_secret_inputs=True explicitly forwards the CLI's opt-in for project secrets and admitted environment inputs.

Only single-file render entry points are supported. Full-tree loading needs a documented manifest inventory: a published tree can also contain ownership indexes and non-manifest state. This package neither downloads the executable nor applies, publishes, or reconciles resources, and has no persistent Python cache.

Inspecting declarations

ManifestSet is iterable, has a length, and preserves document order. select(kind=None, name=None, *, namespace=..., api_version=None) returns another ManifestSet. one(kind, name=None, *, namespace=..., api_version=None) requires exactly one match. Omit namespace to search all namespaces; explicitly pass namespace=None to select resources with no declared namespace. Selection errors show resource identities without manifest bodies. ManifestSet.from_yaml(text) safely reads multi-document YAML 1.2, ignores empty documents, and rejects invalid resource envelopes. Nyl's emitted quoting preserves strings such as "on", "yes", and "001"; no YAML 1.1 boolean coercion is applied by Python.

Resources expose raw, api_version, kind, name, and namespace. containers(include_init=False) handles Pods, Deployments, StatefulSets, DaemonSets, ReplicaSets, ReplicationControllers, Jobs, and CronJobs. It yields regular containers in order, followed by init containers when requested. Unsupported kinds raise DeclarationError.

Containers expose raw, name, security_context (an empty dictionary when omitted), and env. env.value(name) requires an explicit literal string; env.secret_ref(name) requires one Secret key reference and returns (name, key). Missing, duplicate, malformed, and incompatible declarations raise DeclarationError. These helpers do not resolve Secrets, ConfigMaps, envFrom, Pod-level security context inheritance, or live cluster data. Raw dictionaries remain mutable.

Errors and compatibility

All library errors derive from NylError and are exported from nyl:

Error Meaning
ExecutableNotFoundError Install the CLI or correct its executable path
RenderTimeoutError The subprocess exceeded its deadline
RenderError A nonzero exit status or an OS execution error
InvalidOutputError stdout is not valid rendered resource YAML
ResourceNotFoundError one() found zero matches
AmbiguousResourceError one() found several matches
DeclarationError A helper cannot interpret the declaration

Execution errors derive from ExecutionError and retain command (an argument tuple), exit_code (None when unavailable), and diagnostics (stderr). They do not retain or automatically print stdout. YAML errors omit input excerpts; resource and container representations include only identities. CLI diagnostics can contain sensitive information and should be handled accordingly.

Tested with Nyl CLI 0.5.9. The package's version is available through importlib.metadata.version("nyl").

Development and releases

From the repository root:

mise run python-check  # Ruff, type checking, parallel tests, checkout-built CLI
mise run python-build # Stamp Cargo-derived version, then build wheel and sdist
mise run pre-commit   # Required Rust and Python checks

Or inside python/:

uv sync --locked
uv run python scripts/version.py
uv run ruff check .
uv run ruff format --check .
uv run mypy
uv run pytest
uv build

The test fixture builds the CLI and reads Cargo's executable artifact, honoring Cargo's configured target and output directory. Set NYL_TEST_EXECUTABLE to use a binary you built separately.

scripts/version.py derives the release version from root Cargo.toml and stamps src/nyl/_version.py before building. For CLI 0.MINOR.PATCH, Python uses 0.2MINOR.PATCH (concatenation): 0.5.9 → 0.25.9, 0.10.3 → 0.210.3. From CLI 1.x, versions match. Strict SemVer prereleases alpha.N, beta.N, and rc.N map to PEP 440 aN, bN, and rcN. Other prereleases and build metadata are rejected. The stamped file is build metadata, not a separately maintained release counter. Stamp after synchronizing the development environment; uv run --no-sync can use that environment when preparing a newer native release. The source distribution includes its stamped version and builds without the Rust repository, Cargo, or Nyl.

The handwritten .github/workflows/python.yaml tests and builds artifacts on relevant pull requests, develop changes, and native v* tags. The tag must match the Cargo version. Its publish job consumes the tested artifacts and uses PyPI Trusted Publishing from the pypi environment for NiklasRosenstein/nyl. Release through the repository's native release command (scripts/release.sh X.Y.Z); no separate Python counter or PyPI API token is needed.

Metadata

Release files for nyl 0.26.1

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

Source distribution (sdist)

Source distribution for nyl 0.26.1
File Size Uploaded Provenance Actions
nyl-0.26.1.tar.gz 8.5 kB With provenance Details for nyl-0.26.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nyl 0.26.1
File Interpreter ABI Platform Actions
nyl-0.26.1-py3-none-any.whl Python 3 none any Details for nyl-0.26.1-py3-none-any.whl

Total release size: 18.5 kB

Release files / nyl-0.26.1.tar.gz

Download URL nyl-0.26.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e08727fa66b96de3bf57a286fcf610840256c6640059eb7a3352d4fea986aca8
BLAKE2b-256 checksum
How to use checksums
6cba4d4c302519b2235bfd298e3bbce4ab6f213541dcf11e561c04bf2ee307a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / nyl-0.26.1-py3-none-any.whl

Download URL nyl-0.26.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94972e1be6681fe9f4621bbb31d6c1125f14e1c1e7879a9c8f2d748fa6ce9443
BLAKE2b-256 checksum
How to use checksums
0b1f621db519798f77c34315c7d55f79ebf5d3b3d8df40c4230b35d008778a3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Security for nyl 0.26.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nyl-0.26.1.tar.gz

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 Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.26.1 This release

2 release files Full provenance

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