Skip to main content

jupyterlite-simple-cors-proxy

Simple CORS proxy wrapper for making http requests from JupyterLite. Uses https://corsproxy.io/

Installation

pip install jupyterlite-simple-cors-proxy

Usage

from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl

# Set up
url = "https://api.example.com/data"
# Optional params
params = {"key": "value"}

# Get a cross-origin proxied url
cross_origin_url = xurl(url) # xurl(url, params)

# Get a file like object
# (Make the request, then create a file like object
# from the response)
file_ob = furl(url) # furl(url, params)

# Make a request
response = cors_proxy_get(url, params)

# Use like requests
print(response.text)
data = response.json()
raw = response.content

The robust_get_request() will first try a simple request, then a proxied request: robust_get_request(url, params)

Features

  • Simple CORS proxy wrapper
  • Requests response object
  • Support for URL parameters

Using an API key with a CORS proxy

Some proxies, such as corsproxy.io, support (or require) an API key, passed as ?key=abcd1234&url=.... Pass it via the api_key argument on any of the helper functions:

from jupyterlite_simple_cors_proxy.proxy import xurl, cors_proxy_get

cross_origin_url = xurl(url, api_key="abcd1234")
response = cors_proxy_get(url, params, api_key="abcd1234")

Or set a default api_key once when using the CorsProxy class:

from jupyterlite_simple_cors_proxy.cacheproxy import CorsProxy

proxy = CorsProxy(api_key="abcd1234")
response = proxy.cors_proxy_get(url, params)  # api_key applied automatically

fastf1 cors proxy

A monkey patch for fastf1 is provided as:

import fast f1
from jupyterlite_simple_cors_proxy.fastf1_proxy import enable_cors_proxy

enable_cors_proxy(
#    domains=["api.formula1.com", "livetiming.formula1.com"],
#    debug=True,
#    proxy_url="https://corsproxy.io/",
)

CorsProxy with cache facility

Via claude.ai, the package is now further enriched.

Note that pyodide sqlite can't write to /drive so the cache path dir needs to be something like /tmp or a dir created on /.

I'm not convinced the following works in pyodide and xeus-python yet - requests-cache dependency issues etc. requests-cache has requirements attrs, cattrs,platformdirs, url-normalize.

from simple_cors_proxy.proxy import CorsProxy

# Create a cached proxy instance
proxy = CorsProxy(use_cache=True, expire_after=3600)  # Cache for 1 hour

# Optionally pass an api_key (and/or proxy) to use by default
proxy = CorsProxy(use_cache=True, expire_after=3600, api_key="abcd1234")

# Use furl directly from your proxy instance
file_like = proxy.furl('https://example.com/somefile.csv')

#----
import pandas as pd
from simple_cors_proxy.cacheproxy import CorsProxy

proxy = CorsProxy(use_cache=True)
file_like = proxy.furl('https://example.com/data.csv')
df = pd.read_csv(file_like)

#----

from simple_cors_proxy.proxy import create_cached_proxy

proxy = create_cached_proxy(cache_name='my_cache', expire_after=86400)  # Cache for 1 day
file_like = proxy.furl('https://example.com/somefile.csv')

Metadata

Release files for jupyterlite-simple-cors-proxy 0.1.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jupyterlite-simple-cors-proxy 0.1.18
File Size Uploaded
jupyterlite_simple_cors_proxy-0.1.18.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jupyterlite-simple-cors-proxy 0.1.18
File Interpreter ABI Platform
jupyterlite_simple_cors_proxy-0.1.18-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / jupyterlite_simple_cors_proxy-0.1.18.tar.gz

Download URL jupyterlite_simple_cors_proxy-0.1.18.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dfeb481f0a29bc58db67ec823d89ff714b49d94501eb76202f8e51693ed4035d
BLAKE2b-256 checksum
How to use checksums
f0f5cf354418dc8d56b5f3974ffedc3cc2c4d5e2f45fbbe8471a534bba9e988f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / jupyterlite_simple_cors_proxy-0.1.18-py3-none-any.whl

Download URL jupyterlite_simple_cors_proxy-0.1.18-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36c3bd84ad4fc5c52d73e3b1dedb9897e1c5f3c8d50c15a5ebb57e54c059f00b
BLAKE2b-256 checksum
How to use checksums
a977e1912d4a72cc74802b7b09ca30f569306020ab1e43f9dbd953846d1b3489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.1.18 This release

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page