| Version: | 0.13.0 |
|---|---|
| Source: | https://github.com/maykinmedia/zgw-consumers |
| Keywords: | OpenAPI, Zaakgericht Werken, Common Ground, NLX |
| PythonVersion: | 3.6, 3.7, 3.8 |
Manage your external API's to consume.
Contents
- Store services with their configuration in the database
- Integrate with OpenAPI 3.0 specifications
- NLX support
- Declare data/domain objects as modern Python dataclasses
- Python 3.6 or newer
- setuptools 30.3.0 or newer
- Django 2.2 or newer
- Install from PyPI
pip install zgw-consumers- Add
zgw_consumersto theINSTALLED_APPSsetting. - Optionally override
ZGW_CONSUMERS_CLIENT_CLASSto a custom client class. - Optionally specify
ZGW_CONSUMERS_OAS_CACHEto point to a separate django cache. Defaults todjango.core.cache.DEFAULT_CACHE_ALIAS, which isdefaultin practice. For performance reasons we highly recommend to use a real cache backend like Redis or Memcache.
In the Django admin, you can create Service instances to define your external APIs.
Client
To get a client for a given resource, you can use:
from zgw_consumers.models import Service
client = Service.get_client(some_url)Or, to just retrieve the auth header(s):
from zgw_consumers.models import Service
auth = Service.get_auth_header(some_url)Data model
Use zgw_consumers.api_models.base.factory to turn raw JSON responses into instances
of domain models:
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.zaken import Zaak
results = client.list("zaak")["results"]
return factory(Zaak, results)It works for both collections and scalar values, and takes care of the camel-case to snake case conversion.
You can also define your own data models, take a look at the zgw_consumers.api_models
package for inspiration.