Parkkihubi is a Django based REST API for processing parking data.
- Python >= 3.10
- PostgreSQL 14 + PostGIS 3.4
Preferred versions are Python 3.12, PostgreSQL 16.13 and PostGIS 3.5 on Ubuntu 24.04.
Current uv.lock pins Django to 5.2, but 4.2 and 6.0 should also work.
Use uv to install and maintain installed dependencies. You may also need build essentials and some development libraries installed.
sudo apt-get install build-essential libpq-dev
pipx install uv # Or see uv's docs for other install methods
And then, to install the dependencies:
uv sync
Environment variables are used to customize base configuration in
parkkihubi/settings.py. If you wish to override any settings, you can place
them in a local .env file which will automatically be sourced when Django imports
the settings file.
Create a basic file for development as follows
echo 'DEBUG=True' > .env
PARKKIHUBI_PUBLIC_API_ENABLEDdefaultTruePARKKIHUBI_MONITORING_API_ENABLEDdefaultTruePARKKIHUBI_OPERATOR_API_ENABLEDdefaultTruePARKKIHUBI_ENFORCEMENT_API_ENABLEDdefaultTrue
Run all tests
pytest
Run with coverage
pytest --cov-report html --cov .
Open htmlcov/index.html for the coverage report.
To import Helsinki parking areas run:
python manage.py import_parking_areas
To import payment zones from geojson run:
python manage.py import_geojson_payment_zones --domain=HKI <GEOJSON_FILE_PATH>
To import permit areas from geojson run:
python manage.py import_geojson_permit_areas --domain=HKI <GEOJSON_FILE_PATH>
With VSCode environment, you can start development server from debug side-bar. You also need to run migrations and generate static files.
python manage.py migrate
python manage.py collectstatic --noinput
Operator API will be available at http://127.0.0.1:8000/operator/v1/
Enforcement API will be available at http://127.0.0.1:8000/enforcement/v1/
Public API will be available at http://127.0.0.1:8000/public/v1/
The API documentation conforms to Swagger Specification 2.0.
Three possible ways (out of many) to generate the documentation:
-
Run the documentation generating script:
./generate-docsThe output will be in
docs/generateddirectory by default. If you want to generate to a different directory, give that directory as the first argument to the script. -
Probably the recommended way.
Installation:
npm install -g bootprint npm install -g bootprint-openapiRunning (in
parkkihubirepository root):bootprint openapi docs/api/enforcement.yaml </output/path/enforcement/> bootprint openapi docs/api/operator.yaml </output/path/operator/> -
Due to a bug in swagger-codegen, we're using an unreleased version at the moment.
To build swagger-codegen from source, you need Apache maven installed (you'll need java 7 runtime at a minimum):
# Ubuntu sudo apt-get install mavenClone swagger-codegen master branch and build it:
git clone https://github.com/swagger-api/swagger-codegen cd swagger-codegen/ mvn clean package # Takes a few minutesThe client will now be available at
modules/swagger-codegen-cli/target/swagger-codegen-cli.jar.To build the docs, in
parkkihubirepository root:cd docs/api java -jar /path/to/codegen/swagger-codegen-cli.jar generate \ -i enforcement.yaml -l html2 -c config.json \ -o /output/path/enforcement/ java -jar /path/to/codegen/swagger-codegen-cli.jar generate \ -i operator.yaml -l html2 -c config.json \ -o /output/path/operator/