Do check our First Contribution repository, where we have provided the guidelines to set up Git and how to make a pull request !
Copy the URL of the forked repository and clone it.
git clone https://github.com/<github_username>/fintech-api
cd fintech-api
Folder Structure
fintect-api
│
└───📂helpers
│ │ { Python functions for different calculations }
│
└───📂tasks
│ │ { Python functions for different tasks }
│
└───📂validators
│ │ { Pydantic Models for different validations }
📄.gitignore
📄CONTRIBUTING.md
📄main.py
📄README.md
📄requirements.txt
📄test_main.py
python -m venv env
For windows
env\Scripts\Activate.ps1
For Linux
source env/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload
from root directory (FINTECH-API) where test_main.py is located
pip install pytest # install pytest, only need to do once
pip install httpx
pytest #run the test
What to contribute?👀 Check the project workflow section below.
Once you are done with the changes you wanted to add. Follow the steps to make the pull request.
git checkout -b <branch_name>
git add .
git commit -m "Enter your message here"
git push origin <branch_name>
Briefly explaining, this project is an API providing endpoints that makes your financial calculation easy. This API can be easily integrated into websites, mobile applications, chrome extensions, etc. So how it works?
-
Once you run the server, and route to a path. For now, be it
/simple_interest_rate
(mentioned in main.py). You'll need to pass some query parameters. -
As it is described, this endpoint returns the simple interest based on some input provided by the user.
-
Or you can route to the
/docs
path, where you can easily access and visualize the endpoints through a dashboard provided by swagger UI. -
Here you can see, we are calling a function
simple_interest_rate()
that is defined inside./helpers/functions.py
. -
This function is responsible for making some calculations based on the parameter passed and returns the required value.
-
So, to add an endpoint, raise an issue regarding adding an endpoint. Once you are assigned, go through the project setup and set up the project on the local machine.
-
Then create a function in
./helpers/functions.py
, passing the required parameters and returning the output as shown below
# Function to Calculate Simple Interest Rate
def simple_interest_rate(amount_paid:float, principle_amount:float, months:int):
term = months/12
interest_paid = amount_paid-principle_amount
rate = (interest_paid*100)/(principle_amount*term)
return rate
-
Cross-validate your endpoint output from some online calculators available or even manually.
-
After completing with creating the function, create the request validation in
validators/request_validation.py
like this -
class SimpleInterestRateRequest(BaseModel):
amount_paid: float
principle_amount: float
months: int
- Once the validation is done, create a task called
simple_interest.py
in./tasks
and the task like this -
def simple_interest_rate(amount_paid: float, principle_amount: float, months: int):
try:
rate = functions.simple_interest_rate(amount_paid, principle_amount, months)
return {
"Tag": "Simple Interest Rate",
"Total amount paid": amount_paid,
"Principle amount": principle_amount,
"Interest Paid": amount_paid - principle_amount,
"Interest Rate": f"{rate}%",
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
- Once the task is ready, create an endpoint in the
main.py
file following all the good practices of Fast API.
@app.post(
"/simple_interest_rate",
tags=["simple_interest_rate"],
description="Calculate simple interest rates",
)
def simple_interest_rate(request: SimpleInterestRateRequest):
return simple_interest_rate_task(request.amount_paid, request.principle_amount, request.months)
+Also add your funtion in ENDPOINTS.md
.
**POST** `/simple_interest_rate`
- Request body : `{
"amount_paid": 20.23,
"principle_amount": 30.9,
"months": 5
}`
- Sample output
```py
{
"Tag": "Simple Interest Rate",
"Total amount paid": 20.23,
"Principle amount": 30.9,
"Interest Paid": -10.669999999999998,
"Interest Rate": "-82.87378640776697%"
}
+Update the Docs
|---------------------------|----------------------------------------|---------------------------------------------------------|
| GET /simple_interest_rate | Calculate simple interest rates | - `amount_paid` (float): The amount paid. |
| | | - `principle_amount` (float): The principle amount. |
| | | - `months` (int): The number of months. |
+ And that's it, you are now ready to make your pull request.
---