https://github.com/lenaar/column-operations-api
Flask API with basic calculations
https://github.com/lenaar/column-operations-api
flask-api openapi pydantic python3 sqlalchemy
Last synced: 5 months ago
JSON representation
Flask API with basic calculations
- Host: GitHub
- URL: https://github.com/lenaar/column-operations-api
- Owner: lenaar
- Created: 2025-09-07T16:48:09.000Z (5 months ago)
- Default Branch: feature/rest-api-implementation
- Last Pushed: 2025-09-07T17:58:43.000Z (5 months ago)
- Last Synced: 2025-09-07T19:21:54.146Z (5 months ago)
- Topics: flask-api, openapi, pydantic, python3, sqlalchemy
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Column Operations API
A Flask-based REST API for performing column operations on integer data stored in SQLite.
## ๐ Quick Start
### Option 1: Docker (Recommended)
```bash
# Clone the repository
git clone
cd tacton
# Build and run with Docker Compose
docker-compose up --build
# Or run with Docker directly
docker build -t column-operations-api .
docker run -p 8000:8000 column-operations-api
```
### Option 2: Local Python
#### Prerequisites
- Python 3.11+
- pip
#### Installation
```bash
# Clone the repository
git clone
cd tacton
# Install dependencies
pip install -r requirements.txt
# Run the application
python main.py
```
The API will be available at `http://localhost:8000`
## ๐ API Documentation
Interactive API documentation is available at: `http://localhost:8000/apidocs`
## ๐ API Endpoints
### 1. View All Data
```http
GET /api/v1/data
```
**Response:**
```json
{
"data": [
{
"id": 1,
"column_1": 10,
"column_2": 20,
"column_3": 30,
"column_4": 40,
"column_5": 50
},
{
"id": 2,
"column_1": 15,
"column_2": 25,
"column_3": 35,
"column_4": 45,
"column_5": 55
}
],
"count": 2
}
```
### 2. Sum Two Columns
```http
POST /api/v1/data:sumColumns
```
**Request:**
```json
{
"the_first_col_name": "column_1",
"my_second_colname": "column_5"
}
```
**Response:**
```json
{
"result": [60, 70]
}
```
### 3. Calculate Formula
```http
POST /api/v1/data:calculateFormula
```
**Request:**
```json
{
"myFormula": "column_1 + column_2 * column_3"
}
```
**Response:**
```json
{
"result": [610, 890]
}
```
## ๐งช Testing
### Docker Testing
```bash
# Run tests in Docker container
docker-compose run test
# Or build and run tests only
docker build -t column-operations-api .
docker run --rm column-operations-api python run_tests.py
```
### Local Testing
```bash
# Run all tests
python run_tests.py
# Or using pytest directly
pytest tests/ -v
```
## ๐๏ธ Architecture
```
โโโ api/ # API routes and schemas
โโโ config/ # Configuration and environment
โโโ db/ # Database models and initialization
โโโ services/ # Business logic
โโโ tests/ # Test suite
โโโ docs/ # API documentation
```
## โ๏ธ Configuration
Copy `env.sample` to `.env` and customize:
```bash
cp env.sample .env
```
Available environment variables:
- `DATABASE_URL`: SQLite database path
- `TABLE_NAME`: Database table name
- `LOG_LEVEL`: Logging level
- `API_HOST`: API host (default: localhost)
- `API_PORT`: API port (default: 8000)
## ๐ง Development
### Adding New Columns
1. Update `config/columns.py`:
```python
COLUMN_NAMES = ['column_1', 'column_2', 'column_3', 'column_4', 'column_5', 'column_6']
```
2. Update Swagger documentation manually in `docs/openapi/v1.yaml`
3. Update database schema (migration needed)
### Code Quality
- **Type hints** throughout the codebase
- **Pydantic models** for validation
- **Comprehensive tests** with 30+ test cases
- **Error handling** with proper HTTP status codes
## ๐ Features
- โ
**RESTful API** with Flask
- โ
**SQLite database** with automatic initialization
- โ
**Pydantic validation** for request/response
- โ
**Swagger documentation** with OpenAPI 2.0
- โ
**Comprehensive testing** with pytest
- โ
**Error handling** with detailed error messages
- โ
**Environment configuration** support
- โ
**API versioning** (`/api/v1/`)
- โ
**Modular architecture** with separation of concerns
- โ
**Docker support** with automated testing
- โ
**Health checks** for monitoring
## ๐ง Future Enhancements
See [ENHANCEMENTS.md](ENHANCEMENTS.md) for planned improvements.
## ๐ License
[Add your license here]