jupyterlite-simple-cors-proxy 0.1.9__tar.gz → 0.1.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/PKG-INFO +34 -1
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/README.md +33 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy/__init__.py +2 -2
- jupyterlite_simple_cors_proxy-0.1.10/jupyterlite_simple_cors_proxy/proxy.py +55 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy.egg-info/PKG-INFO +34 -1
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy.egg-info/SOURCES.txt +1 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/setup.py +1 -1
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/LICENSE +0 -0
- /jupyterlite_simple_cors_proxy-0.1.9/jupyterlite_simple_cors_proxy/proxy.py → /jupyterlite_simple_cors_proxy-0.1.10/jupyterlite_simple_cors_proxy/cacheproxy.py +0 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy/fastf1_proxy.py +0 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy.egg-info/dependency_links.txt +0 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy.egg-info/requires.txt +0 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/jupyterlite_simple_cors_proxy.egg-info/top_level.txt +0 -0
- {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: jupyterlite-simple-cors-proxy
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.10
|
4
4
|
Summary: A simple CORS proxy utility with requests-like response
|
5
5
|
Home-page: https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy
|
6
6
|
Author: Tony Hirst
|
@@ -80,3 +80,36 @@ enable_cors_proxy(
|
|
80
80
|
# proxy_url="https://corsproxy.io/",
|
81
81
|
)
|
82
82
|
```
|
83
|
+
|
84
|
+
## `CorsProxy` with cache facility
|
85
|
+
|
86
|
+
Via `claude.ai`, the package is now further enriched.
|
87
|
+
|
88
|
+
*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 `/`.*
|
89
|
+
|
90
|
+
*I'm not convinced the following works in `pyodide` and `xeus-python` yet - `requests-cache` dependency issues etc.*
|
91
|
+
|
92
|
+
```python
|
93
|
+
from simple_cors_proxy.proxy import CorsProxy
|
94
|
+
|
95
|
+
# Create a cached proxy instance
|
96
|
+
proxy = CorsProxy(use_cache=True, expire_after=3600) # Cache for 1 hour
|
97
|
+
|
98
|
+
# Use furl directly from your proxy instance
|
99
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
100
|
+
|
101
|
+
#----
|
102
|
+
import pandas as pd
|
103
|
+
from simple_cors_proxy.cacheproxy import CorsProxy
|
104
|
+
|
105
|
+
proxy = CorsProxy(use_cache=True)
|
106
|
+
file_like = proxy.furl('https://example.com/data.csv')
|
107
|
+
df = pd.read_csv(file_like)
|
108
|
+
|
109
|
+
#----
|
110
|
+
|
111
|
+
from simple_cors_proxy.proxy import create_cached_proxy
|
112
|
+
|
113
|
+
proxy = create_cached_proxy(cache_name='my_cache', expire_after=86400) # Cache for 1 day
|
114
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
115
|
+
```
|
@@ -56,3 +56,36 @@ enable_cors_proxy(
|
|
56
56
|
# proxy_url="https://corsproxy.io/",
|
57
57
|
)
|
58
58
|
```
|
59
|
+
|
60
|
+
## `CorsProxy` with cache facility
|
61
|
+
|
62
|
+
Via `claude.ai`, the package is now further enriched.
|
63
|
+
|
64
|
+
*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 `/`.*
|
65
|
+
|
66
|
+
*I'm not convinced the following works in `pyodide` and `xeus-python` yet - `requests-cache` dependency issues etc.*
|
67
|
+
|
68
|
+
```python
|
69
|
+
from simple_cors_proxy.proxy import CorsProxy
|
70
|
+
|
71
|
+
# Create a cached proxy instance
|
72
|
+
proxy = CorsProxy(use_cache=True, expire_after=3600) # Cache for 1 hour
|
73
|
+
|
74
|
+
# Use furl directly from your proxy instance
|
75
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
76
|
+
|
77
|
+
#----
|
78
|
+
import pandas as pd
|
79
|
+
from simple_cors_proxy.cacheproxy import CorsProxy
|
80
|
+
|
81
|
+
proxy = CorsProxy(use_cache=True)
|
82
|
+
file_like = proxy.furl('https://example.com/data.csv')
|
83
|
+
df = pd.read_csv(file_like)
|
84
|
+
|
85
|
+
#----
|
86
|
+
|
87
|
+
from simple_cors_proxy.proxy import create_cached_proxy
|
88
|
+
|
89
|
+
proxy = create_cached_proxy(cache_name='my_cache', expire_after=86400) # Cache for 1 day
|
90
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
91
|
+
```
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# File: jupyterlite_simple_cors_proxy/__init__.py
|
2
|
-
from .
|
2
|
+
from .cacheproxy import cors_proxy_get, robust_get_request, xurl, furl
|
3
3
|
|
4
4
|
# from .fastf1_proxy import enable_cors_proxy as fastf1_cors_proxy
|
5
5
|
|
6
|
-
__version__ = "0.1.
|
6
|
+
__version__ = "0.1.10"
|
7
7
|
__all__ = ["cors_proxy_get", "robust_get_request", "xurl", "furl"]
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# File: simple_cors_proxy/proxy.py
|
2
|
+
from urllib.parse import urlencode, quote
|
3
|
+
import requests
|
4
|
+
import io
|
5
|
+
|
6
|
+
import platform
|
7
|
+
|
8
|
+
PLATFORM = platform.system().lower()
|
9
|
+
|
10
|
+
|
11
|
+
def xurl(url, params=None, force=False):
|
12
|
+
"""Generate a proxied URL."""
|
13
|
+
if PLATFORM == "emscripten" or force:
|
14
|
+
if params:
|
15
|
+
url = f"{url}?{urlencode(params)}"
|
16
|
+
url = f"https://corsproxy.io/{quote(url)}"
|
17
|
+
|
18
|
+
return url
|
19
|
+
|
20
|
+
|
21
|
+
def furl(url, params=None, force=False):
|
22
|
+
"""Return file like object after calling the proxied URL."""
|
23
|
+
r = cors_proxy_get(url, params, force)
|
24
|
+
|
25
|
+
# Return a file-like object from the JSON string
|
26
|
+
return io.BytesIO(r.content)
|
27
|
+
|
28
|
+
|
29
|
+
def cors_proxy_get(url, params=None, force=False):
|
30
|
+
"""
|
31
|
+
CORS proxy for GET resources with requests-like response.
|
32
|
+
|
33
|
+
Args:
|
34
|
+
url (str): The URL to fetch
|
35
|
+
params (dict, optional): Query parameters to include
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
A requests response object.
|
39
|
+
"""
|
40
|
+
proxy_url = xurl(url, params, force)
|
41
|
+
|
42
|
+
# Do a simple requests get and
|
43
|
+
# just pass through the entire response object
|
44
|
+
return requests.get(proxy_url)
|
45
|
+
|
46
|
+
|
47
|
+
def robust_get_request(url, params=None):
|
48
|
+
"""
|
49
|
+
Try to make a simple request else fall back to a proxy.
|
50
|
+
"""
|
51
|
+
try:
|
52
|
+
r = requests.get(url, params=params)
|
53
|
+
except:
|
54
|
+
r = cors_proxy_get(url, params=params)
|
55
|
+
return r
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: jupyterlite-simple-cors-proxy
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.10
|
4
4
|
Summary: A simple CORS proxy utility with requests-like response
|
5
5
|
Home-page: https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy
|
6
6
|
Author: Tony Hirst
|
@@ -80,3 +80,36 @@ enable_cors_proxy(
|
|
80
80
|
# proxy_url="https://corsproxy.io/",
|
81
81
|
)
|
82
82
|
```
|
83
|
+
|
84
|
+
## `CorsProxy` with cache facility
|
85
|
+
|
86
|
+
Via `claude.ai`, the package is now further enriched.
|
87
|
+
|
88
|
+
*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 `/`.*
|
89
|
+
|
90
|
+
*I'm not convinced the following works in `pyodide` and `xeus-python` yet - `requests-cache` dependency issues etc.*
|
91
|
+
|
92
|
+
```python
|
93
|
+
from simple_cors_proxy.proxy import CorsProxy
|
94
|
+
|
95
|
+
# Create a cached proxy instance
|
96
|
+
proxy = CorsProxy(use_cache=True, expire_after=3600) # Cache for 1 hour
|
97
|
+
|
98
|
+
# Use furl directly from your proxy instance
|
99
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
100
|
+
|
101
|
+
#----
|
102
|
+
import pandas as pd
|
103
|
+
from simple_cors_proxy.cacheproxy import CorsProxy
|
104
|
+
|
105
|
+
proxy = CorsProxy(use_cache=True)
|
106
|
+
file_like = proxy.furl('https://example.com/data.csv')
|
107
|
+
df = pd.read_csv(file_like)
|
108
|
+
|
109
|
+
#----
|
110
|
+
|
111
|
+
from simple_cors_proxy.proxy import create_cached_proxy
|
112
|
+
|
113
|
+
proxy = create_cached_proxy(cache_name='my_cache', expire_after=86400) # Cache for 1 day
|
114
|
+
file_like = proxy.furl('https://example.com/somefile.csv')
|
115
|
+
```
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|