# osc_lib.api package

## Submodules

## osc_lib.api.api module

Base API Library

class osc_lib.api.api.BaseAPI(session: Session | None = None, service_type: str | None = None, endpoint: str | None = None, **kwargs: Any)

  Bases: `object`

  Base API wrapper for keystoneauth1.session.Session

  Encapsulate the translation between keystoneauth1.session.Session and requests.Session in a single layer:

  - Restore some requests.session.Session compatibility; keystoneauth1.session.Session.request() has the method and url arguments swapped from the rest of the requests-using world.

  - Provide basic endpoint handling when a Service Catalog is not available.

  HEADER_NAME = 'OpenStack-API-Version'
  SERVICE_TYPE = ''
  create(url: str, session: Session | None = None, method: str | None = None, **params: Any) → Response | Any

    Create a new resource

    Parameters:

      - url (string) – The API-specific portion of the URL path

      - session (Session) – HTTP client session

      - method (string) – HTTP method (default POST)

  delete(url: str, session: Session | None = None, **params: Any) → Response

    Delete a resource

    Parameters:

      - url (string) – The API-specific portion of the URL path

      - session (Session) – HTTP client session

  find(path: str, value: str | None = None, attr: str | None = None, headers: dict[str, str] | None = None) → Any

    Find a single resource by name or ID

    Parameters:

      - path (string) – The API-specific portion of the URL path

      - value (string) – search expression (required, really)

      - attr (string) – name of attribute for secondary search

      - headers (dict) – Headers dictionary to pass to requests

  find_attr(path: str, value: str | None = None, attr: str | None = None, resource: str | None = None) → Any

    Find a resource via attribute or ID

    Most APIs return a list wrapped by a dict with the resource name as key. Some APIs (Identity) return a dict when a query string is present and there is one return value. Take steps to unwrap these bodies and return a single dict without any resource wrappers.

    Parameters:

      - path (string) – The API-specific portion of the URL path

      - value (string) – value to search for

      - attr (string) – attribute to use for resource search

      - resource (string) – plural of the object resource name; defaults to path

    For example:

      n = find(netclient, ‘network’, ‘networks’, ‘matrix’)

  find_bulk(path: str, headers: dict[str, str] | None = None, **kwargs: Any) → list[Any]

    Bulk load and filter locally

    Parameters:

      - path (string) – The API-specific portion of the URL path

      - kwargs – A dict of AVPs to match - logical AND

      - headers (dict) – Headers dictionary to pass to requests

    Returns:

      list of resource dicts

  find_one(path: str, **kwargs: Any) → Any

    Find a resource by name or ID

    Parameters:

      path (string) – The API-specific portion of the URL path

    Returns:

      resource dict

  list(path: str, session: Session | None = None, body: Any = None, detailed: bool = False, headers: dict[str, str] | None = None, **params: Any) → Response | Any

    Return a list of resources

    GET ${ENDPOINT}/${PATH}?${PARAMS}

    path is often the object’s plural resource type

    Parameters:

      - path (string) – The API-specific portion of the URL path

      - session (Session) – HTTP client session

      - body – data that will be encoded as JSON and passed in POST request (GET will be sent by default)

      - detailed (bool) – Adds ‘/details’ to path for some APIs to return extended attributes

      - headers (dict) – Headers dictionary to pass to requests

    Returns:

      JSON-decoded response, could be a list or a dict-wrapped-list

## osc_lib.api.auth module

Authentication Library

osc_lib.api.auth.build_auth_plugins_option_parser(parser: _ArgumentParserT) → _ArgumentParserT

  Auth plugins options builder

  Builds dynamically the list of options expected by each available authentication plugin.

osc_lib.api.auth.check_valid_authentication_options(options: cloud_region.CloudRegion, auth_plugin_name: str) → None

  Validate authentication options, and provide helpful error messages.

osc_lib.api.auth.check_valid_authorization_options(options: cloud_region.CloudRegion, auth_plugin_name: str) → None

  Validate authorization options, and provide helpful error messages.

osc_lib.api.auth.get_keystone2keystone_auth(local_auth: BaseIdentityPlugin, service_provider: str, project_id: str | None = None, project_name: str | None = None, project_domain_id: str | None = None, project_domain_name: str | None = None) → Keystone2Keystone

  Return Keystone 2 Keystone authentication for service provider.

  Parameters:

    - local_auth – authentication to use with the local Keystone

    - service_provider – service provider id as registered in Keystone

    - project_id – project id to scope to in the service provider

    - project_name – project name to scope to in the service provider

    - project_domain_id – id of domain in the service provider

    - project_domain_name – name of domain to in the service provider

  Returns:

    Keystone2Keystone auth object for service provider

osc_lib.api.auth.get_options_list() → dict[str, _OptionDict]

  Gather plugin options so the help action has them available

osc_lib.api.auth.get_plugin_list() → frozenset[str]

  Gather plugin list and cache it

## osc_lib.api.utils module

API Utilities Library

osc_lib.api.utils.simple_filter(data: _T | None = None, attr: str | None = None, value: str | None = None, property_field: str | None = None) → _T | None

  Filter a list of dicts

  Parameters:

    - data (list) – The list to be filtered. The list is modified in-place and will be changed if any filtering occurs.

    - attr (string) – The name of the attribute to filter. If attr does not exist no match will succeed and no rows will be returned. If attr is None no filtering will be performed and all rows will be returned.

    - value (string) – The value to filter. None is considered to be a ‘no filter’ value. ‘’ matches against a Python empty string.

    - property_field (string) – The name of the data field containing a property dict to filter. If property_field is None, attr is a field name. If property_field is not None, attr is a property key name inside the named property field.

  Returns:

    Returns the filtered list

  Rtype list:

  This simple filter (one attribute, one exact-match value) searches a list of dicts to select items. It first searches the item dict for a matching `attr` then does an exact-match on the `value`. If `property_field` is given, it will look inside that field (if it exists and is a dict) for a matching `value`.

## Module contents

this page last updated: 2026-02-24 14:35:42

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug