Metadata-Version: 2.4
Name: site-context-extension
Version: 0.1.0
Summary: pynetbox client extension for the netbox-site-context plugin
Author-email: Wouter de Bruijn <wouter@hedium.nl>
License-Expression: MIT
Project-URL: Documentation, https://github.com/wouterdebruijn/netbox-site-context/blob/main/extension/README.md
Project-URL: Source, https://github.com/wouterdebruijn/netbox-site-context
Project-URL: Tracker, https://github.com/wouterdebruijn/netbox-site-context/issues
Keywords: netbox,pynetbox,netbox-site-context
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Telecommunications Industry
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: System :: Networking
Requires-Python: >=3.12.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pynetbox>=7.8.0
Dynamic: license-file

# site-context-extension

A [pynetbox](https://github.com/netbox-community/pynetbox) **client extension**
for the [netbox-site-context](https://github.com/wouterdebruijn/netbox-site-context)
NetBox plugin.

This package is for **API consumers** — scripts and automation that talk to a
NetBox instance which already has the `netbox_site_context` plugin installed. It
lets pynetbox understand the plugin's Site Context objects and exposes a helper
for fetching a site's rendered (deep-merged) context.

It ships **only** the `site_context_extension` module and depends on nothing
beyond `pynetbox` — you do **not** need the NetBox plugin source or its
server-side dependencies to use it.

## Installing

```bash
pip install site-context-extension
```

This pulls in `pynetbox` automatically.

## Usage

Register the extension when you create your pynetbox client, then use the plugin
endpoints and the `rendered_site_context` helper:

```python
import pynetbox

from site_context_extension import SiteContextExtension, rendered_site_context

nb = pynetbox.api(
    "https://netbox.example.com",
    token="<your-api-token>",
    extensions=[SiteContextExtension],
)

# Standard CRUD over the plugin's Site Context objects
for ctx in nb.plugins.netbox_site_context.site_contexts.all():
    print(ctx.name, ctx.weight, ctx.data)

# The rendered (deep-merged) context for a single site
rendered = rendered_site_context(nb, site_id=2)
if rendered is not None:
    print(rendered.context)
```

### What you get

- `SiteContextExtension` — the `pynetbox.Extension` to pass in `extensions=[...]`.
  It maps the plugin's records so `data` / `context` JSON payloads round-trip as
  plain dicts (via `JsonField`) instead of being coerced into nested records.
- `rendered_site_context(api, site_id)` — returns a `RenderedContext` record for
  the site's merged context, or `None` if the site is not found (HTTP 404).

## Compatibility

Requires a NetBox instance running the `netbox_site_context` plugin, and
`pynetbox >= 7.8.0`.

## License

MIT — see [LICENSE](LICENSE).
