pynautobot is the official API client library for Nautobot, a Network Source of Truth and Automation Platform. It provides a Pythonic interface to interact with the Nautobot REST API. The current version is 3.1.0, and new major versions are released to align with Nautobot core major releases, with frequent minor and patch updates in between.
pip install pynautobotVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the pynautobot API client using environment variables for the Nautobot URL and API token. It then fetches and prints the names of the first five devices found in your Nautobot instance. Ensure `NAUTOBOT_URL` and `NAUTOBOT_TOKEN` are set in your environment.
Ensure your pynautobot version matches your Nautobot instance version: use pynautobot v3.x.x for Nautobot v3.x.x+ and pynautobot v2.x.x (LTM) for Nautobot v2.x.x.
Upgrade your Nautobot instance to v3.x.x+ and pynautobot to v3.x.x+ to benefit from new features and ongoing development. If stuck on Nautobot 2.x.x, use pynautobot v2.x.x but be aware of limited support.
For pynautobot v3.1.0 and later, nested attributes are often directly accessible without explicit `full_details()`. Review your code to remove unnecessary `full_details()` calls for related objects if upgrading, as they might still trigger extra API requests. If on older versions, be aware of this limitation and use `full_details()` as needed.
Verify the `NAUTOBOT_URL` environment variable or the `url` parameter in your `pynautobot.api()` call. Ensure the Nautobot server is running and accessible from the machine running the script. Check firewall rules.
Ensure the `NAUTOBOT_TOKEN` environment variable or the `token` parameter in your `pynautobot.api()` call is set correctly with a valid API token. Verify that the token has the necessary read/write permissions for the resources being accessed.
Double-check the lookup criteria (e.g., slug, name, ID). If the object might not exist, use `.filter()` which returns an empty list instead of raising an exception if no objects match, or wrap your `.get()` call in a `try...except pynautobot.exceptions.ObjectDoesNotExist` block.