Flask-Cors


NameFlask-Cors JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttps://github.com/corydolphin/flask-cors
SummaryA Flask extension adding a decorator for CORS support
upload_time2023-06-26 05:38:46
maintainer
docs_urlNone
authorCory Dolphin
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements Flask
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Flask-CORS
==========

|Build Status| |Latest Version| |Supported Python versions|
|License|

A Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible.

This package has a simple philosophy: when you want to enable CORS, you wish to enable it for all use cases on a domain. 
This means no mucking around with different allowed headers, methods, etc. 

By default, submission of cookies across domains is disabled due to the security implications. 
Please see the documentation for how to enable credential'ed requests, and please make sure you add some sort of `CSRF <http://en.wikipedia.org/wiki/Cross-site_request_forgery>`__ protection before doing so!

Installation
------------

Install the extension with using pip, or easy\_install.

.. code:: bash

    $ pip install -U flask-cors

Usage
-----

This package exposes a Flask extension which by default enables CORS support on all routes, for all origins and methods. 
It allows parameterization of all CORS headers on a per-resource level. 
The package also contains a decorator, for those who prefer this approach.

Simple Usage
~~~~~~~~~~~~

In the simplest case, initialize the Flask-Cors extension with default arguments in order to allow CORS for all domains on all routes. 
See the full list of options in the `documentation <https://flask-cors.corydolphin.com/en/latest/api.html#extension>`__.

.. code:: python


    from flask import Flask
    from flask_cors import CORS

    app = Flask(__name__)
    CORS(app)

    @app.route("/")
    def helloWorld():
      return "Hello, cross-origin-world!"

Resource specific CORS
^^^^^^^^^^^^^^^^^^^^^^

Alternatively, you can specify CORS options on a resource and origin level of granularity by passing a dictionary as the `resources` option, mapping paths to a set of options. 
See the full list of options in the `documentation <https://flask-cors.corydolphin.com/en/latest/api.html#extension>`__.

.. code:: python

    app = Flask(__name__)
    cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

    @app.route("/api/v1/users")
    def list_users():
      return "user example"

Route specific CORS via decorator
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This extension also exposes a simple decorator to decorate flask routes with. 
Simply add ``@cross_origin()`` below a call to Flask's ``@app.route(..)`` to allow CORS on a given route. 
See the full list of options in the `decorator documentation <https://flask-cors.corydolphin.com/en/latest/api.html#decorator>`__.

.. code:: python

    @app.route("/")
    @cross_origin()
    def helloWorld():
      return "Hello, cross-origin-world!"

Documentation
-------------

For a full list of options, please see the full `documentation <https://flask-cors.corydolphin.com/en/latest/api.html>`__

Troubleshooting
---------------

If things aren't working as you expect, enable logging to help understand what is going on under the hood, and why.

.. code:: python

    logging.getLogger('flask_cors').level = logging.DEBUG


Tests
-----

A simple set of tests is included in ``test/``. 
To run, install nose, and simply invoke ``nosetests`` or ``python setup.py test`` to exercise the tests.

If nosetests does not work for you, due to it no longer working with newer python versions.
You can use pytest to run the tests instead.

Contributing
------------

Questions, comments or improvements? 
Please create an issue on `Github <https://github.com/corydolphin/flask-cors>`__, tweet at `@corydolphin <https://twitter.com/corydolphin>`__ or send me an email. 
I do my best to include every contribution proposed in any way that I can.

Credits
-------

This Flask extension is based upon the `Decorator for the HTTP Access Control <https://web.archive.org/web/20190128010149/http://flask.pocoo.org/snippets/56/>`__ written by Armin Ronacher.

.. |Build Status| image:: https://api.travis-ci.org/corydolphin/flask-cors.svg?branch=master
   :target: https://travis-ci.org/corydolphin/flask-cors
.. |Latest Version| image:: https://img.shields.io/pypi/v/Flask-Cors.svg
   :target: https://pypi.python.org/pypi/Flask-Cors/
.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/Flask-Cors.svg
   :target: https://img.shields.io/pypi/pyversions/Flask-Cors.svg
.. |License| image:: http://img.shields.io/:license-mit-blue.svg
   :target: https://pypi.python.org/pypi/Flask-Cors/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/corydolphin/flask-cors",
    "name": "Flask-Cors",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Cory Dolphin",
    "author_email": "corydolphin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c8/b0/bd7130837a921497520f62023c7ba754e441dcedf959a43e6d1fd86e5451/Flask-Cors-4.0.0.tar.gz",
    "platform": "any",
    "description": "Flask-CORS\n==========\n\n|Build Status| |Latest Version| |Supported Python versions|\n|License|\n\nA Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible.\n\nThis package has a simple philosophy: when you want to enable CORS, you wish to enable it for all use cases on a domain. \nThis means no mucking around with different allowed headers, methods, etc. \n\nBy default, submission of cookies across domains is disabled due to the security implications. \nPlease see the documentation for how to enable credential'ed requests, and please make sure you add some sort of `CSRF <http://en.wikipedia.org/wiki/Cross-site_request_forgery>`__ protection before doing so!\n\nInstallation\n------------\n\nInstall the extension with using pip, or easy\\_install.\n\n.. code:: bash\n\n    $ pip install -U flask-cors\n\nUsage\n-----\n\nThis package exposes a Flask extension which by default enables CORS support on all routes, for all origins and methods. \nIt allows parameterization of all CORS headers on a per-resource level. \nThe package also contains a decorator, for those who prefer this approach.\n\nSimple Usage\n~~~~~~~~~~~~\n\nIn the simplest case, initialize the Flask-Cors extension with default arguments in order to allow CORS for all domains on all routes. \nSee the full list of options in the `documentation <https://flask-cors.corydolphin.com/en/latest/api.html#extension>`__.\n\n.. code:: python\n\n\n    from flask import Flask\n    from flask_cors import CORS\n\n    app = Flask(__name__)\n    CORS(app)\n\n    @app.route(\"/\")\n    def helloWorld():\n      return \"Hello, cross-origin-world!\"\n\nResource specific CORS\n^^^^^^^^^^^^^^^^^^^^^^\n\nAlternatively, you can specify CORS options on a resource and origin level of granularity by passing a dictionary as the `resources` option, mapping paths to a set of options. \nSee the full list of options in the `documentation <https://flask-cors.corydolphin.com/en/latest/api.html#extension>`__.\n\n.. code:: python\n\n    app = Flask(__name__)\n    cors = CORS(app, resources={r\"/api/*\": {\"origins\": \"*\"}})\n\n    @app.route(\"/api/v1/users\")\n    def list_users():\n      return \"user example\"\n\nRoute specific CORS via decorator\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis extension also exposes a simple decorator to decorate flask routes with. \nSimply add ``@cross_origin()`` below a call to Flask's ``@app.route(..)`` to allow CORS on a given route. \nSee the full list of options in the `decorator documentation <https://flask-cors.corydolphin.com/en/latest/api.html#decorator>`__.\n\n.. code:: python\n\n    @app.route(\"/\")\n    @cross_origin()\n    def helloWorld():\n      return \"Hello, cross-origin-world!\"\n\nDocumentation\n-------------\n\nFor a full list of options, please see the full `documentation <https://flask-cors.corydolphin.com/en/latest/api.html>`__\n\nTroubleshooting\n---------------\n\nIf things aren't working as you expect, enable logging to help understand what is going on under the hood, and why.\n\n.. code:: python\n\n    logging.getLogger('flask_cors').level = logging.DEBUG\n\n\nTests\n-----\n\nA simple set of tests is included in ``test/``. \nTo run, install nose, and simply invoke ``nosetests`` or ``python setup.py test`` to exercise the tests.\n\nIf nosetests does not work for you, due to it no longer working with newer python versions.\nYou can use pytest to run the tests instead.\n\nContributing\n------------\n\nQuestions, comments or improvements? \nPlease create an issue on `Github <https://github.com/corydolphin/flask-cors>`__, tweet at `@corydolphin <https://twitter.com/corydolphin>`__ or send me an email. \nI do my best to include every contribution proposed in any way that I can.\n\nCredits\n-------\n\nThis Flask extension is based upon the `Decorator for the HTTP Access Control <https://web.archive.org/web/20190128010149/http://flask.pocoo.org/snippets/56/>`__ written by Armin Ronacher.\n\n.. |Build Status| image:: https://api.travis-ci.org/corydolphin/flask-cors.svg?branch=master\n   :target: https://travis-ci.org/corydolphin/flask-cors\n.. |Latest Version| image:: https://img.shields.io/pypi/v/Flask-Cors.svg\n   :target: https://pypi.python.org/pypi/Flask-Cors/\n.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/Flask-Cors.svg\n   :target: https://img.shields.io/pypi/pyversions/Flask-Cors.svg\n.. |License| image:: http://img.shields.io/:license-mit-blue.svg\n   :target: https://pypi.python.org/pypi/Flask-Cors/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Flask extension adding a decorator for CORS support",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "https://github.com/corydolphin/flask-cors"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10691e6cfb87117568a9de088c32d6258219e9d1ff7c131abf74249ef2031279",
                "md5": "29e4bef47f239d9dc302fe55d7780d57",
                "sha256": "bc3492bfd6368d27cfe79c7821df5a8a319e1a6d5eab277a3794be19bdc51783"
            },
            "downloads": -1,
            "filename": "Flask_Cors-4.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "29e4bef47f239d9dc302fe55d7780d57",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14273,
            "upload_time": "2023-06-26T05:38:44",
            "upload_time_iso_8601": "2023-06-26T05:38:44.733464Z",
            "url": "https://files.pythonhosted.org/packages/10/69/1e6cfb87117568a9de088c32d6258219e9d1ff7c131abf74249ef2031279/Flask_Cors-4.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8b0bd7130837a921497520f62023c7ba754e441dcedf959a43e6d1fd86e5451",
                "md5": "0ccfa375e744200243d85719b38cdbc6",
                "sha256": "f268522fcb2f73e2ecdde1ef45e2fd5c71cc48fe03cffb4b441c6d1b40684eb0"
            },
            "downloads": -1,
            "filename": "Flask-Cors-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0ccfa375e744200243d85719b38cdbc6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29934,
            "upload_time": "2023-06-26T05:38:46",
            "upload_time_iso_8601": "2023-06-26T05:38:46.364980Z",
            "url": "https://files.pythonhosted.org/packages/c8/b0/bd7130837a921497520f62023c7ba754e441dcedf959a43e6d1fd86e5451/Flask-Cors-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-26 05:38:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "corydolphin",
    "github_project": "flask-cors",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "Flask",
            "specs": [
                [
                    ">=",
                    "0.9"
                ]
            ]
        }
    ],
    "lcname": "flask-cors"
}
        
Elapsed time: 0.27404s