A FastAPI-based REST API server for CSV files
Project description
CSV Server
CSV Server is a robust Python library and CLI tool that instantly turns your CSV files into a fully-featured REST API. Inspired by json-server, it is designed for rapid prototyping, data exploration, and lightweight data services—no database required.
Features
- 🚀 Instant REST API: Serve any folder of CSV files as RESTful endpoints.
- 🔒 Read-Only by Default: Safe, non-destructive access; enable writes as needed.
- 🆔 Auto-ID Management: Automatic primary key synthesis and incrementing.
- 🔎 Advanced Querying: Search, filter, sort, and paginate results.
- 🛡️ Safe Writes: Atomic file operations with file locking.
- 📖 Interactive API Docs: Swagger/OpenAPI documentation at
/docs. - ⚡ CLI & Python API: Use as a command-line tool or integrate as a library.
- 🧪 Comprehensive Testing: Includes pytest-based test suite.
- 🐍 Modern Python: Type hints, linting, and optional pandas support for large datasets.
Installation
pip install csv-server
Quick Start
CLI Usage
csv-server serve ./data --port 8000
- Instantly exposes all CSV files in
./dataas REST endpoints. - Visit http://localhost:8000/docs for interactive API documentation.
Python Library Usage
from csv_server import serve_csv_directory
serve_csv_directory("./data", port=8000, readonly=True)
Directory Structure
csv_server/
__init__.py
cli.py
app.py
resources.py
config.py
storage/
base.py
csv_store.py
sqlite_store.py
query.py
utils_csv_ids.py
version.py
tests/
examples/
data/users.csv
data/orders.csv
config.yaml
pyproject.toml
README.md
LICENSE
API Overview
For each CSV file (e.g., users.csv), the following endpoints are generated:
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
List rows with query support |
| GET | /users/{id} |
Fetch a single row by ID |
| POST | /users |
Add a new row (if not read-only) |
| PUT | /users/{id} |
Replace a row (if not read-only) |
| PATCH | /users/{id} |
Update a row (if not read-only) |
| DELETE | /users/{id} |
Delete a row (if not read-only) |
| GET | /users/schema |
Get inferred column schema |
Query Parameters
q: Full-text searchfilter: Field-based filtering (e.g.,filter=age:gt:30)sort: Sorting (e.g.,sort=name:asc)limit&offset: Pagination
Configuration
You can use a YAML config file for advanced setup:
resources:
users:
file: "users.csv"
primary_key: "id"
readonly: false
orders:
file: "orders.csv"
primary_key: "order_id"
readonly: true
Run with:
csv-server serve ./data --config config.yaml
Example Data
Sample CSV files are provided in examples/data/ for demonstration and testing.
Testing
Run the test suite with:
pytest
Roadmap
- SQLite backend for large datasets
- Hot reload for CSV file changes
- Resource relationships (foreign keys)
- Docker image for easy deployment
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- Built with FastAPI
- Inspired by json-server
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csv_server-0.1.2.tar.gz.
File metadata
- Download URL: csv_server-0.1.2.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00493a49bd00ec76abfa8b67b94a5ba6cd4e87f6974fd5f65500d08138d1d40a
|
|
| MD5 |
54808009c21179d3a8021071e9cb109f
|
|
| BLAKE2b-256 |
e220170f049dcdb34058746566b4cd89576b13f75a908387e5b0bed22412dbed
|
File details
Details for the file csv_server-0.1.2-py3-none-any.whl.
File metadata
- Download URL: csv_server-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b117fed5ecefbeb16048c88d84f46203aa815d48f72c14ba725488c4ab742a69
|
|
| MD5 |
a36b9ebf278e8370f25ca95d60ab450a
|
|
| BLAKE2b-256 |
bd59e016cf4ee2b622127522eb170748c3d1f4c48be3afab41e2bf1c3c88b614
|