Django Dharma
Django Dharma is a Django library designed to facilitate running checks on models. It provides a structured way to perform and manage checks on your Django models.
Why Use Django Dharma?
Django Dharma is useful in scenarios where you need to validate data after it has been entered into your system. For example, if you are importing data from an external source without validating it during the import process (maybe you want to get them in your system as they are), you might want to perform validation checks afterward. With Django Dharma, you can execute checks such as:
How many records have been inserted?
Does the foo column contain values other than bar?
You can save the results of these checks and then analyze them or take necessary precautions based on the findings.
Project Structure
The project consists of two main components:
django_dharma/: The core library containing logic for running model checks.
test_project/: A test Django project used to perform migrations and test the library with different Django versions.
Installation
To install Django Dharma, you can use pip:
Install the package:
bash pip install django-dharma
Add ``django_dharma`` to your Django project’s ``INSTALLED_APPS`` in ``settings.py``:
python INSTALLED_APPS = [ # ... other installed apps 'django_dharma', ]
Usage
To use Django Dharma, you need to run the perform_checks management command to execute the checks on your models. This command will collect all implementations of the specified protocol and run the checks, saving any anomalies to the Anomaly model.
Run migrations:
```bash python manage.py migrate
```
Create a check:
To create a check, define a class that implements the CheckProtocol. The class should include a run_checks method and an attribute model of type models.MyModel. Here is an example:
```python from datetime import datetime from djangodharma.base import countcheck from myapp import models
class MyModelCheck: model = models.MyModel
def run_checks(self) -> None: """ Verifies that the 'foo' column contains only 'biz' and 'foo' values. """ allowed_values = {'biz', 'foo'} # Get distinct values in the 'foo' column distinct_values = set(self.model.objects.values_list('foo', flat=True).distinct()) # Check if all distinct values are in the allowed_values set assert distinct_values.issubset(allowed_values), ( f"Column 'foo' contains unexpected values: {distinct_values - allowed_values}" ) """ Some example checks are included in this package. Please contribute if you have useful checks to share! This check verifies that there are at least 30 records in the MyModel model for today. """ count_check(model=self.model, filters={"date": datetime.today().date()}, count=30) print("All checks passed!")```
Run the checks:
bash python manage.py perform_checks
Contributing
If you would like to contribute to the project, please follow these steps:
Fork the repository.
Create a branch for your change:
bash git checkout -b my-feature
Add and commit your changes:
bash git add . git commit -m "Add a new feature"
Push your branch and open a pull request.
Testing
The project uses flake8 for linting, black for code formatting, and isort for import sorting. You can run linting and formatting checks with the following commands:
bash poetry run flake8 django_dharma/ poetry run black --check django_dharma/ poetry run isort --check-only django_dharma/
Metadata
Release files for django-dharma 0.1.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 | |
|---|---|---|---|---|
| django_dharma-0.1.0.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_dharma-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / django_dharma-0.1.0.tar.gz
| Download URL | django_dharma-0.1.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee60f9b67ddfca354b4c1151b5c52f0f986e205947f6c090fe06bfb8194691f8
|
|
BLAKE2b-256 checksum How to use checksums |
3806118b94a88b71cd76d26df5b1bfa715574a8c5e318cfab2e688c3e059ff41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / django_dharma-0.1.0-py3-none-any.whl
| Download URL | django_dharma-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc1fb3e97d2ff97aca35c2252fe4a15a55ea36e1af69f79f673cf8583c5619b4
|
|
BLAKE2b-256 checksum How to use checksums |
409714b64c93a487caf85495a04c4f2640c45f650da95a1e4c07ec2fafee1550
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Security for django-dharma 0.1.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.