Install & Compatibility
Where this runs
tested against v4.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 3.580s · 180.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 17.8s · import 3.438s · 180MB
188MB installed
● package 188MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
context
✓ from neutron_lib import context
✗ from neutron import context
neutron-lib was extracted from neutron; direct imports from 'neutron' may break.
exceptions
✓ from neutron_lib import exceptions
✗ from neutron.common import exceptions
Old path from monolithic neutron; use neutron_lib.exceptions.
Creates a RequestContext and demonstrates using exceptions.
from neutron_lib import context
from neutron_lib import exceptions
# Create a request context
req_context = context.RequestContext(user_id='admin',
tenant_id='admin',
roles=['admin'])
print(req_context.to_dict())
# Raise a NeutronException
try:
raise exceptions.NeutronException(message='example')
except exceptions.NeutronException as e:
print(e)
Errors
Common errors & fixes
ImportError: cannot import name 'NeutronException' from 'neutron_lib'
NeutronException is in neutron_lib.exceptions, not directly in neutron_lib.
fixUse: from neutron_lib import exceptions
try:
raise exceptions.NeutronException(...) AttributeError: module 'neutron_lib' has no attribute 'context'
Common mistake: trying to use 'neutron_lib.context' but context module is not automatically imported. You need an explicit import.
fixAdd: from neutron_lib import context
neutron_lib.exceptions.NeutronException: Object not found
This error is raised when a resource is not found (like a port, network, etc.) but the caller may not realize it's an exception from neutron-lib.
fixCatch neutron_lib.exceptions.NeutronException or a more specific subclass like PortNotFound, NetworkNotFound.
Upgrade
Version history
4.1.0latest on PyPI · released Jun 17, 2026
Audit
Dependencies
oslo.logrequiredLogging utilities used throughout