Skip to content

Extending Netherframe (Plugins and Custom Generators)

Netherframe is designed around provider-neutral core contracts (nf.core.plugins, PLUGIN_API_VERSION = 1). Teams and third-party packages extend Netherframe through standard Python pyproject.toml entry points without modifying netherframe.core.


Plugin entry-point contracts (ENTRY_POINT_GROUPS)

Entry-point group Purpose Documentation
nf.lint_packs Offline policy & schema rule packs run by nf lint and app.lint() Offline Policy Linting
nf.generators Custom in-process value generators for GeneratedValue Generated Values
nf.backends Custom state backend plugins validated by StateBackendContract Backend Plugin System
nf.discoverers Live cloud/service inventory and codification providers (nf discover) Creating Discovery Packages
nf.state_normalizers Provider-specific state normalization hooks (e.g., netherframe.ext.aws) nf.core.plugins.StateNormalizerPlugin
nf.drift.import_id_resolvers Fallback import-ID resolvers for providers without GetResourceIdentitySchemas nf.core.plugins.ImportIdResolverPlugin
nf.graph_identities / nf.graph_planning Qualified object-identity & affected-scope planning profiles for PostgreSQL graph state Provider Releases

Naming rule: Distribution names use netherframe.* (or your own package prefix), while all plugin entry-point group names keep their stable nf.* contract names.


Example 1: Add a custom offline policy pack (nf.lint_packs)

Define a zero-argument factory returning a RulePack:

from nf.core.linting import Rule, RulePack


def rule_pack() -> RulePack:
    return RulePack(
        "acme",
        (
            Rule(
                "ACME_S3_VERSIONING",
                "aws_s3_bucket",
                ("tags", "Owner"),
                lambda owner: isinstance(owner, str) and bool(owner.strip()),
                "Every S3 bucket must declare a non-empty Owner tag",
                missing_status="failed",
            ),
        ),
    )

Register it in your package's pyproject.toml:

[project.entry-points."nf.lint_packs"]
acme = "acme_policies:rule_pack"

Once installed in the project's Python environment, nf lint --app infra:app --pack acme and app.lint() discover and run it automatically.


Example 2: Add a custom GeneratedValue generator (nf.generators)

Register a named generator so teams can produce organization-specific tokens, PINs, or IDs in-process without external provider binaries:

import secrets

from nf.core.providers.generators import register_generator


def numeric_pin(digits: int = 6) -> str:
    return "".join(secrets.choice("0123456789") for _ in range(digits))


# Register dynamically in Python, or publish via [project.entry-points."nf.generators"]
register_generator("acme_pin", numeric_pin)

To package it as a reusable plugin:

[project.entry-points."nf.generators"]
acme_pin = "acme_generators:numeric_pin"

Apps then reference it by name (keeping plans serializable):

from nf.core import App, GeneratedValue, Stack

with App(nf_id="pin-demo") as app, Stack(nf_id="auth"):
    pin = GeneratedValue(nf_id="recovery_pin", generator="acme_pin", params={"digits": 8})

Example 3: Validate a custom state backend with StateBackendContract

Install netherframe.testing (uv add --dev netherframe.testing) and subclass nf.testing.state_backend_contract.StateBackendContract in your backend's pytest suite. The shared contract suite automatically verifies:

  • Loads and conditional compare-and-swap writes (rejecting stale serials)
  • Mutual-exclusion locking and lock release
  • Pre-apply checkpoints and run-status records
  • Atomic single-write nf state mv (rewriting dependent entries) and nf state rm (refusing dangling dependents)

Checking plugin API compatibility

Inspect the active plugin API version and registered entry-point groups from Python:

from nf.core.plugins import ENTRY_POINT_GROUPS, PLUGIN_API_VERSION, check_plugin_api_version

assert PLUGIN_API_VERSION == 1
assert "backends" in ENTRY_POINT_GROUPS
check_plugin_api_version(PLUGIN_API_VERSION)