# The `oslo_context.context` Module

Base class for holding contextual information of a request

This class has several uses:

- Used for storing security information in a web request.

- Used for passing contextual details to oslo.log.

Projects should subclass this class if they wish to enhance the request context or provide additional information in their specific WSGI pipeline or logging context.

class oslo_context.context.RequestContext(auth_token: str | None = None, user_id: str | None = None, project_id: str | None = None, domain_id: str | None = None, user_domain_id: str | None = None, project_domain_id: str | None = None, is_admin: bool | None = False, read_only: bool = False, show_deleted: bool = False, request_id: str | None = None, resource_uuid: str | None = None, overwrite: bool = True, roles: list[str] | None = None, user_name: str | None = None, project_name: str | None = None, domain_name: str | None = None, user_domain_name: str | None = None, project_domain_name: str | None = None, is_admin_project: bool = True, service_token: str | None = None, service_user_id: str | None = None, service_user_name: str | None = None, service_user_domain_id: str | None = None, service_user_domain_name: str | None = None, service_project_id: str | None = None, service_project_name: str | None = None, service_project_domain_id: str | None = None, service_project_domain_name: str | None = None, service_roles: list[str] | None = None, global_request_id: str | None = None, system_scope: str | None = None)

  Bases: `object`

  Helper class to represent useful information about a request context.

  Stores information about the security context under which the user accesses the system, as well as additional request information.

  FROM_DICT_EXTRA_KEYS: list[str] = []
  check_is_admin() → bool | None

    The interface to implement is_admin check according to policy.

  classmethod from_dict(values: dict[str, Any], **kwargs: Any) → Self

    Construct a context object from a provided dictionary.

  classmethod from_environ(environ: dict[str, Any], **kwargs: Any) → Self

    Load a context object from a request environment.

    If keyword arguments are provided then they override the values in the request environment.

    Parameters:

      environ (dict) – The environment dictionary associated with a request.

  get_logging_values() → dict[str, Any]

    Return a dictionary of logging specific context attributes.

  property global_id: str

    Return a sensible value for global_id to pass on.

    When we want to make a call with to another service, it’s important that we try to use global_request_id if available, and fall back to the locally generated request_id if not.

  property is_admin: bool | None
  redacted_copy(**kwargs: Any) → Self

    Return a copy of the context with sensitive fields redacted.

    This is useful for creating a context that can be safely logged.

    Returns:

      A copy of the context with sensitive fields redacted.

  to_dict() → dict[str, Any]

    Return a dictionary of context attributes.

  to_policy_values() → MutableMapping

    A dictionary of context attributes to enforce policy with.

    oslo.policy enforcement requires a dictionary of attributes representing the current logged in user on which it applies policy enforcement. This dictionary defines a standard list of attributes that should be available for enforcement across services.

    It is expected that services will often have to override this method with either deprecated values or additional attributes used by that service specific policy.

  update_store() → None

    Store the context in the current thread.

  user_idt_format = '{user} {project_id} {domain} {user_domain} {p_domain}'

oslo_context.context.generate_request_id() → str

  Generate a unique request id.

oslo_context.context.get_admin_context(show_deleted: bool = False) → RequestContext

  Create an administrator context.

oslo_context.context.get_context_from_function_and_args(function: Callable[[...], Any], args: list[Any], kwargs: dict[str, Any]) → RequestContext | None

  Find an arg of type RequestContext and return it.

  This is useful in a couple of decorators where we don’t know much about the function we’re wrapping.

oslo_context.context.get_current() → RequestContext | None

  Return this thread’s current context

  If no context is set, returns None

oslo_context.context.is_user_context(context: Any) → bool

  Indicates if the request context is a normal user.

this page last updated: 2026-07-14 03:05:54

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