This repo is the main API of AI Atelier. It allows Clients (our mobile applications and web app) to interact with our product.
To work properly, the API acts as a middle-tier API and fetch data from our users' emails providers (Gmail and Outlook mainly).
This API is a FastAPI python API. After launching your app locally you can access the API documentation at the http://localhost:8000/docs url.
FastAPI is a very lightweight framework to manage a python API. It comes with a lot of coroutines features (async mode) that we could capitalized on to better manage I/O (with the Microsoft/Gmail API) and CPU use at some point with our ML models.
The main.py file is the entrypoint and contains the API endpoints.
All the business logic is located in the betteremail folder with mainly:
graph.pythat allows us to manage the Microsft Graph API;google.pythat will allow us to manage Gmail API;
We use poetry as a package managers (pretty modern tool wih more features that pip to easily manage different environments).
#on Mac
curl -sSL https://install.python-poetry.org | python3 -
At the root
poetry install
You will need environment variables. The project comes with default and publics data to work locally. Currently, you will need to ask for the MICROSOFT_CLIENT_SECRET variable.
At the root
uvicorn main:app --reload
- A user who first tries to interact to our API will be asked to provide his email;
- Based on the email, we will require the user to complete an oAuth2 workflow, and consent to our requirements (access to their inbox on their behalf);
- Then, the client can start interacting with the API which will act on behalf of our users to fetch data from their mail boxes directly;
This is for users with @outlook.fr or @microsoft.com email addresses.
We have registered an App on Azure AD betteremail-mobile-client.
with the following scopes:
- profile, email, openid, offline_access, Mail.Read
- Mail.read
We use the On-Behalf-Of workflow with matches what we want to do.
/!\ For now we have only one App registered. We could, in the future look for having 2 App registered:
- one for the client - API ;
- one the API - Graph;
This could give us more flexibility to manage scopes and rights.
It's a work in progress. The interface already exists though.