skillfed

Sanic-Cors

A Sanic extension adding a decorator for CORS support. Based on flask-cors by Cory Dolphin.

sanic-cors v2.2.0 311.1K downloads/30d#7,740 on PyPI162
Permissive license MIT Abandoned released

What it is and what it does

Sanic-CORS is a Sanic web framework extension that handles Cross-Origin Resource Sharing (CORS) headers and preflight requests, allowing your Sanic application to safely serve cross-origin AJAX requests. It is based on flask-cors and provides both a global initialization approach and per-route decorator patterns for fine-grained control over which origins, methods, and headers are allowed.

The extension operates with a permissive default philosophy: when enabled globally, it allows CORS for all origins and methods on all routes unless you explicitly configure restrictions. It includes an automatic_options feature to handle OPTIONS preflight responses without manual route configuration. The package depends on sanic and packaging, and supports Python 3.7 through 3.10. However, the project has been abandoned since early 2023, with the last release in October 2022, and carries two known security vulnerabilities.

Use it for:

  • Enable CORS globally on a Sanic API to allow browser-based clients from any origin to make cross-origin requests.
  • Configure CORS selectively for specific API routes using the @cross_origin decorator to restrict which origins can access sensitive endpoints.
  • Set up resource-level CORS policies by mapping URL patterns to specific allowed origins, methods, and headers in the resources parameter.
  • Automatically handle CORS preflight OPTIONS requests without manually implementing OPTIONS handlers on each route.
  • Integrate CORS support into a Sanic application managed by Sanic-Ext using the plugin system.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Sanic-CORS is a Sanic extension that adds Cross-Origin Resource Sharing (CORS) support to Sanic web applications, enabling cross-origin AJAX requests with configurable per-route or global policies.

No. While Sanic-CORS provides straightforward CORS support with low install friction and permissive licensing, the project is abandoned (last commit January 2023) and carries two known security vulnerabilities. For new projects, consider alternatives or implement CORS handling directly. For existing projects already using it, evaluate whether upgrading to a maintained solution is feasible.

Install

sanic-cors on PyPI

pip

pip install sanic-cors

uv

uv add sanic-cors

poetry

poetry add sanic-cors

Installing Sanic-Cors

Before you install

Installation is straightforward with low friction. The package depends only on sanic and packaging. However, maintenance is a concern: the last release was October 2022 and the repository shows no commits since January 2023, indicating the project is abandoned despite the repository not being formally archived.

License in practice

MIT license is permissive and poses no restrictions on use, modification, or distribution in commercial or private projects.

Quickstart

pip install sanic-cors

from sanic import Sanic
from sanic.response import text
from sanic_cors import CORS

app = Sanic(__name__)
CORS(app)

@app.route("/", methods=['GET', 'OPTIONS'])
def hello_world(request):
    return text("Hello, cross-origin-world!")

Sanic-CORS requires routes to explicitly include 'OPTIONS' in the methods list to handle CORS preflight requests, unless automatic_options is enabled.

Verify before relying

  • Whether the two known vulnerabilities (GHSA-94jw-hqvj-vw74, PYSEC-2026-3539) have been patched or remain unresolved in version 2.2.0.
  • Compatibility status with current Sanic versions beyond the notices provided for v21.9, v21.12, and v22.9.
  • Whether the package will receive security updates or bug fixes despite abandonment status.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 2 — sanic, packaging
Maintenance abandoned — 1,407 days since the last release
Last repo commit
First released
Downloads 311,128/month — #7,740 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities 2 — GHSA-94jw-hqvj-vw74, PYSEC-2026-3539

Evidence: Sanic_Cors-2.2.0-py2.py3-none-any.whl

Environment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python Modules

Tags

sanic cors extensioncross-origin requests saniccors middleware sanicenable cors sanic appcross-origin ajax sanicsanic cors decorator
corsabandoned-projectsanic-framework

More Python Modules packages