Streamlit-FastAPI
Streamlit-FastAPI copied to clipboard
đ Building a Streamlit boilerplate with Streamlit, SQLite DB, and REST API.
Building a Streamlit boilerplate with Streamlit, SQLite DB, and REST API.
đ Project Structure
Self-Hosted
Requirements
- Python version > 3.10 đ
- Pip package manager đĻ
- Streamlit đ
Installation
-
- Clone the repository:
git clone https://github.com/hunterzhang86/Streamlit-FastAPI.git
- Navigate to the project directory:
cd Streamlit-FastAPI
Create a new Python virtual environment, or use conda/mamba to create a new environment:
- Python Virtual Environment:
python -m venv apidemo
source apidemo/bin/activate
- Conda:
conda create -n apidemo python=3.10
conda activate apidemo
- Mamba:
mamba create -n apidemo
mamba activate apidemo
- Install the required dependencies:
pip install -r requirements.txt
Running the Backend
Start the FastAPI backend server:
uvicorn app.main:app --reload
The backend server will be running at http://localhost:8000/docs# đ.
Access the Swagger UI documentation:
Open your browser and visit http://localhost:8000/docs đ. You will find the interactive API documentation powered by Swagger UI. Here, you can explore the available endpoints, test them, and view the response schemas.
(go to Swagger ui at localhost:8000/docs#/)
Fastapi Swagger UI Snip
Running the Streamlit Frontend
Open a new terminal session.
- Navigate to the project directory (if not already there):
cd Streamlit-FastAPI
- Start the Streamlit app:
streamlit run app/app.py
Access the Streamlit app:
Open your browser and visit http://localhost:8501 đ. You will see the Streamlit app interface, where you can interact with the API and visualize the data.
(go to streamlit ui at localhost:8501)
Streamlit App Snip
Deployment
docker build -t streamlit-app . -f streamlit.Dockerfile
docker build -t fastapi-app . -f fastapi.Dockerfile
docker run -d --name streamlit-container -p 8080:8080 streamlit-app
docker run -d --name fastapi-container -p 8000:8000 fastapi-app
Uninstall/Remove Enviorments
deactivate # deactivate the virtual environment
rm -rf /path/to/apidemo # delete the directory
conda env remove --name apidemo
mamba env remove --name apidemo
Contributing
We welcome contributions from the community! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on GitHub.
License
This project is licensed under the AGPLv3 License ÂŠī¸ Feel Free to use.
Sources and Citations
FastAPI: https://fastapi.tiangolo.com/ đ Streamlit: https://streamlit.io/ đ SQLite: https://www.sqlite.org/ đ Feel free to explore the documentation and official websites of the tools used in this project for further information and guidance.