d4 - Base Project Generator
Generate a backend and frontend stack using Python and json-ld, including interactive API documentation.
d4? What is d4 for?
d4 is a kind of template project for creating µServices based on python. These µServices collect existing data (e.g. inventory data from IT systems) and make this data available in a distributed way via standardised interfaces (REST-API) and in a standardised form (JSON-LD).
For this purpose, the µServices collect data from several Single Points of Truth (SPOTs) and offer possibilities to link the individual data sets (from different SPOTs) with each other. There is also a µService template that can be used to create a very simple SPOT with a web UI and CSV/Excel interface. This is used for data enrichment (distributed in several locations) that cannot be automatically read from systems. The templates produce µServices that are intended to enable the value-added consolidation of distributed data across organisational and departmental boundaries.
Some feature aspects:
- µservices adapting and caching SPOTs
- robust and fast, based on python, fastapi, docker
- uses OpenAPI (formerly Swagger)
- uses JSON-LD including schemas
- a µService can enrich information from its "neighbourhood" itself
- at a "psydocentral" location, a lot of data from µServices can be consolidated in a "big graph DB".
- the template project evolved from various iterations to improve heterogeneous IT infrastructures with "data driven" aspects.
How to use it in a virtual python environment.
optionally create a virtual environment like
$ python3 -m venv ~/.virtualenvs/d4
$ source ~/.virtualenvs/d4/bin/activate[.fish|.csh]
$ pip --version
pip 21.2.4 from [...]/d4/lib/python3.10/site-packages/pip (python 3.10)
Go to the directory where you want to create your project and run:
$ pip install --upgrade pip
$ pip install -r requirements_dev.txt
# > cookiecutter https://github.com/mleist/cookiecutter-fastapi-json-ld
$ cookiecutter .
project_name [Base Project]:
project_slug [base-project]:
cookiecutter has created a project under base-project.
Now we start - without any further changes - the backend
$ cd base-project/backend/
$ uvicorn app.main:app --reload
INFO: Will watch for changes in these directories: ['[...]/base-project/backend']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [50623] using statreload
INFO: Started server process [50625]
INFO: Waiting for application startup.
INFO: Application startup complete.
From here on, the generated µService runs.
$ curl http://127.0.0.1:8000
{"message":"Hello world! From FastAPI running on Uvicorn with Gunicorn. Using Python 3.10"}
More to read
documentation.
There isintroduction to the d4 basics.
There is anWhat is the difference between introduction and documentation?
The introduction is for clarification of how d4 works, it is not included in the project cookiecutter will have created.
The documentation is part of the project and thus intended for later use in the generated project.