This project demonstrates how to create a personalized email writing assistant using FastAPI, OpenAI's API, and FastCRUD. For a full step-by-step tutorial, head to the medium post.
- Python 3.9+: Ensure you have Python 3.9 or a newer version installed.
- Poetry: A dependency manager for Python. Install it with
pip install poetry
. - OpenAI API Key: # and get an API key from OpenAI's website.
- Access to a Terminal (macOS or Linux): Use the terminal for setting up the project and managing dependencies.
Tip for Windows Users: Use Windows Subsystem for Linux (WSL) to follow along with this tutorial.
-
Create a Project Folder:
mkdir email-assistant-api cd email-assistant-api
-
Initialize a Poetry Project:
poetry init
-
Add Dependencies:
poetry add fastapi fastcrud sqlmodel openai aiosqlite greenlet python-jose bcrypt
-
Set Up Environment Variables: Create a
.env
file in theapp
directory with the following content:OPENAI_API_KEY="your_openai_api_key" SECRET_KEY="your_secret_key"
email_assistant_api/
│
├── app/
│ ├── __init__.py
│ ├── main.py # The main application file
│ ├── routes.py # Contains API route definitions and endpoint logic
│ ├── database.py # Database setup and session management
│ ├── models.py # SQLModel models for the application
│ ├── crud.py # CRUD operation implementations using FastCRUD
│ ├── schemas.py # Schemas for request and response models
│ └── .env # Environment variables
│
├── pyproject.toml # Project configuration and dependencies
├── README.md # Provides an overview and documentation
└── .gitignore # Files to be ignored by version control
To start the application, run:
poetry run uvicorn app.main:app --reload
Open a browser and navigate to 127.0.0.1:8000/docs
to access the API documentation.
If you have any questions, want to discuss tech-related topics, or share your feedback, feel free to reach out to me on social media: