跳转到主要内容

流式传输CSV内容的方法。

项目描述

stream-csv

Latest Commit
Package version

安装

pip install stream-csv

使用

from fastapi import FastAPI
from starlette.responses import StreamingResponse

from stream_csv.stream import stream_data

app = FastAPI()


@app.get("/")
def get_csv():
    headers = ["type", "color", "size"]
    dict_data = [
        {"type": "potato", "color": "blue", "size": 1},
        {"type": "banana", "color": "red", "size": 2},
        {"type": "potato", "size": 3, "color": "yellow"},
    ]
    return StreamingResponse(
        stream_data(dict_data, headers),
        media_type="text/csv",
        headers={"Content-Disposition": "attachment; filename=data.csv"},
    )

许可证

本项目受MIT许可证条款约束。

由以下支持