This is a sample FastAPI application that demonstrates how to create a FastAPI web service. This README provides step-by-step instructions on how to set up and run the application.
- Python 3.x (Download Python)
- Docker (Get Docker)
Clone this repository to your local machine using Git:
git clone https://github.com/yourusername/fastapi-sample-app.git
cd fastapi-sample-app
You can create a Python virtual environment to isolate the project's dependencies. If you prefer not to use a virtual environment, you can skip this step.
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
On Windows:
venv\Scripts\activate
On macOS and Linux:
source venv/bin/activate
Install the required Python packages using pip:
pip install -r requirements.txt
Before running the FastAPI app, you'll need to set up the necessary environment variables by creating a .env
file in the project directory. You can use the provided example.env
as a template. Copy and rename it to .env
, then edit it to include your specific configuration.
cp example.env .env
Edit the .env
file to include the required values for your application.
Example .env
file:
# Database configuration
DATABASE_URL=sqlite:///./app.db
# SMTP server configuration for sending emails
SMTP_SERVER=smtp.example.com
SMTP_PORT=587
SMTP_USERNAME=your_username
SMTP_PASSWORD=your_password
# FastAPI app settings
FASTAPI_ENV=development
DEBUG=True
Make sure to replace the example values with your actual configuration settings.
You can run the app in a Docker container. Ensure that Docker is installed and running on your machine.
# Build the Docker image
docker build -t fastapi-app .
# Run the Docker container
docker run -d -p 8000:8000 fastapi-app
The FastAPI app will be accessible at http://localhost:8000.
Alternatively, you can run the app directly with Python:
python main.py
The FastAPI app will be accessible at http://localhost:8000.
You can interact with the FastAPI app by visiting http://localhost:8000 in your web browser or using API testing tools like Swagger UI or ReDoc. The app provides various endpoints that you can explore and test.
If you'd like to contribute to this project, please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.
This Markdown README provides detailed instructions for setting up and running your FastAPI application, including creating a `.env` file with the necessary configuration data.