Skip to main content

A FastAPI-based REST API server for CSV files

Project description

CSV Server

PyPI version License: MIT CI

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 ./data as 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 search
  • filter: 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv_server-0.1.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv_server-0.1.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file csv_server-0.1.1.tar.gz.

File metadata

  • Download URL: csv_server-0.1.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for csv_server-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9fdb943f9420c93155d90bb407e9d3532fb2a0bf8f500953382e1e4d54e1ad9
MD5 8a22a06be6f9afd0f4a4b440f20c6bcd
BLAKE2b-256 66a6ead62aca95de1a8d928ac3e84e14cbf0085e977243bddf206e8c832a958e

See more details on using hashes here.

File details

Details for the file csv_server-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: csv_server-0.1.1-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

Hashes for csv_server-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aadaca2f6e407479d21e1530907a7fff3c4c93cbc1aba03f459242fdd36cecb7
MD5 b43a243c34bf916f5fa313e617a439c6
BLAKE2b-256 b4ab3e1a42ee6cf49f4b930a493637feac0ac3b224f9d86d5e8ded56cb3ebdca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page