An ASGI framework to build HTTP API's from a Python module structure.
Go to file
Maxime Alves LIRMM 0282da6e3d [release][0.1.0] First HalfAPI release
Squashed commit of the following:

commit 68032dc55a07565ccd17a188407d9ac2537b62e6
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 15:40:26 2020 +0200

    [release][0.1.0] First HalfAPI release

commit a046a81114a3ae22bbc84a53f1e85217a0954dbc
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 15:26:15 2020 +0200

    [doc] màj du readme

commit ed45b3011125c071aa53df8087d28bfa1150b373
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 11:03:17 2020 +0200

    [wip] rm apidb

commit 7df4b9bacf3d26f09ea07856587505f74284cab4
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 10:58:46 2020 +0200

    [db] forgot foreign key router->domain

commit 604b9a90f405121725e4b2126d73a5a83eec398f
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 10:51:01 2020 +0200

    [wip] routes mounting fixed

commit c50a5572633d7dcc3cad48ef79c5ea1ca098284d
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Thu Jul 23 10:29:09 2020 +0200

    [wip][db][nf] http_verb, fct_name are in api.route

commit 2b5b78db2f9c280dd5eb9d8bafc9174d9afc092f
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Wed Jul 22 17:37:21 2020 +0200

    [wip] refactor du 22 juillet 2222

commit d019b7e333ab37f106895c84521cef1bfe768caa
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Wed Jul 22 14:48:51 2020 +0200

    [wip] remove "version" from app

commit 98ccd61dcf369b8c4aac817a0c8409b6fed00f50
Author: Joël Maïzi <joel.maizi@lirmm.fr>
Date:   Wed Jul 22 14:45:28 2020 +0200

    Remove api.version from database.

commit aa0d4f8dbba8b8ec878835bb58b69facff7e675e
Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 21:46:22 2020 +0200

    [db] added router as api.acl primary_key part

commit a97984e9de0e6a00bddca7dece0c715c9c16cbe1
Author: Maxime Alves LIRMM@home <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 21:41:31 2020 +0200

    [wip] moved all acl treatment to acl_caller_middleware, fix route mounting, fix typo in logs

commit 3dd310e80aaf6cb32f6c4ac23c1e2a924cebfde1
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 13:10:26 2020 +0200

    [wip][nf] gestion des routes avec routers

commit c2687c4a24126fbc3e57257bf23c267b334df522
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 12:39:53 2020 +0200

    [db] ajout de la table api.router

commit 9a10f76cf7790f75f23b72e19b0a58978752565c
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 12:19:53 2020 +0200

    [db] renommage des champs d'acl

commit c4e8c26a24835559d2e9b251df0eb462fe7e667d
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 12:13:38 2020 +0200

    [wip][nf] modification du systeme de montage des routes

commit b7e8352ba1e427e9883797a44bb0f3da5edd576d
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 11:15:30 2020 +0200

    [wip][dbupdate] insertion des routes au nouveau format

commit 28947444c4c062e6ced74f9bfdef11a36ddc438b
Author: Maxime Alves LIRMM <maxime.alves@lirmm.fr>
Date:   Tue Jul 21 10:32:57 2020 +0200

    [wip][dbupdate] Suppression des routes hors domaine
2020-07-23 17:54:47 +02:00
conf [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
halfapi [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
scripts [query] add fields list to query 2020-07-20 11:20:58 +02:00
tests [debug] better handling of debug routes 2020-07-10 12:58:53 +02:00
.gitignore [middleware] put AclCallerMiddleware in lib file 2020-07-08 17:12:58 +02:00
CHANGELOG.md [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
LICENSE [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
README.md [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
__init__.py [WIP] Import halfapi OK dans test_jwt_middleware. 2020-07-03 21:39:59 +02:00
pytest.ini [test] add default DEBUG flag for pytest, add tests for jwt_middleware 2020-07-09 10:29:17 +02:00
requirements.txt [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00
setup.py [release][0.1.0] First HalfAPI release 2020-07-23 17:54:47 +02:00

README.md

HalfAPI

This Python-based ASGI application aims to provide the core functionality to multiple API domains.

It's developed at the LIRMM in Montpellier, France.

The name "halfAPI" comes from the deep relationship between it and halfORM, a project authored by Joël Maizi.

You'll need a database with the API details. You can find the database model in halfapi/models/api.sql

NOTE : The authentication module is deeply linked with auth_lirmm, so if you need to use the acl.connected function, you will need a running auth_lirmm server to get a token.

TODO : include a token generation tool for testing purpose.

Dependencies

  • python3
  • python3-pip
  • poetry
  • uvicorn

Installing

pip install .

As the project uses the poetry package manager, you first have to install it for the current user. Be sur to have pip binary directory ($HOME/.local/bin) included in your PATH.

pip3 install poetry

Be sur to include the bin directory of pip in your PATH.

Installation of the deps :

poetry install

If you need a domain, i.e: organigramme, just add -E organigramme to the command.

NOTE : You need to run poetry install before installing any domains (that depends on halfapi).

API database

Populate the API database with te server information, the domain's routes, and their ACL by running the following command :

poetry run halfapi dbupdate

NOTE: You need to have the domain's package installed if you want to populate the api routes module, as it check for the existence of the acl functions.

Database configuration

The api and domains' databases connection settings are stored by default in /etc/half_orm. Check halfORM documentation for more information on how to write these configuration files.

You can set the HALFORM_SECRET environment variable if you want to specify an authentication secret.

TODO : find a modular way to configure the database connection for each mounted domain

Running

Development mode

In the halfapi repository, type :

poetry run halfapi

If you need to launch the test suite (only works if you have pytest installed) :

poetry run pytest

Production

The production server may use different init systems. As our main server is Debian-based, we use systemd services to manage the api server. Find the right service files and configure them properly in order to make your production setup perfect.

cp conf/systemd/lirmm_api* /etc/systemd/system/
systemctl daemon-reload
systemctl start lirmm_api

To make it start at boot :

systemctl enable lirmm_api

To get the logs :

journalctl -f --unit lirmm_api