datasette-cors
Datasette plugin for configuring CORS headers, based on asgi-cors.
You can use this plugin to allow JavaScript running on an allowlisted set of domains to make fetch() calls to the JSON API provided by your Datasette instance.
Installation
datasette install datasette-cors
Configuration
You need to add some plugin configuration for this plugin to take effect.
To allowlist specific domains, use this:
{
"plugins": {
"datasette-cors": {
"hosts": ["https://www.example.com"]
}
}
}
This affects the access-control-allow-origin header.
You can also allowlist host patterns like this:
{
"plugins": {
"datasette-cors": {
"host_wildcards": ["https://*.example.com"]
}
}
}
To allow all origins, use:
{
"plugins": {
"datasette-cors": {
"allow_all": true
}
}
}
This sets the access-control-allow-origin header to *.
You can specify allowed headers - with the access-control-allow-headers header - using the headers option:
{
"plugins": {
"datasette-cors": {
"allow_all": true,
"headers": ["Authorization", "Content-Type"]
}
}
}
To allow specific HTTP methods with the access-control-allow-methods header, use the methods option:
{
"plugins": {
"datasette-cors": {
"allow_all": true,
"methods": ["GET", "POST", "OPTIONS"]
}
}
}
You can set the access-control-max-age header using the max_age option:
{
"plugins": {
"datasette-cors": {
"allow_all": true,
"max_age": 3600
}
}
}
Testing it
To test this plugin out, run it locally by saving one of the above examples as metadata.json and running this:
datasette -m metadata.json
With Datasette 1.0 use -c config.json instead, or try this:
datasette -s plugins.datasette-cors.allow_all true
Now visit https://www.example.com/ in your browser, open the browser developer console and paste in the following:
fetch("http://127.0.0.1:8001/_memory.json?sql=select+sqlite_version%28%29").then(r => r.json()).then(console.log)
If the plugin is working correctly, you will see the JSON response output to the console.
Metadata
Release files for datasette-cors 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datasette-cors-1.0.1.tar.gz | 6.6 kB | Without provenance | Details for datasette-cors-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datasette_cors-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for datasette_cors-1.0.1-py3-none-any.whl |
Total release size: 13.7 kB
Release files / datasette-cors-1.0.1.tar.gz
| Download URL | datasette-cors-1.0.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a676982c6d316258d634e1e2437ec842fe917be601468ea5a16ed8a6ef9a9182
|
|
BLAKE2b-256 checksum How to use checksums |
250755f754a104eddba0d3080a50a2c96d75c6851d65db29f6fcd1b244fb8512
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / datasette_cors-1.0.1-py3-none-any.whl
| Download URL | datasette_cors-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5890293fd81c469672b9fb63958e094b10449b1f126a406ce4036640b57b040
|
|
BLAKE2b-256 checksum How to use checksums |
99a8293da46a70fc332d57646a8fb2beddab12f9f36a824b538fae09061bd5a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for datasette-cors 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.