Skip to main content

Create APIs from CSV files within seconds, using fastapi

Project description

fastapi-csv

🚧 Create APIs from CSV files within seconds, using fastapi

This is a Python package to create APIs from CSV files, using a lightweight & fully customizable wrapper around fastapi. Endpoints and query parameters are auto-generated based on the column names and data types in the CSV file. Its data is written to a (temporary) sqlite database, so the API is blazing fast even for huge files.

Installation

pip install git+https://github.com/jrieke/fastapi-csv.git

Requires Python 3.6+

How to use it

1. From the command line

There's a simple CSV file in this repo for testing (people.csv). To start an API for it, run one of:

# from file
fastapi-csv people.csv

# directly from URL
fastapi-csv https://raw.githubusercontent.com/jrieke/fastapi-csv/main/people.csv

Either command should start a fastapi instance, which has auto-generated endpoints and query parameters based on the CSV file. Here, the API has an endpoint /people (same name as the file), which can be queried using the CSV's column names, e.g. you can do:

  • /people?first_name=Rachel
  • /people?last_name=Johnson&age=48

Additionally, fastapi-csv creates some convenience query parameters for specific data types, e.g.

  • /people&age_greaterThan=18 (for int/float)
  • /people&age_lessThanEqual=18 (for int/float)
  • /people&first_name_contains=ach (for string, watch out: this one is case sensitive!)

Check out the API docs for more information and an interactive demo, they should be at http://127.0.0.1:8000/docs

2. From Python

Create a file my_file.py:

from fastapi_csv import FastAPI_CSV

app = FastAPI_CSV("people.csv")

Start from terminal just like a normal fastapi app:

uvicorn my_file:app

Extending the API

The cool thing: FastAPI_CSV is just a wrapper around FastAPI. Therefore, you can do all the stuff you can do with a normal fastapi instance, e.g. add a new endpoint:

# Add a new endpoint, just like in normal fastapi
@app.get("/hello")
def hello(self):
    return {"Hello:", "World"}

In the future, you will also be able to easily modify existing endpoints that were generated from the CSV file.

Updating the data

If your CSV file changes, you can update the API data with:

app.update_database()

Note that this will only update the data, not the API endpoints or query parameters. To do that, you need to create a new FastAPI_CSV instance or re-start uvicorn.

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

fastapi-csv-0.0.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

fastapi_csv-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-csv-0.0.1.tar.gz.

File metadata

  • Download URL: fastapi-csv-0.0.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.6

File hashes

Hashes for fastapi-csv-0.0.1.tar.gz
Algorithm Hash digest
SHA256 10d431e8b4ad997d72fade57afd9be2385331d1f319b8a28ff33936894e6aa7f
MD5 53b248125019750a84e773b0b8524ca1
BLAKE2b-256 7685b53d3a9981b264ed79427a90584fb9b794014107e8c3ac488b69e1287758

See more details on using hashes here.

File details

Details for the file fastapi_csv-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_csv-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.6

File hashes

Hashes for fastapi_csv-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5eba09887971e27adcd302a37a6ccb0a6fc23e8321622e2c59b433ab9d25e820
MD5 cbfdf0de69517ddcbf0bfd7bc3220de0
BLAKE2b-256 5b4b463c78d48560c09447e99feb3b4455d9360a1118cc50a6c9e5cb7a014098

See more details on using hashes here.

Supported by

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