jupyterlite-simple-cors-proxy 0.1.9__tar.gz → 0.1.11__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (14) hide show
  1. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/PKG-INFO +34 -1
  2. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/README.md +33 -0
  3. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy/__init__.py +2 -2
  4. jupyterlite_simple_cors_proxy-0.1.9/jupyterlite_simple_cors_proxy/proxy.py → jupyterlite_simple_cors_proxy-0.1.11/jupyterlite_simple_cors_proxy/cacheproxy.py +2 -1
  5. jupyterlite_simple_cors_proxy-0.1.11/jupyterlite_simple_cors_proxy/proxy.py +55 -0
  6. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy.egg-info/PKG-INFO +34 -1
  7. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy.egg-info/SOURCES.txt +1 -0
  8. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/setup.py +1 -1
  9. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/LICENSE +0 -0
  10. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy/fastf1_proxy.py +0 -0
  11. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy.egg-info/dependency_links.txt +0 -0
  12. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy.egg-info/requires.txt +0 -0
  13. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/jupyterlite_simple_cors_proxy.egg-info/top_level.txt +0 -0
  14. {jupyterlite_simple_cors_proxy-0.1.9 → jupyterlite_simple_cors_proxy-0.1.11}/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.9
3
+ Version: 0.1.11
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. `requests-cache` has requirements `attrs`, `cattrs`,`platformdirs`, `url-normalize`.*
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. `requests-cache` has requirements `attrs`, `cattrs`,`platformdirs`, `url-normalize`.*
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 .proxy import cors_proxy_get, robust_get_request, xurl, furl
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.9"
6
+ __version__ = "0.1.11"
7
7
  __all__ = ["cors_proxy_get", "robust_get_request", "xurl", "furl"]
@@ -1,7 +1,7 @@
1
1
  # File: simple_cors_proxy/proxy.py
2
2
  from urllib.parse import urlencode, quote
3
3
  import requests
4
- import requests_cache
4
+
5
5
  import io
6
6
  import platform
7
7
  from typing import Optional, Union
@@ -21,6 +21,7 @@ class CorsProxy:
21
21
  (e.g., cache_name, backend, expire_after)
22
22
  """
23
23
  if use_cache:
24
+ import requests_cache
24
25
  # Set some sensible defaults if not provided
25
26
  if 'cache_name' not in cache_kwargs:
26
27
  cache_kwargs['cache_name'] = 'cors_proxy_cache'
@@ -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.9
3
+ Version: 0.1.11
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. `requests-cache` has requirements `attrs`, `cattrs`,`platformdirs`, `url-normalize`.*
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
+ ```
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  jupyterlite_simple_cors_proxy/__init__.py
5
+ jupyterlite_simple_cors_proxy/cacheproxy.py
5
6
  jupyterlite_simple_cors_proxy/fastf1_proxy.py
6
7
  jupyterlite_simple_cors_proxy/proxy.py
7
8
  jupyterlite_simple_cors_proxy.egg-info/PKG-INFO
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="jupyterlite-simple-cors-proxy",
6
- version="0.1.9",
6
+ version="0.1.11",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  "requests",