Prerequisites
Before you begin, ensure you have the following installed:- Python 3.12 or higher
- Docker & Docker Compose (for running PostgreSQL and Redis)
- Git for version control
Fixer.io
Free tier available
OpenExchangeRates
Free tier available
CurrencyAPI
Free tier available
Clone the repository
Start by cloning the repository and navigating to the project directory:Set up Python environment
Install dependencies
Install all required Python packages:Key dependencies include:
fastapi[all]- Web framework with ASGI serversqlalchemy&asyncpg- Async database ORMalembic- Database migrationsredis- Redis client for cachinghttpx- Async HTTP client for providerspytest&pytest-asyncio- Testing framework
Start infrastructure services
The API requires PostgreSQL and Redis to run. You can start them using Docker Compose:- PostgreSQL on port
5432 - Redis on port
6379
Run database migrations
The project uses Alembic for managing database schema. Apply all migrations to create the necessary tables:supported_currencies- List of all supported currency codesrate_history- Historical exchange rate data
Common migration commands
Start the development server
Run the API server with auto-reload enabled:- API Base:
http://localhost:8000 - Interactive Docs:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
On first startup, the API will automatically fetch supported currencies from all three providers and store them in the database and cache. This process is called “bootstrapping” and happens during the application lifespan startup.
Verify your setup
Test the API with a simple conversion request:Configuration details
All configuration is managed throughconfig/settings.py using pydantic-settings. The Settings class reads values from environment variables or the .env file:
config/settings.py
get_settings() function is decorated with @lru_cache, ensuring settings are loaded only once per process.
Development without Docker
If you prefer not to use Docker, you can install PostgreSQL and Redis locally:- macOS
- Ubuntu/Debian
- Windows
.env file with the appropriate connection strings for your local installations.
Common pitfalls
Bootstrap failure - providers unreachable
Bootstrap failure - providers unreachable
If providers are unreachable at startup (e.g., bad API keys), the app will raise
ProviderError and exit.Solution: Verify your API keys in the .env file are correct and that you have an active internet connection.Database connection errors
Database connection errors
If you see connection errors, ensure:
- PostgreSQL is running:
docker-compose ps - The
DATABASE_URLin.envmatches your setup - The database exists:
createdb currency_converter
Redis connection refused
Redis connection refused
Ensure Redis is running and accessible:
Import errors after installing dependencies
Import errors after installing dependencies
Make sure your virtual environment is activated:
Next steps
Testing guide
Learn how to run tests and write new test cases
Adding providers
Add support for new exchange rate providers
Architecture
Understand the system architecture
API reference
Explore the API endpoints
