Oslo Limit

raw JSON →
2.10.0 verified Fri May 01 auth: no python

Limit enforcement library to assist with quota calculation, part of the OpenStack Oslo project. Current version 2.10.0, requires Python >=3.10. Maintenance mode with infrequent releases.

pip install oslo.limit
error ImportError: No module named oslo.limit
cause Using wrong import path; the correct package is oslo_limit.
fix
Run: pip install oslo.limit Then import: from oslo_limit import limit
error TypeError: object Enforcer can't be used in 'await' expression
cause Enforcer methods are async and must be awaited.
fix
Use: await enforcer.enforce(...) inside an async function.
error oslo_limit.limit.ResourceNotFound: Resource 'instances' not found
cause Resource name is not registered or case mismatch.
fix
Verify resource names are registered in the backend and use exact case (e.g., 'instances' vs 'Instances').
breaking Version 2.0.0 dropped Python 2 support and changed the API to be async-only. Synchronous usage will break.
fix Update code to use async/await; see migration guide in documentation.
deprecated The 'limit.Limit' class is deprecated in favor of using the Enforcer directly.
fix Use limit.Enforcer instead of instantiating limit.Limit.
gotcha Resource names are case-sensitive and must match exactly the names used in the backend.
fix Always use consistent casing for resource names (e.g., 'instances' not 'Instances').

Basic usage: create an Enforcer and call enforce() to check quota limits.

from oslo_limit import limit

# Define a resource with a limit of 10
resource = {'name': 'instances', 'limit': 10}
# Check usage
enforcer = limit.Enforcer()
# Would raise exception if exceeded
enforcer.enforce('project-id', resource, usage=5)