All Projects → Shir0kamii → Flask-CSV

Shir0kamii / Flask-CSV

Licence: MIT license
Easily render CSVs within any flask application

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Flask-CSV

flask-simplemde
Flask-SimpleMDE - a Flask extension for SimpleMDE
Stars: ✭ 23 (+15%)
Mutual labels:  flask-extensions
Flask Apscheduler
Adds APScheduler support to Flask
Stars: ✭ 741 (+3605%)
Mutual labels:  flask-extensions
Flask simplelogin
Simple Login - Login Extension for Flask - maintainer @cuducos
Stars: ✭ 133 (+565%)
Mutual labels:  flask-extensions
mvc-flask
You can use the mvc pattern in your flask application using this extension.
Stars: ✭ 26 (+30%)
Mutual labels:  flask-extensions
Flask Blogging
A Markdown Based Python Blog Engine as a Flask Extension.
Stars: ✭ 609 (+2945%)
Mutual labels:  flask-extensions
Flask Apidoc
Adds ApiDoc support to Flask
Stars: ✭ 49 (+145%)
Mutual labels:  flask-extensions
flask-stupe
💉 a.k.a. « Flask on steroids »
Stars: ✭ 30 (+50%)
Mutual labels:  flask-extensions
Flask Excel
A flask extension using pyexcel to read, manipulate and write data in different excel formats: csv, ods, xls, xlsx and xlsm.
Stars: ✭ 227 (+1035%)
Mutual labels:  flask-extensions
Flask Cors
Cross Origin Resource Sharing ( CORS ) support for Flask
Stars: ✭ 696 (+3380%)
Mutual labels:  flask-extensions
Flask And Redis
Simple as dead support of Redis database for Flask applications
Stars: ✭ 76 (+280%)
Mutual labels:  flask-extensions
Connexion
Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support
Stars: ✭ 3,869 (+19245%)
Mutual labels:  flask-extensions
Flask Googlemaps
Easy way to add GoogleMaps to Flask applications. maintainer: @RiverFount
Stars: ✭ 550 (+2650%)
Mutual labels:  flask-extensions
Flask Htmlmin
Flask html response minifier
Stars: ✭ 66 (+230%)
Mutual labels:  flask-extensions
flask-graphite
📈 Push useful metrics for each request without effort!
Stars: ✭ 15 (-25%)
Mutual labels:  flask-extensions
Flask Ask
Alexa Skills Kit for Python
Stars: ✭ 1,877 (+9285%)
Mutual labels:  flask-extensions
flaskerk
A flask extension for api doc and validation of request&response.
Stars: ✭ 24 (+20%)
Mutual labels:  flask-extensions
Flask Json
Flask-JSON is a Flask extension providing better JSON support.
Stars: ✭ 34 (+70%)
Mutual labels:  flask-extensions
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+14025%)
Mutual labels:  flask-extensions
Flask Jsonrpc
A basic JSON-RPC implementation for your Flask-powered sites
Stars: ✭ 223 (+1015%)
Mutual labels:  flask-extensions
Flask Mobility
A Flask extension to simplify building mobile-friendly sites.
Stars: ✭ 68 (+240%)
Mutual labels:  flask-extensions

Flask-CSV

Easily render CSVs within any flask application

Install

Flask-CSV is packaged and you can use pip to install it:

pip install flask_csv

How to use ?

Flask-CSV has a simple hepler method named send_csv which allows you to send csv files in flask endpoints. It takes an iterable of dict, a filename and a list of fields. The keys of all dict in the iterable must correspond to given fields.

It will return a Response object with filename set and body containing the CSV data.

You will better understand with a short example.

@app.route("/")
def index():
    return send_csv([{"id": 42, "foo": "bar"}, {"id": 91, "foo": "baz"}],
                    "test.csv", ["id", "foo"])

Hitting this endpoint will return:

id,foo
42,bar
91,baz

Passing additionnal parameters

The remaining arguments of send_csv will be passed to send_file. For example, to disable caching, do the following:

send_csv([{"id": 42, "foo": "bar"}, {"id": 91, "foo": "baz"}],
         "test.csv", ["id", "foo"], cache_timeout=0)

You can also pass additionnal parameters to the CSV writer like this:

send_csv([{"foo": 42}, {"bar": "baz"}], "test.csv", ["foo"],
         writer_kwargs={"extrasaction": "ignore"})

In this example, the "bar" key will not raise a ValueError since the writer will be given the parameter extrasaction with the value "ignore".

Change delimiter

You can also change the delimiter with the delimiter option.

send_csv([{"id": 42, "foo": "bar"}, {"id": 91, "foo": "baz"}],
         "test.csv", ["id", "foo"], delimiter=';')

Will result in:

id;foo
42;bar
91;baz

Specifying file encoding

You can also specify the encoding used to send the file, with the encoding option (utf-8 by default).

send_csv([{"id": 42, "foo": "bar"}, {"id": 91, "foo": "baz"}],
         "test.csv", ["id", "foo"], encoding='iso-8859-1')

Use Marshmallow Schemas

You can use Schema from marshmallow by passing it as schema to send_csv. If you want to keep only ids and ensure they are integers, you could do:

class IdSchema(Schema):
    id = fields.Integer()

send_csv([{"id": 42, "foo": "bar"}, {"id": 91, "foo": "baz"}],
         "test.csv", ["id", "foo"], schema=IdSchema())

And that would result in this:

id
42
91

SystemError returned a result with an error set

When using uwsgi for your flask app, it might raise this kind of error on the send_file method. If that were the case, adding the following option to your uwsgi conf should solve it :

wsgi-disable-file-wrapper = true

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].