Django Rest Framework Discovery
Summary
Discovery allows you to create an API from an existing database with minimal effort. This project is based on Shabda Raaj's Bookrest. You can also leverage the capabilties of the Django Rest Framework to apply filtering, pagination and documentation generation. Examples can be found in the examples directory.
Problem Statement
The data is not always accessible in legacy applications. You might be in a situation where you need access to the data for reporting or prototyping new tools. Adding new functionality to legacy software can be cost prohibitive and this solution aims to work-around this issue.
Requirements
For successful schema generation, you need to have a primary key present in the table. Otherwise, it will be silently ignored.
Installation
pip install djangorestframework-discovery
In your settings.py:
INSTALLED_APPS = [
# ...
"rest_framework",
"rest_framework_discovery",
]
Add a variable to your settings.py named DISCOVERY_ALIAS_NAME. You can use any value, but discovery is recommended. You will use that to define the database you would like to use for viewset generation.
DISCOVERY_ALIAS_NAME = 'discovery'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'discovery': {
'NAME': 'YOUR_DB_NAME',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'YOUR_DB_USER',
'PASSWORD': 'YOUR_DB_PASSWORD',
'HOST': 'YOUR_DB_HOST',
'PORT': 'YOUR_DB_PORT',
},
}
Add the generated patterns to the rest of your application by modifying the urls.py.
urlpatterns = [
# ...
url(r'^api/discovery/', include('rest_framework_discovery.urls')),
]
You will also need to include DEFAULT_SCHEMA_CLASS explicitly in settings.py to get this to work. See additional details..
REST_FRAMEWORK = {
...
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
Testing
You can run through the testing suite by running runtests.py or tox.
Configuration
You can configure the following in settings.py:
DISCOVERY_ALIAS_NAME: (required) The database alias name to use with discovery.DISCOVERY_READ_ONLY: (optional)TrueorFalse, whether or not the viewsets should be read-only.DISCOVERY_INCLUDE: (optional) A list of tables that you would like to only include.DISCOVERY_EXCLUDE: (optional) A list of tables that you would like to ignore.
Metadata
Release files for djangorestframework-discovery 0.1.8
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 | Actions |
|---|---|---|---|---|
| djangorestframework-discovery-0.1.8.tar.gz | 5.9 kB | Without provenance | Details for djangorestframework-discovery-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| djangorestframework_discovery-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for djangorestframework_discovery-0.1.8-py3-none-any.whl |
Total release size: 13.6 kB
Release files / djangorestframework-discovery-0.1.8.tar.gz
| Download URL | djangorestframework-discovery-0.1.8.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87961156c1fff0ebc1a7a53155bf0093b053b9b0a0623df11e719e65a469905a
|
|
BLAKE2b-256 checksum How to use checksums |
e3ca76c63f900ff127022d17722d180a3ecc16b218ace6a84259ce1548ee1e75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5
|
Release files / djangorestframework_discovery-0.1.8-py3-none-any.whl
| Download URL | djangorestframework_discovery-0.1.8-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c9ee614a6b66d261b0f0bccdacda56e4e94cad0e2a5992bf502ebb62f84dd37
|
|
BLAKE2b-256 checksum How to use checksums |
f618677f3f4787bfdbdc5c05e912903312f37bbdeeab99451409682f34b121c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.5
|
Security for djangorestframework-discovery 0.1.8
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.