Skip to main content

Documentation Status

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.

  1. Create a release branch off the latest main. Past releases have used release/X.Y.Z (e.g. release/0.25.3):

    git checkout main && git pull
    git checkout -b release/X.Y.Z
    
  2. Bump the version with bumpversion. This keeps pyproject.toml and docs/source/conf.py in sync:

    bumpversion patch   # or minor / major
    
  3. 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.

  4. Push the branch and open a pull request. Get it reviewed and merge it into main.

  5. Create a GitHub Release at https://github.com/salesforce/django-declarative-apis/releases/new, targeting the merge commit on main and creating a new tag of the form vX.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 via workflow_dispatch if 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_declarative_apis-0.34.4.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_declarative_apis-0.34.4-py3-none-any.whl (60.0 kB view details)

Uploaded Python 3

File details

Details for the file django_declarative_apis-0.34.4.tar.gz.

File metadata

  • Download URL: django_declarative_apis-0.34.4.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_declarative_apis-0.34.4.tar.gz
Algorithm Hash digest
SHA256 7a7d31c1ad91a678487383fa4e01621c77f9621787720e8e432abbe76d1e8a03
MD5 cc246f87cd3d93d7e45dbf9e02deb92f
BLAKE2b-256 2ba6243f822976bbde3eba99034705353bb7263a725f4ac20121746c35acf36d

See more details on using hashes here.

File details

Details for the file django_declarative_apis-0.34.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_declarative_apis-0.34.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ab0873acf0a35215b32f95022b8fc447a4bdf510e689923bde8ed0187f951496
MD5 d2a7e95cd1b2c6c31ac14ed01c3e7006
BLAKE2b-256 40ea178bcd761302b270087bbfd2f3b7cdb749587bbaf9e333035f931a5a9c88

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.34.4 This release

2 files

0.34.3

2 files

0.34.2

2 files

0.34.1

2 files

0.34.0

2 files

0.33.0

2 files

0.32.0

2 files

0.31.7

2 files

0.31.6

2 files

0.31.5

2 files

0.31.4

2 files

0.31.3

2 files

0.31.2

2 files

0.31.1

2 files

0.29.0

2 files

0.28.0

2 files

0.27.0

2 files

0.26.0

2 files

0.25.3

2 files

0.25.2

2 files

0.25.1

2 files

0.24.0

2 files

0.23.1

1 file

0.22.3

1 file

0.22.2

2 files

0.22.1

2 files

0.21.0

1 file

0.20.0

2 files

0.19.3

2 files

0.19.2

2 files

0.19.1

2 files

0.19.0

2 files

0.18.5

2 files

0.18.4

2 files

0.18.3

1 file

0.18.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page