Overview
django-declarative-apis is a framework built on top of Django aimed at teams implementing RESTful APis. It provides a simple interface to define endpoints declaratively. Some benefits to using django-declarative-apis:
- Define endpoints declaratively
- Define model-bound and unbound resource endpoints with a consistent interface
- OAuth 1.0a authentication out of the box
- Define resource and endpoint-bound tasks, promoting modularity
- Define synchronous and asynchronous tasks (asynchronous tasks implemented with Celery)
- Separation of concerns between request body processing and business logic
Quick start
This guide is intended to demonstrate the bare minimum in order to get a django-declarative-apis project up and running. The example directory contains further examples using endpoint to model relationships, authentication and response attribute filtering.
Create django app
./manage startapp myapp
Add app to INSTALLED_APPS
INSTALLED_APPS = [
"django_declarative_apis",
"myapp",
]
Add required config
DECLARATIVE_ENDPOINT_RESOURCE_ADAPTER = (
"django_declarative_apis.adapters.EndpointResource"
)
DECLARATIVE_ENDPOINT_AUTHENTICATION_HANDLERS = (
"django_declarative_apis.authentication.oauthlib.oauth1.TwoLeggedOauth1"
)
myapp/urls.py
from django_declarative_apis import adapters
import myapp.resources
class NoAuth:
@staticmethod
def is_authenticated(request):
return True
urlpatterns = [
url(
r"^ping$",
adapters.resource_adapter(
get=myapp.resources.PingDefinition, authentication=NoAuth
),
),
]
myproject/myproject/urls.py
from django.conf.urls import url, include
import myapp.urls
urlpatterns = [
url(r"^", include(myapp.urls)),
]
myapp/resources.py
from django_declarative_apis import machinery
class PingDefinition(machinery.BaseEndpointDefinition):
def is_authorized(self):
return True
@property
def resource(self):
return {"ping": "pong"}
Optional: Implement Custom Event Hooks for Event Emission
# settings.py
DDA_EVENT_HOOK = "my_app.hooks.custom_event_handler"
Releasing
Releases are published to PyPI by the publish release GitHub Action, which
runs when a GitHub Release is created from a version tag.
-
Create a release branch off the latest
main. Past releases have usedrelease/X.Y.Z(e.g.release/0.25.3):git checkout main && git pull git checkout -b release/X.Y.Z
-
Bump the version with
bumpversion. This keepspyproject.tomlanddocs/source/conf.pyin sync:bumpversion patch # or minor / major
-
Update
CHANGELOG.md: rename the# [Unreleased]heading to# [X.Y.Z](matching the new version), and add a fresh empty# [Unreleased]section above it for future entries. -
Push the branch and open a pull request. Get it reviewed and merge it into
main. -
Create a GitHub Release at https://github.com/salesforce/django-declarative-apis/releases/new, targeting the merge commit on
mainand creating a new tag of the formvX.Y.Z. Publishing the Release triggers.github/workflows/publish-release.yml, which builds the sdist + wheel and uploads them to PyPI. The workflow can also be re-run manually from the Actions tab viaworkflow_dispatchif the publish step needs to be retried.
Documentation is built and published independently by ReadTheDocs from the repository, so no manual docs step is required as part of cutting a release.
Metadata
Release files for django-declarative-apis 0.34.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_declarative_apis-0.34.5.tar.gz | 56.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_declarative_apis-0.34.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 116.0 kB
Release files / django_declarative_apis-0.34.5.tar.gz
| Download URL | django_declarative_apis-0.34.5.tar.gz |
|---|---|
| Size | 56.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f68fc1fa6f43cae344d41fb387884ec15dac709d6ae3136d761849ca875c49f
|
|
BLAKE2b-256 checksum How to use checksums |
58651c22b6ccf20a8fa79e30f52a4a0d6fc320dfb8fd3bcebdc16eed8ee7bdb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / django_declarative_apis-0.34.5-py3-none-any.whl
| Download URL | django_declarative_apis-0.34.5-py3-none-any.whl |
|---|---|
| Size | 60.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7dfac2adbd6fbf16c7bd5bf0189109453dd98f1f6b01c382bc3e153847655638
|
|
BLAKE2b-256 checksum How to use checksums |
a7e031b41033f8984b5239f2e62468d82a9e988b04eef436371cd4b9583e6827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|