A generic REST API built with FastAPI that works with any CSV dataset. Load any CSV file, and instantly get endpoints to query, filter, sort, and summarize your data — without writing a single line of code for each new dataset.
Built as a portfolio project covering FastAPI, Pandas, Pydantic, REST API design, and generic/reusable backend architecture.
- Works with any CSV dataset — no code changes needed per dataset
- Filter rows by any column with operators:
eq,gte,lte,contains - Sort results by any column in ascending or descending order
- Paginate results with
limitandoffset - Get column names and their data types via a dedicated endpoint
- Get descriptive statistics for all numeric columns
- Auto-generated interactive API documentation at
/docs - Configurable dataset path via environment variable
mini-api/
├── data/
│ └── dataset.csv # Your input CSV file goes here
├── app/
│ ├── __init__.py # Empty — marks app as a Python package
│ ├── loader.py # CSV loading and in-memory DataFrame storage
│ ├── filters.py # Filtering and sorting logic
│ ├── models.py # Pydantic response models
│ └── routes.py # All API endpoint definitions
├── main.py # FastAPI app entry point
├── requirements.txt # Project dependencies
└── README.md
1. Clone the repository
git clone https://github.com/alizahai/mini-api.git
cd mini-api2. Create and activate a virtual environment
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate3. Install dependencies
pip install -r requirements.txt4. Add your CSV file
Place your CSV file inside the data/ folder and name it dataset.csv.
Or set a custom path via environment variable (see Configuration section).
5. Start the server
python main.pyThe API will be live at http://127.0.0.1:8000
By default the API loads data/dataset.csv. To use a different file path,
set the DATASET_PATH environment variable before starting the server:
# Windows
set DATASET_PATH=data/my_custom_file.csv
# macOS/Linux
export DATASET_PATH=data/my_custom_file.csvReturns a welcome message and lists available endpoints.
Returns all column names in the dataset and their data types. Call this first when working with a new dataset to know what columns are available for filtering and sorting.
Example response:
{
"Registration Number": "object",
"CGPA": "float64",
"MT-111": "float64"
}Returns rows from the dataset. Supports filtering, sorting, and pagination.
| Parameter | Type | Default | Description |
|---|---|---|---|
filter_col |
string | None | Column name to filter on |
filter_val |
string | None | Value to filter by |
filter_op |
string | eq |
Filter operator: eq, gte, lte, contains |
sort_by |
string | None | Column name to sort by |
order |
string | asc |
Sort direction: asc or desc |
limit |
integer | 100 |
Number of rows to return (max 1000) |
offset |
integer | 0 |
Number of rows to skip (for pagination) |
Filter operators:
| Operator | Meaning | Works on |
|---|---|---|
eq |
Equal to | Numeric and text columns |
gte |
Greater than or equal to | Numeric columns only |
lte |
Less than or equal to | Numeric columns only |
contains |
Partial text match (case-insensitive) | Text columns only |
Examples:
# Get first 100 rows
GET /data
# Filter by exact numeric value
GET /data?filter_col=CGPA&filter_val=3.5&filter_op=eq
# Filter rows where CGPA is 3.0 or above
GET /data?filter_col=CGPA&filter_val=3.0&filter_op=gte
# Filter by text match
GET /data?filter_col=Registration Number&filter_val=CS&filter_op=contains
# Sort by CGPA descending
GET /data?sort_by=CGPA&order=desc
# Combine filter, sort, and pagination
GET /data?filter_col=CGPA&filter_val=2.5&filter_op=gte&sort_by=CGPA&order=desc&limit=10&offset=0
# Get next page
GET /data?filter_col=CGPA&filter_val=2.5&filter_op=gte&sort_by=CGPA&order=desc&limit=10&offset=10Returns descriptive statistics for all numeric columns in the dataset.
Example response:
[
{
"column": "CGPA",
"mean": 2.85,
"median": 2.79,
"std_dev": 0.52,
"min": 1.2,
"max": 3.94
}
]FastAPI automatically generates interactive API documentation. Once the server is running, open your browser and visit: http://127.0.0.1:8000/docs
You can explore all endpoints, see expected parameters, and test requests directly from the browser without any external tool.
| Library | Purpose |
|---|---|
fastapi |
Web framework for building the API |
uvicorn |
ASGI server that runs the FastAPI application |
pandas |
CSV loading, in-memory data storage, filtering and sorting |
pydantic |
Response model validation and JSON serialization |
Aliza Haider GitHub: alizahai