{"id":21610,"library":"neutron-lib","title":"Neutron Lib","description":"neutron-lib is a library of shared routines and utilities for OpenStack Neutron. It provides common code (exceptions, DB models, API definitions, extensions) used by neutron and neutron sub-projects. Version 3.25.0 supports Python >=3.10. Release cadence follows OpenStack coordinated releases, often with multiple minor releases per cycle.","status":"active","version":"3.25.0","language":"python","source_language":"en","source_url":"https://opendev.org/openstack/neutron-lib","tags":["openstack","neutron","networking","shared-library"],"install":[{"cmd":"pip install neutron-lib","lang":"bash","label":"default"}],"dependencies":[{"reason":"Logging utilities used throughout","package":"oslo.log","optional":false}],"imports":[{"note":"neutron-lib was extracted from neutron; direct imports from 'neutron' may break.","wrong":"from neutron import context","symbol":"context","correct":"from neutron_lib import context"},{"note":"Old path from monolithic neutron; use neutron_lib.exceptions.","wrong":"from neutron.common import exceptions","symbol":"exceptions","correct":"from neutron_lib import exceptions"}],"quickstart":{"code":"from neutron_lib import context\nfrom neutron_lib import exceptions\n\n# Create a request context\nreq_context = context.RequestContext(user_id='admin',\n                                      tenant_id='admin',\n                                      roles=['admin'])\nprint(req_context.to_dict())\n\n# Raise a NeutronException\ntry:\n    raise exceptions.NeutronException(message='example')\nexcept exceptions.NeutronException as e:\n    print(e)","lang":"python","description":"Creates a RequestContext and demonstrates using exceptions."},"warnings":[{"fix":"If using neutron_lib.db.model_base, check the OpenStack release notes for the exact new import path, e.g., from neutron_lib.db import model_base as mb.","message":"In neutron-lib >= 2.0.0, the DB model classes were moved into separate database backend modules. Direct imports from neutron_lib.db.model_base may be deprecated or changed.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use from neutron_lib.api.definitions import ATTR_NOT_SPECIFIED instead.","message":"The api.attributes module was refactored in some versions; constants like ATTR_NOT_SPECIFIED were moved to neutron_lib.api.definitions.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure that the versions of neutron and neutron-lib are consistent (e.g., both from the same OpenStack release).","message":"Do not install both neutron and neutron-lib from different versions in the same environment. They must be from the same OpenStack release series to avoid API incompatibility.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from neutron_lib import exceptions\ntry:\n    raise exceptions.NeutronException(...)","cause":"NeutronException is in neutron_lib.exceptions, not directly in neutron_lib.","error":"ImportError: cannot import name 'NeutronException' from 'neutron_lib'"},{"fix":"Add: from neutron_lib import context","cause":"Common mistake: trying to use 'neutron_lib.context' but context module is not automatically imported. You need an explicit import.","error":"AttributeError: module 'neutron_lib' has no attribute 'context'"},{"fix":"Catch neutron_lib.exceptions.NeutronException or a more specific subclass like PortNotFound, NetworkNotFound.","cause":"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.","error":"neutron_lib.exceptions.NeutronException: Object not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}