Flask-Cors


NameFlask-Cors JSON
Version 5.0.0 PyPI version JSON
download
home_pagehttps://github.com/corydolphin/flask-cors
SummaryA Flask extension adding a decorator for CORS support
upload_time2024-08-31 00:44:26
maintainerNone
docs_urlNone
authorCory Dolphin
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
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://github.com/corydolphin/flask-cors/actions/workflows/unittests.yaml/badge.svg
   :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": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Cory Dolphin",
    "author_email": "corydolphin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4f/d0/d9e52b154e603b0faccc0b7c2ad36a764d8755ef4036acbf1582a67fb86b/flask_cors-5.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://github.com/corydolphin/flask-cors/actions/workflows/unittests.yaml/badge.svg\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": "5.0.0",
    "project_urls": {
        "Homepage": "https://github.com/corydolphin/flask-cors"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56071afa0514c876282bebc1c9aee83c6bb98fe6415cf57b88d9b06e7e29bf9c",
                "md5": "66199b77d52f670fed222a27689fe68d",
                "sha256": "b9e307d082a9261c100d8fb0ba909eec6a228ed1b60a8315fd85f783d61910bc"
            },
            "downloads": -1,
            "filename": "Flask_Cors-5.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66199b77d52f670fed222a27689fe68d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14463,
            "upload_time": "2024-08-31T00:44:24",
            "upload_time_iso_8601": "2024-08-31T00:44:24.394708Z",
            "url": "https://files.pythonhosted.org/packages/56/07/1afa0514c876282bebc1c9aee83c6bb98fe6415cf57b88d9b06e7e29bf9c/Flask_Cors-5.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4fd0d9e52b154e603b0faccc0b7c2ad36a764d8755ef4036acbf1582a67fb86b",
                "md5": "a6e8202cc008ef6f70ce75a7ae7f8d9d",
                "sha256": "5aadb4b950c4e93745034594d9f3ea6591f734bb3662e16e255ffbf5e89c88ef"
            },
            "downloads": -1,
            "filename": "flask_cors-5.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a6e8202cc008ef6f70ce75a7ae7f8d9d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30954,
            "upload_time": "2024-08-31T00:44:26",
            "upload_time_iso_8601": "2024-08-31T00:44:26.395654Z",
            "url": "https://files.pythonhosted.org/packages/4f/d0/d9e52b154e603b0faccc0b7c2ad36a764d8755ef4036acbf1582a67fb86b/flask_cors-5.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-31 00:44:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "corydolphin",
    "github_project": "flask-cors",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "flask-cors"
}
        
Elapsed time: 0.86545s