API for the Tech With Tim website using FastAPI.
- 🏁 Getting Started
- 🐳 Running with Docker
- ✅ Linting
- 🚨 Tests
- 📚 Docs
- 📜 Licence
- ⛏️ Built Using
- ✍️ Authors
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See Running with Docker if you want to setup the API faster with Docker.
Create a new Discord application here by clicking the New application
button and name it whatever you want.
Now that you have an application, go to the OAuth2 tab.
And add http://127.0.0.1:5000/auth/discord/callback
to the redirects.
Install Pipenv:
pip install pipenv
Install the required packages and the packages for development with Pipenv:
pipenv install --dev
Start by writing this in a file named .env
:
REDIS_URI=
SECRET_KEY=
POSTGRES_URI=
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
And fill in the variables with the values below:
REDIS_URI
is the Redis server URI.SECRET_KEY
is the key used for JWT token encoding.POSTGRES_URI
is the PostgreSQL database URI.DISCORD_CLIENT_ID
is the Discord application ID. Copy it from your Discord application page (see below).DISCORD_CLIENT_SECRET
is the Discord application secret. Copy it from your Discord application page (see below).
For testing you need to add these environment variables:
TEST_REDIS_URI
is the Connection URI for Redis testing server.TEST_POSTGRES_URI
is the PostgreSQL database URI for tests.
If you are self hosting the Piston API, you need to set the PISTON_URL
environment variable.
Run the API and initialise the database:
If you have not initialized submodules use this command:
git submodule update --init
To update submodules:
git submodule foreach git pull
pipenv run python launch.py runserver --initdb
The API should run at http://127.0.0.1:5000. For more information about the CLI, check the docs here.
Both the API and the frontend can be started using Docker. Using Docker is generally recommended (but not strictly required) because it abstracts away some additional set up work.
-
Setup the discord app like done here.
-
Make a file named
.env
like done here. You don't need the DB_URI environment variable though. -
Then make sure you have
docker
anddocker-compose
installed, if not read this for docker and this for docker compose. -
Deploy the API:
docker-compose up --build api
We use a pre-commit hook for linting the code before each commit. Set up the pre-commit hook:
pipenv run pre-commit install
If you want to run the pre-commit checks before trying to commit, you can do it with:
pipenv run lint
To test the API, we use the pytest framework to make sure that the code we write works.
Run the tests:
pipenv run test
When you contribute, you need to add tests on the features you add.
- Python - Language
- FastAPI - Backend framework
- PostDB - Database module
- pytest - Testing framework
- pytest-asyncio - Testing plugin for pytest
- @SylteA - Most of the backend
- @Shubhaankar-sharma - Docker deployment
- @takos22 - Some endpoints and markdown files
See also the list of contributors who participated in this project.