This lab leveraged the FastAPI framework for building APIs with Python 3.6+ based on standard Python type hints. In this lab we worked on 2 examples one was just Fastapi demo and other we created a fastapi that can be used to track investors buying and selling on the stock-market.
In addition to serving PUT and GET requests, the endpoint stores all data on DynamoDB.
The key features are:
- Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.
- Fast to code: Increase the speed to develop features by about 200% to 300%. *
- Fewer bugs: Reduce about 40% of human (developer) induced errors. *
- Intuitive: Great editor support. Completion everywhere. Less time debugging.
- Easy: Designed to be easy to use and learn. Less time reading docs.
- Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
- Robust: Get production-ready code. With automatic interactive documentation.
- Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.
Experiment Setup
Prerequisites
- Installed below 3 libraries
- pip3 install fastapi
- pip3 install uvicorn
- pip3 install iexfinance
- Created a free developer account in IEXCloud to access the current stock price using API tokens.
- Created a table Customer_Trades in AWS DynamoDB to store the data from API.
Example-1
- In python file we have code for root
- Used the below command highlighted command to run the app
- App is launched in port 127.0.0.1:8000 by default
Result-1
We also tested the docs and executed get and put methods.
Example-2
- Here we are using trades.py and stock_price.py files
Stock_price.py contains the function that is fetching current stock price based on ticker.
Result-2
- Executing get and post methods and checking DynamoDB records
- Getting current of stock of Apple
- Adding a customer entry in DynamoDB
- Record is successfully stored
- AWS Dynamodb Table Console
- Getting details of Customer records based on ID
Lesson Learned
- Learned to create an app using Fastapi framework
- Learned to store and fetch data using api from AWS DynamoDB
- Learned about default docs in Fastapi available to get and put data
References
https://github.com/holladileep/CSYE7245-Spring2021-Labs/tree/main/fast-api
Reviews
There are no reviews yet.