Skip to content

FastAPI-based API that delivers real-time currency conversion rates

Notifications You must be signed in to change notification settings

d2avids/currency_rates

Repository files navigation

Currency Rates

Python 3.12 FastAPI Docker Postgres coverage tests deploy

Description

Currency Rates API is a modern, high-performance API built with FastAPI that delivers real-time currency conversion rates for specific dates. The API first attempts to retrieve conversion rates from a local database. If the requested data is not found, it automatically fetches the required information from an external resource.

Notes & limitations:

  • Rate 0.0 is returned if there is no data for a given data and currency pair.
  • Conversion rates represent the average rate value for a given date.
  • The most recent rate available corresponds to the previous day.

Docs

Request example:

curl -X 'POST' \
  'https://currency-rates.servehttp.com/v1/currency-rates/get-rate' \
  -H 'accept: application/json' \
  -H 'X-API-Key: <key>' \
  -H 'Content-Type: application/json' \
  -d '{
  "fromCur": "USD",
  "toCur": "EUR",
  "date": "2019-02-01"
}'

Response example:

{
  "from_cur": "USD",
  "to_cur": "EUR",
  "date": "2019-02-01",
  "rate": "0.87161482"
}

Tech stack:

  • Python 3.12
  • FastAPI - a high-performance web framework for building APIs with autogenerated OpenAPI documentation.
  • PostgreSQL - an open-source relational database.
  • SQLAlchemy - a Python ORM and SQL toolkit for interacting with databases using an object-oriented approach.
  • Alembic - a database migration tool for managing schema changes in SQLAlchemy-based projects.
  • Pydantic - a data validation and settings management library that ensures type safety in FastAPI applications.
  • Uvicorn - a fast ASGI server for running FastAPI applications in production.
  • Pytest - a testing package, used alongside testcontainers for containerized database testing.
  • CI/CD - Continuous Integration and Continuous Delivery via Github Actions workflow

Installation

1. Install poetry dependencies:

poetry install

2. Activate virtual environment:

poetry shell

3. Set environment variables in .env file based on .env_example:

cp .env_example .env

4. Run the service locally:

cd src && python main.py

or in Docker containers:

docker compose up --build --force-recreate -d

Author

About

FastAPI-based API that delivers real-time currency conversion rates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published