Django Quotas
A robust, extensible quotas and plan management library for Django applications. This package provides a flexible framework for defining, assigning, and tracking quotas (limits) for users, accounts, or any custom entity in your Django project.
Features
- Strictly typed, modular codebase with clear separation between core logic, database implementations, and utilities
- Abstract base classes and DTOs for easy extension
- Default and database-specific implementations provided
- Supports hourly, daily, monthly, and total quota buckets
- Pluggable quota models and account models via Django settings
- Utilities for dynamic model/class loading
- Designed for integration with Django 5.x and Python 3.11/3.12
Installation
pip install django-quotas
Or, if using Poetry:
poetry add django-quotas
Quickstart
-
Add to
INSTALLED_APPS(to use standard Quota model and database storage backend):INSTALLED_APPS = [ # ... 'django_quotas', 'django_quotas.defaults', 'django_quotas.backends.db' ]
-
Configure (optional): You can override default models and table prefixes in your Django settings:
DJANGO_QUOTAS_TABLE_PREFIX = 'myquotas' # default: 'django_quotas' DJANGO_QUOTAS_QUOTA_MODEL_NAME = 'myapp.MyQuotaModel' # default: 'django_quotas.defaults.QuotaModel' DJANGO_QUOTAS_QUOTA_RELATED_ACCOUNT_MODEL_NAME = 'auth.User' # or your custom user/account model
-
Run migrations:
python manage.py migrate
-
Assign quotas: Use the provided models or extend them to assign quotas to users/accounts.
Configuration
All configuration is done via Django settings. See src/django_quotas/config.py for all available options.
DJANGO_QUOTAS_TABLE_PREFIX: Prefix for all quota-related tables.DJANGO_QUOTAS_QUOTA_MODEL_NAME: Dotted path to the quota model.DJANGO_QUOTAS_RELATED_ACCOUNT_MODEL: Dotted path to the related account/user model.
API Overview
Core Data Structures
QuotaBucket: Enum for supported buckets (hourly,daily,monthly,total)ValuePerBucket: Dataclass holding quota values for each bucketQuotaStatus,QuotaStats,QuotaUseForBucket,Quota,QuotaUsage: DTOs for quota management
Abstract Service
QuotaService: Abstract base class for quota management logicQuotaExceededError: Exception raised when a quota is exceeded
Models
BaseQuotaModel: Abstract base model for quotasDefaultQuotaModel: Default implementation for quota assignmentQuotaUsageModel: Tracks quota usage per account/feature/time
Utilities
get_model_by_name(model_name: str): Load a Django model by dotted nameget_class_by_name(dotted_path: str): Import a class by dotted pathdatetime_now(): Get current UTC datetime
Extending & Customization
- Custom Quota Models: Inherit from
BaseQuotaModeland register via settings. - Custom Account Models: Set
DJANGO_QUOTAS_RELATED_ACCOUNT_MODELto your user/account model. - Custom Quota Logic: Implement your own
QuotaServicesubclass.
Contributing
Contributions are welcome! If you have ideas or find bugs, feel free to open an issue or submit a pull request.
Please:
- Follow PEP8 and project code style (see
.github/copilot-instructions.md) - Use type hints and docstrings (PEP257)
- Run
make setupandmakebefore submitting a PR - Add unit tests for new features or bugfixes
Credits
- Dmitry Berezovsky (@corvis) - Author and maintainer
License
Django Quotas is licensed under the MIT License. See LICENSE for more details.
For more details, see the source code in src/django_quotas/ and the included docstrings.
Metadata
Release files for django-quotas 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_quotas-1.0.0.tar.gz | 14.9 kB | Without provenance | Details for django_quotas-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_quotas-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_quotas-1.0.0-py3-none-any.whl |
Total release size: 35.6 kB
Release files / django_quotas-1.0.0.tar.gz
| Download URL | django_quotas-1.0.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11701d6d6733686a278dc02fe51c1b04c475bb649d259b07f66e6928d364914e
|
|
BLAKE2b-256 checksum How to use checksums |
a32f41886354c85359f77fb746b4f66db4dfff2c3f8f1087cb03cb9293bcf853
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Release files / django_quotas-1.0.0-py3-none-any.whl
| Download URL | django_quotas-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30b8d12a92129d670d6e435a8b7c6c9825a239d8b4b38b56bb51007d4b200b94
|
|
BLAKE2b-256 checksum How to use checksums |
43727640a26d9803d68d7d448244f865b029d5481231662daa20c8ed3780b06c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Security for django-quotas 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.