DJ Actions
A pattern + tooling to enable a standardized way to interact with and mutate data on a Django model
Getting started
Installation
pip install dj-actions
Add to INSTALLED_APPS
Prepare your app for action!
python manage.py start_actions
Add your first action
python manage.py create_action
Add actions to your Django app
1. Create an actions module in your app:
DJActions convention is to isolate each action into it's own module. A typical file layout might look something like this:
[app]
|_ [actions]
|_ action_registry.py
|_ [some_action]
|_ [some_other_action]
2. Create your action registry
The action registry is how we tell DJActions how to route to our actions. The action registry will also be responsible for generating your documentation endpoints
Here is an example registry:
from actions.util import (
STATUS,
ACTION_TYPE,
# get_action_docs,
enrich_actions
)
action_list = []
## -- START ACTION REGISTRY -- ##
action_list.append(('mark_done', ACTION_TYPE.INSTANCE.value, STATUS.ALPHA.value))
## -- END ACTION REGISTRY -- ##
# this is the abolsute path to the base of your app:
# dj-actions uses this to locate your action directory
base = '/code/example_app/'
# convention over configuration
# this will load your actions configurations from
initial_registry = { "resource": "todo", "basepath": "/todos/", "actions": {} }
ACTIONS = enrich_actions(
base,
initial_registry,
action_list
)
Now you need to mixin actions.ActionViews into your ViewSet:
from rest_framework import routers, serializers, viewsets
from actions.mixins import ActionMixin
from actions.actions.action_registry import ACTIONS
from actions.models import EventAction
class EventActionViewSet(ActionMixin, viewsets.ModelViewSet):
queryset = EventAction.objects.all()
serializer_class = TodoSerializer
action_registry = ACTIONS
router = routers.DefaultRouter()
router.register(r'todos', TodoViewSet)
Configuration
DJACTION_TRACK_ACTIONSifTruewill store action info in the db (default:True)DJACTION_TTL_MINUTESactions older than this will be archived (default 1 day (60*24))
Features
- Reliable, simple pattern to execute complex logic
- Self documenting
Tooling
This library provides you with some tools and tasks which might be useful:
Stream,io (WIP)
Push action information into stream.io
Airflow (WIP)
Push downstream work to an airflow task
Concepts
Task Registry
The Task Registry provides a means of defining tasks in a self documenting way. Based on the meta-data provided in the task registry, tasks will be exposed in various different ways
Metadata
Release files for dj-actions 0.0.7
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 | |
|---|---|---|---|---|
| dj-actions-0.0.7.tar.gz | 15.9 kB | Without provenance | Details |
Release files / dj-actions-0.0.7.tar.gz
| Download URL | dj-actions-0.0.7.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98a428cef867f954a2885875b40daf60531c4f16736d1227cdc70d9ea8cff51c
|
|
BLAKE2b-256 checksum How to use checksums |
df44af8d2d1a4e08cea8ab45ba7735b574300d072525e4d33360a001a43747f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
|
Security for dj-actions 0.0.7
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.