Skip to content

Repository files navigation

SmolMathWebService

A REST service providing math operations: power, Fibonacci, factorial.

Getting Started

Prerequisites

  • Python 3.10+
  • PostgreSQL 13+
  • Docker & Docker Compose (optional, for containerized setup)

Installation

  1. Clone the repo:
    git clone https://github.com/vela-paul/math.git
    cd SmolMathWebService
  2. Create and activate a virtual environment, then install dependencies:
    py -3-m venv .venv; .\.venv\Scripts\Activate; pip install -r requirements.txt

Database Setup & Migrations

  1. Start PostgreSQL and create the database/user:
    CREATEDATABASEmath_ops;
    CREATEUSERmathuser WITH PASSWORD 'mathpass';
    GRANT ALL PRIVILEGES ON DATABASE math_ops TO mathuser;
  2. Run Alembic migrations:
    py -m alembic upgrade head

Running Locally

Start the FastAPI server:

uvicorn src.app:app --reload --host 127.0.0.1--port 8000

API Endpoints

All endpoints accept JSON and return a MathResponse:

POST /pow

Request: { "base": 2, "exponent": 3 }Response: {"operation": "pow",
"parameters": { "base": 2, "exponent": 3 },
"result": "8"}

POST /fib

Request: { "n": 5 }Response: {"operation": "fib",
"parameters": { "n": 5 },
"result": "5"}

POST /factorial

Request: { "n": 4 }Response: {"operation": "factorial",
"parameters": { "n": 4 },
"result": "24"}

Running Tests

pytest

Docker & Docker Compose

A Dockerfile and docker-compose.yml are provided for local development:

docker-compose up --build

Services:

  • db: PostgreSQL 13
  • web: FastAPI app on port 8000

Data is persisted in a Docker volume db_data.

#easter-egg somewhere in the code

About

A small maths helper written in python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages