Skip to content

App

pynautobot.core.app

This module defines the App and PluginsApp classes for interacting with Nautobot applications and plugins.

pynautobot.core.app.App

Represents apps in Nautobot.

Calls to attributes are returned as Endpoint objects.

Returns:

Type Description
Endpoint

Matching requested attribute.

Raises:

Type Description
RequestError

If requested endpoint doesn't exist.

__dir__()

Get the directory of the App object.

__getattr__(name)

Get an attribute from the App object.

__getstate__()

Get the state of the App object.

__init__(api, name)

Initialize the App object.

__setstate__(d)

Set the state of the App object.

choices()

Returns _choices response from App.

Returns:

Type Description
List[Response]

Raw response from Nautobot's _choices endpoint.

config()

Returns config response from app.

Returns:

Type Description
dict

Raw response from Nautobot's config endpoint.

Raises:

Type Description
RequestError

If called for an invalid endpoint.

Examples:

>>> pprint.pprint(nb.users.config())
{'tables': {'DeviceTable': {'columns': ['name',
                                        'status',
                                        'tenant',
                                        'device_role',
                                        'site',
                                        'primary_ip',
                                        'tags']}}}

get_custom_field_choices(filters=None)

Returns custom-field-choices response from app.

Parameters:

Name Type Description Default
filters dict

Contains key/value pairs that correlate to the filters a given endpoint accepts.

None

Returns:

Type Description
List[Response]

Raw response from Nautobot's custom-field-choices endpoint.

Raises:

Type Description
RequestError

If called for an invalid endpoint.

Examples:

>>> nb.extras.get_custom_field_choices()
[
    {
        "id": "5b39ba88-e5ab-4be2-89f5-5a016473b53c",
        "display": "First option",
        "url": "http://localhost:8000/api/extras/custom-field-choices/5b39ba88-e5ab-4be2-89f5-5a016473b53c/",
        "field": {
            "display": "Test custom field 2",
            "id": "5b39ba88-e5ab-4be2-89f5-5a016473b53c",
            "url": "http://localhost:8000/api/extras/custom-fields/5b39ba88-e5ab-4be2-89f5-5a016473b53c/",
            "name": "test_custom_field_2"
        },
        "value": "First option",
        "weight": 100,
        "created": "2023-04-15",
        "last_updated": "2023-04-15T18:11:57.163237Z"
    },
]

Scope the results by passing a filters dict, whose key/value pairs are sent as query parameters to the endpoint:

>>> nb.extras.get_custom_field_choices(filters={"field": "test_custom_field_2"})
[...]

get_custom_fields(filters=None)

Returns custom-fields response from app.

Parameters:

Name Type Description Default
filters dict

Contains key/value pairs that correlate to the filters a given endpoint accepts.

None

Returns:

Type Description
List[Response]

Raw response from Nautobot's custom-fields endpoint.

Raises:

Type Description
RequestError

If called for an invalid endpoint.

Examples:

>>> nb.extras.get_custom_fields()
[
    {
        "id": "5b39ba88-e5ab-4be2-89f5-5a016473b53c",
        "display": "Test custom field",
        "url": "http://localhost:8000/api/extras/custom-fields/5b39ba88-e5ab-4be2-89f5-5a016473b53c/",
        "content_types": ["dcim.rack"],
        "type": {"value": "integer", "label": "Integer"},
        "label": "Test custom field",
        "name": "test_custom_field",
        "slug": "test_custom_field",
        "description": "",
        "required": False,
        "filter_logic": {"value": "loose", "label": "Loose"},
        "default": None,
        "weight": 100,
        "validation_minimum": None,
        "validation_maximum": None,
        "validation_regex": "",
        "created": "2023-04-15",
        "last_updated": "2023-04-15T17:45:11.839431Z",
        "notes_url": "http://localhost:8000/api/extras/custom-fields/5b39ba88-e5ab-4be2-89f5-5a016473b53c/notes/",
    },
]

Scope the results by passing a filters dict, whose key/value pairs are sent as query parameters to the endpoint:

>>> nb.extras.get_custom_fields(filters={"content_types": "dcim.device"})
[...]

pynautobot.core.app.CoreApp

Bases: App

Represents the Nautobot core app.

In addition to the generic App endpoint access, this exposes a dedicated helper for the render-jinja-template endpoint.

render_jinja_template(template_code, context=None, api_version=None)

Render a Jinja template server-side via Nautobot.

Parameters:

Name Type Description Default
template_code str

The Jinja template to render.

required
context dict

Context variables for the template. Defaults to {}.

None
api_version str

Override the default or globally-set Nautobot REST API version for this single request.

None

Returns:

Type Description
dict

Raw response containing rendered_template, rendered_template_lines, template_code, and context.

Raises:

Type Description
RequestError

If the template fails to render.

Examples:

>>> nb.core.render_jinja_template(
...     template_code="Hello {{ name }}",
...     context={"name": "world"},
... )
{'rendered_template': 'Hello world',
 'rendered_template_lines': ['Hello world'],
 'template_code': 'Hello {{ name }}',
 'context': {'name': 'world'}}

pynautobot.core.app.PluginsApp

Add plugins to the URL path.

Basically, valid plugins API could be handled by the same App class, but you need to add "plugins" to the request URL path.

Returns:

Type Description
App

With "plugins" added to the path.

__dir__()

Get the directory of the PluginsApp object.

__getattr__(name)

Get an attribute from the PluginsApp object.

__init__(api)

Initialize the PluginsApp object.

installed_plugins()

Returns raw response with installed plugins.

Returns:

Type Description
List[Response]

Raw response from Nautobot's installed plugins.

Examples:

>>> nb.plugins.installed_plugins()
[{
    'name': 'test_plugin',
    'package': 'test_plugin',
    'author': 'Dmitry',
    'description': 'Nautobot test plugin',
    'verison': '0.10'
}]

pynautobot.core.app.UiApp

Bases: App

Represents the Nautobot ui app.

core property

Access core endpoints nested under ui (e.g. render-jinja-template).

Returns:

Type Description
CoreApp

A CoreApp bound to the ui/core path.

Examples:

>>> nb.ui.core.render_jinja_template(
...     template_code="Hello {{ name }}",
...     context={"name": "world"},
... )
{'rendered_template': 'Hello world', ...}