jupyterlite-simple-cors-proxy


Namejupyterlite-simple-cors-proxy JSON
Version 0.1.11 PyPI version JSON
download
home_pagehttps://github.com/innovationOUtside/jupyterlite-simple-cors-proxy
SummaryA simple CORS proxy utility with requests-like response
upload_time2025-01-15 18:38:41
maintainerNone
docs_urlNone
authorTony Hirst
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jupyterlite-simple-cors-proxy
Simple CORS proxy wrapper for making http requests from JupyterLite. Uses https://corsproxy.io/

## Installation

```bash
pip install jupyterlite-simple-cors-proxy
```

## Usage

```python
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

## `fastf1` cors proxy

A monkey patch for `fastf1` is provided as:

```python
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`.*

```python
from simple_cors_proxy.proxy import CorsProxy

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

# 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')
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy",
    "name": "jupyterlite-simple-cors-proxy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Tony Hirst",
    "author_email": "tony.hirst@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/68/54/a3982e488a394c5c4f14393ba4621a50a6e28ce52ed0bdf67b30640517f5/jupyterlite_simple_cors_proxy-0.1.11.tar.gz",
    "platform": null,
    "description": "# jupyterlite-simple-cors-proxy\nSimple CORS proxy wrapper for making http requests from JupyterLite. Uses https://corsproxy.io/\n\n## Installation\n\n```bash\npip install jupyterlite-simple-cors-proxy\n```\n\n## Usage\n\n```python\nfrom jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl\n\n# Set up\nurl = \"https://api.example.com/data\"\n# Optional params\nparams = {\"key\": \"value\"}\n\n# Get a cross-origin proxied url\ncross_origin_url = xurl(url) # xurl(url, params)\n\n# Get a file like object\n# (Make the request, then create a file like object\n# from the response)\nfile_ob = furl(url) # furl(url, params)\n\n# Make a request\nresponse = cors_proxy_get(url, params)\n\n# Use like requests\nprint(response.text)\ndata = response.json()\nraw = response.content\n```\n\nThe `robust_get_request()` will first try a simple request, then a proxied request: `robust_get_request(url, params)`\n\n## Features\n\n- Simple CORS proxy wrapper\n- Requests response object\n- Support for URL parameters\n\n## `fastf1` cors proxy\n\nA monkey patch for `fastf1` is provided as:\n\n```python\nimport fast f1\nfrom jupyterlite_simple_cors_proxy.fastf1_proxy import enable_cors_proxy\n\nenable_cors_proxy(\n#    domains=[\"api.formula1.com\", \"livetiming.formula1.com\"],\n#    debug=True,\n#    proxy_url=\"https://corsproxy.io/\",\n)\n```\n\n## `CorsProxy` with cache facility\n\nVia `claude.ai`, the package is now further enriched.\n\n*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 `/`.*\n\n*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`.*\n\n```python\nfrom simple_cors_proxy.proxy import CorsProxy\n\n# Create a cached proxy instance\nproxy = CorsProxy(use_cache=True, expire_after=3600)  # Cache for 1 hour\n\n# Use furl directly from your proxy instance\nfile_like = proxy.furl('https://example.com/somefile.csv')\n\n#----\nimport pandas as pd\nfrom simple_cors_proxy.cacheproxy import CorsProxy\n\nproxy = CorsProxy(use_cache=True)\nfile_like = proxy.furl('https://example.com/data.csv')\ndf = pd.read_csv(file_like)\n\n#----\n\nfrom simple_cors_proxy.proxy import create_cached_proxy\n\nproxy = create_cached_proxy(cache_name='my_cache', expire_after=86400)  # Cache for 1 day\nfile_like = proxy.furl('https://example.com/somefile.csv')\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simple CORS proxy utility with requests-like response",
    "version": "0.1.11",
    "project_urls": {
        "Homepage": "https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "707167ea52c04420bb8e717f69ea160f1963a7fc21943481a464283e560cd951",
                "md5": "62686a50229334b7504f220632bbd5d2",
                "sha256": "51eff436c3e82b812f185c13e67bdca963d52becbdcd13bf5bd10164935cd132"
            },
            "downloads": -1,
            "filename": "jupyterlite_simple_cors_proxy-0.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62686a50229334b7504f220632bbd5d2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8151,
            "upload_time": "2025-01-15T18:38:40",
            "upload_time_iso_8601": "2025-01-15T18:38:40.271336Z",
            "url": "https://files.pythonhosted.org/packages/70/71/67ea52c04420bb8e717f69ea160f1963a7fc21943481a464283e560cd951/jupyterlite_simple_cors_proxy-0.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6854a3982e488a394c5c4f14393ba4621a50a6e28ce52ed0bdf67b30640517f5",
                "md5": "ee0dd2d3479cddad485ebb969977dc4b",
                "sha256": "c70f215af4b61be14cd7553aa54a9434844e8fbcef01ea27fec3364689d394c8"
            },
            "downloads": -1,
            "filename": "jupyterlite_simple_cors_proxy-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "ee0dd2d3479cddad485ebb969977dc4b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6456,
            "upload_time": "2025-01-15T18:38:41",
            "upload_time_iso_8601": "2025-01-15T18:38:41.330493Z",
            "url": "https://files.pythonhosted.org/packages/68/54/a3982e488a394c5c4f14393ba4621a50a6e28ce52ed0bdf67b30640517f5/jupyterlite_simple_cors_proxy-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-15 18:38:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "innovationOUtside",
    "github_project": "jupyterlite-simple-cors-proxy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jupyterlite-simple-cors-proxy"
}
        
Elapsed time: 0.41742s