Skip to content

Commit

Permalink
Merge pull request #43 from wednesday-solutions/feat/documentation
Browse files Browse the repository at this point in the history
Documentation
  • Loading branch information
shamoilattaar-wednesday authored Apr 18, 2024
2 parents f1453be + 5d828b4 commit 532ee01
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 48 deletions.
145 changes: 97 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
# FastAPI Template

<img align="left" src="./assets/fastAPILogo.svg" width="480" height="510" />

<div>
<a href="https://www.wednesday.is?utm_source=gthb&utm_medium=repo&utm_campaign=serverless" align="left" style="margin-left: 0;">
<img src="https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f5879492fafecdb3e5b0e75_wednesday_logo.svg">
</a>
<p>
<h1 align="left">Python FastAPI Template
</h1>
</p>

<p>
An enterprise Python FastAPI template application to create and deploy FastAPI project.
</p>

___


<p>
<h4>
Expert teams of digital product strategists, developers, and designers.
</h4>
</p>

<div>
<a href="https://www.wednesday.is/contact-us?utm_source=gthb&utm_medium=repo&utm_campaign=serverless" target="_blank">
<img src="https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f6ae88b9005f9ed382fb2a5_button_get_in_touch.svg" width="121" height="34">
</a>
<a href="https://github.com/wednesday-solutions/" target="_blank">
<img src="https://uploads-ssl.webflow.com/5ee36ce1473112550f1e1739/5f6ae88bb1958c3253756c39_button_follow_on_github.svg" width="168" height="34">
</a>
</div>

___

<span>We’re always looking for people who value their work, so come and join us. <a href="https://www.wednesday.is/hiring">We are hiring!</a></span>
</div>


This repository provides a template for creating and deploying a FastAPI project. Follow the steps below to set up the local environment, run the project, manage database migrations, and deploy the service on AWS ECS.

Expand All @@ -25,24 +63,23 @@ This repository provides a template for creating and deploying a FastAPI project

- Python 3.11+ support
- SQLAlchemy 2.0+ support
- Asynchoronous capabilities
- Asynchronous capabilities
- Database migrations using Alembic
- Basic Authentication using JWT
- Caching using Redis
- Error reporting using Sentry
- Asynchoronous background tasks using Celery
- Test cases
- Dockerized application
- Asynchronous background tasks using Celery
- Feature flagging to enable/disable features
- Readily available CRUD operations
- Readily available middlewares for rate limiting, request id injection etc
- Error reporting using Sentry
- Type checking using mypy
- Linting using flake8
- Formatting using black
- Code quality analysis using SonarQube
- Application monitoring using Signoz
- Feature flagging added - User can enable/disable features
- Database Monitoring using percona
- Loadtests using locust
- Application monitoring using SigNoz
- Database Monitoring using Percona
- Load-tests using Locust

### Getting Started

Expand All @@ -55,13 +92,15 @@ This repository provides a template for creating and deploying a FastAPI project

- To initialize and set up your environment, run the following script:

```
```shell
./scripts/initialize-env.sh
```

This script installs the necessary dependencies and prepares the environment for running the FastAPI application on your machine.

##### Activate the environment

- To activate the python environment, run the following command:
```
# Mac & Linux:
source ./venv/bin/activate
Expand All @@ -88,56 +127,64 @@ DB_ROOT_PASSWORD=

#### 3. Database Migrations
Create new database migrations when you make changes to your models. Use the following command:
```
```shell
alembic revision -m 'brief description of changes'
```

This command initializes a new migration script based on the changes made to your models. Provide a brief description of the changes in the migration message.

Apply the database migrations with the following command:
```
```shell
alembic upgrade head
```
This command updates the database schema to reflect the latest changes defined in the migration scripts

#### 4. Redis Dependency
##### Install Locally:
```
# Mac
brew install redis
brew services start redis

# Windows
Please refer: https://developer.redis.com/create/windows/
To install and set-up Redis execute the following commands:

# Linux
sudo apt install redis
sudo systemctl enable redis
sudo systemctl start redis
sudo systemctl status redis # verify status
##### Install Locally:

```

- ###### Mac
```shell
brew install redis
brew services start redis
```

- ###### Windows
```
Please refer: https://developer.redis.com/create/windows/
```
- ###### Linux
```shell
sudo apt install redis
sudo systemctl enable redis
sudo systemctl start redis
sudo systemctl status redis # verify status
```

##### Install via docker:
```
```shell
docker run --name recorder-redis -p 6379:6379 -d redis:alpine
```

#### 5. Celery Dependency
Run following command to initiallize the celery worker
```
To initialize the celery worker execute the following command:
```shell
celery -A app.app.celery worker -l info
```
[Optional] Turn Up Celery Flower with
```
[Optional] To activate Celery Flower execute the following command:
```shell
flower --broker=${REDIS_URL}/6 --port=5555
```

#### 6. Run the Project

##### Running Application Locally

```
```shell
./scripts/local_server.sh
```

Expand All @@ -149,7 +196,7 @@ This script upgrades the database migrations using Alembic and starts the FastAP
- Inject Docker environment using
```shell
set -a source .env.docker set +a
- use following command to turn on the application
- Execute following command to turn on the application
```shell
docker compose --env-file .env.docker up
```
Expand Down Expand Up @@ -181,20 +228,20 @@ async def external_service_endpoint():
raise HTTPException(status_code=503, detail="Service temporarily unavailable")
```
#### Configuring Signoz Monitoring Tool
#### Configuring SigNoz Monitoring Tool
To utilize Signoz for monitoring your applications, follow these steps:
To utilize SigNoz for monitoring your applications, follow these steps:
1. **Sign Up:**
- Go to the Signoz cloud portal [here](https://signoz.io/teams/).
- Go to the SigNoz cloud portal [here](https://signoz.io/teams/).
- Sign up for an account.
- After signing up, you will receive a verification email from Signoz.
- After signing up, you will receive a verification email from SigNoz.
2. **Verify Email:**
- Verify your email through the verification email sent by Signoz.
- Verify your email through the verification email sent by SigNoz.
3. **Application Monitoring Setup:**
- Once verified, log in to your Signoz account.
- Once verified, log in to your SigNoz account.
- Click on "Application Monitoring".
4. **Configure Application:**
Expand All @@ -205,34 +252,36 @@ To utilize Signoz for monitoring your applications, follow these steps:
5. **Setup Quickstart:**
- Select your OS and architecture.
- Choose Quickstart.
6. **Install Dependencies:**
- Skip this step and move to next step
- Skip this step and move to next step.
7. **Configure Environment Variables:**
- In the next step, you need to update the values for the following variables in `.env.local` and `.env.docker` files:
```shell
```
OTEL_RESOURCE_ATTRIBUTES=
OTEL_EXPORTER_OTLP_ENDPOINT=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_PROTOCOL=
```
#### Logging with Signoz
#### Logging with SigNoz
To enable logging with Signoz, follow these steps:
To enable logging with SigNoz, follow these steps:
1. **Open Dashboard:**
- Log in to your Signoz dashboard.
- Log in to your SigNoz dashboard.
2. **Navigate to Logs Section:**
- Go to the logs section of your dashboard.
3. **Configure Log Sending:**
- Click on "Sending Logs to Signoz".
- Click on "Sending Logs to SigNoz".
4. **Follow Instructions:**
- Follow the instructions provided to configure log sending to Signoz.
- Follow the instructions provided to configure log sending to SigNoz.
By following these steps, you can effectively set up application monitoring and logging using Signoz for your Python FastAPI applications.
By following these steps, you can effectively set up application monitoring and logging using SigNoz for your Python FastAPI applications.
#### Database Monitoring Using Percona
Expand All @@ -246,7 +295,7 @@ To monitor your database using Percona, follow these steps:
3. **Login:**
- Use the following credentials to log in:
```shell
```
Username: admin
Password: admin
```
Expand All @@ -271,7 +320,7 @@ By following these steps, you'll successfully configure Percona to monitor your
#### Deploy Service on AWS ECS
To deploy the FastAPI application on AWS ECS, use the following script:

```
```shell
./scripts/setup-ecs.sh develop
```

Expand Down
Binary file added assets/Cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Python FastAPI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Social Media.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

1 comment on commit 532ee01

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
app
   app.py38380%1–70
app/config
   __init__.py3167%6
   base.py38879%29–36, 54–55
   celery_config.py17170%1–27
   celery_utils.py21210%1–30
   redis_config.py5260%8–9
app/constants
   jwt_utils.py161131%11–23
app/daos
   home.py10550%11–18
   users.py726411%12–136
app/middlewares
   cache_middleware.py51510%1–67
   rate_limiter_middleware.py25250%1–35
   request_id_injection.py17170%1–25
app/models
   __init__.py330%1–5
   users.py27270%1–38
app/routes
   __init__.py12120%1–15
app/routes/cache_router
   __init__.py330%1–5
   cache_samples.py12120%1–18
app/routes/celery_router
   __init__.py330%1–5
   celery_samples.py12120%1–17
app/routes/home
   __init__.py330%1–5
   home.py33330%1–45
app/routes/users
   __init__.py330%1–5
   users.py38380%1–57
app/schemas/users
   users_request.py42420%1–73
   users_response.py10100%1–14
app/sessions
   db.py53530%1–82
app/tests
   test_basic.py201620%8–34
   test_daos_home.py231057%15–22, 28–37, 41
   test_daos_users.py1109514%19–208
app/utils
   exception_handler.py19190%1–36
   redis_utils.py440%1–7
   slack_notification_utils.py14140%1–32
   user_utils.py25250%1–36
app/wrappers
   cache_wrappers.py19190%1–24
TOTAL81871612% 

Tests Skipped Failures Errors Time
2 0 💤 0 ❌ 2 🔥 0.497s ⏱️

Please sign in to comment.