A REST service providing math operations: power, Fibonacci, factorial.
- Python 3.10+
- PostgreSQL 13+
- Docker & Docker Compose (optional, for containerized setup)
- Clone the repo:
git clone https://github.com/vela-paul/math.git cd SmolMathWebService
- Create and activate a virtual environment, then install dependencies:
py -3 -m venv .venv; .\.venv\Scripts\Activate; pip install -r requirements.txt
- Start PostgreSQL and create the database/user:
CREATE DATABASE math_ops; CREATE USER mathuser WITH PASSWORD 'mathpass'; GRANT ALL PRIVILEGES ON DATABASE math_ops TO mathuser;
- Run Alembic migrations:
py -m alembic upgrade head
Start the FastAPI server:
uvicorn src.app:app --reload --host 127.0.0.1 --port 8000All endpoints accept JSON and return a MathResponse:
Request: { "base": 2, "exponent": 3 }
Response: {
"operation": "pow",
"parameters": { "base": 2, "exponent": 3 },
"result": "8"
}Request: { "n": 5 }
Response: {
"operation": "fib",
"parameters": { "n": 5 },
"result": "5"
}Request: { "n": 4 }
Response: {
"operation": "factorial",
"parameters": { "n": 4 },
"result": "24"
}pytestA Dockerfile and docker-compose.yml are provided for local development:
docker-compose up --buildServices:
- db: PostgreSQL 13
- web: FastAPI app on port 8000
Data is persisted in a Docker volume db_data.
MIT