django_describer
An easy-to-use tool to auto-generate GraphQL API from Django models. More APIs TBD.
Get started
- Install
django_describervia PyPI, e. g.pip install django_describer. - Add
graphene_djangoto yourINSTALLED_APPSin Django settings. Otherwise, the template for GraphQL would be invisible.
Usage
Write your Django models:
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=50)
@property
def short_books(self):
return self.books.all().filter(page_count__lt=300)
def __str__(self):
return self.name
class Book(models.Model):
name = models.CharField(max_length=50)
page_count = models.IntegerField()
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE, blank=True, null=True, related_name="books")
def __str__(self):
return "{} ({})".format(self.name, self.publisher)
Now write a Describer for it. You can specify:
- which fields (and model properties) are exposed to the API and who can access them
- which CRUD operations are allowed for each model and who can perform them
- extra actions on each model
Per-request field specification, ordering, filtering and pagination are for granted.
from django_describer.actions import DetailAction
from django_describer.datatypes import QuerySet
from django_describer.describers import Describer
from django_describer.permissions import IsAuthenticated
from user.models import User
class UserDescriber(Describer):
model = User
extra_actions = {
"myself": DetailAction(permissions=IsAuthenticated, fetch_fn=lambda request, pk: request.user, id_arg=False)
}
Import all describers into your urls.py and create a URL for the api:
from django.contrib import admin
from django.urls import path
from django_describer.adapters.base import generate
from django_describer.adapters.graphql.main import GraphQL
from course.describers import *
from user.describers import *
urlpatterns = [
path('admin/', admin.site.urls),
path("graphql/", generate(GraphQL)),
]
Now you can do things such as:
query q{
UserMyself{
id
username
}
}
mutation m{
UserCreate(data: {username: "John", password: "asdf"}){
object{
id
}
}
}
Metadata
Release files for django-describer 0.0.24
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_describer-0.0.24.tar.gz | 14.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_describer-0.0.24-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.2 kB
Release files / django_describer-0.0.24.tar.gz
| Download URL | django_describer-0.0.24.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44593368790fce69bb2efe9d99bb49452a1663a365bfd2ea0846c49bf4a1e162
|
|
BLAKE2b-256 checksum How to use checksums |
81e6a4c7b822014f67235fffbe1bc3e11d7bd5841326e9b4ecaa04798dc82b78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.6
|
Release files / django_describer-0.0.24-py3-none-any.whl
| Download URL | django_describer-0.0.24-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe14ad5ea0139edee29aef3863a73a57a609e812829ef163d90e70ac309549da
|
|
BLAKE2b-256 checksum How to use checksums |
8bce162de05c4ee70445e03228ed5377fac24dbc89f3f08477f58e938e22fef0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.6
|
Security for django-describer 0.0.24
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.