This is a simple Python web app written in FastAPI with an SQLAlchemy ORM and an SQLite database. The app is implementing a sign in with a Github account using the OAuth protocol. After a successful login with Github account, the /user endpoint is requested, this data is stored in the DB and presented in a simple HTML interface.
A simple FastAPI app can be written in one file, but here that is not the case. Here I am presenting the structure of a FastAPI larger project where each logical part lives in its own module.

- Explorer
- Code
- Readme
I use pyenv to setup the virtual env and install the specific python version. The project should work with most recent versions of Python and you don't have to use pyenv to create the virtual env, if you prefer something else.
- Create a virtualenv for the project:
pyenv virtualenv 3.12.2 damilah cdinto the project and run:pyenv local damilah. This command connects the virtualenv to the project folder. When youcdinto the project folder the virtualenv will automatically be activated. Also, the editors, like VSCode will automatically activate the right virtualenv.- Install third party libraries from the requirements file:
pip install -r requirement.txt - Install third party dev libraries from the dev requirements file:
pip install -r requirement.txt. - Modify env.example to .env and update the variables inside if needed. To make it easier for you, I've decided to upload this project with my registered app credentials. You can run directly the project after installing the requirements.
- Run the app:
uvicorn main:app --reload - For development pre-commit is used and it is installed in step 4. For development to set it up run:
pre-commit install.ruffis used for both linting and formatting. The custom rules can be found in thepyproject.tomlfile.
This app works with the Github OAuth API, so you will need to register an app from the "developers" tab in the settings of your Github settings. Once you create the app, you need to generate the "client secret" and store it in a safe place. The app client id and client secret are needed for the authentication process. These are stored as enviroment variables in the system or in the .env file. Currently the project runs with my own creds, so you don't have to register the Github app.
Run the app: uvicorn main:app --reload
I've chosen the Adapter pattern in order to adapt the requests library and provide a clean interface for making requests to the Github API.
“The Adapter Pattern allows incompatible interfaces to work together by wrapping one with another expected interface.”
Why this pattern?
- Decouples your code from third-party libraries
- Simplifies testing (you can mock your adapter instead of the library)
- Makes refactoring easier (swap out the library without changing your app logic)