jupyterlite-simple-cors-proxy 0.1.3__tar.gz → 0.1.5__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jupyterlite-simple-cors-proxy
3
- Version: 0.1.3
3
+ Version: 0.1.5
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
@@ -8,10 +8,10 @@ Author-email: tony.hirst@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
11
+ Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: requests>=2.32.0
14
+ Requires-Dist: requests
15
15
  Dynamic: author
16
16
  Dynamic: author-email
17
17
  Dynamic: classifier
@@ -34,12 +34,23 @@ pip install jupyterlite-simple-cors-proxy
34
34
  ## Usage
35
35
 
36
36
  ```python
37
- from simple_cors_proxy import cors_proxy_get, robust_get_request
37
+ from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl
38
38
 
39
- # Make a request
39
+ # Set up
40
40
  url = "https://api.example.com/data"
41
+ # Optional params
41
42
  params = {"key": "value"}
42
- response = cors_proxy(url, params)
43
+
44
+ # Get a cross-origin proxied url
45
+ cross_origin_url = xurl(url) # xurl(url, params)
46
+
47
+ # Get a file like object
48
+ # (Make the request, then create a file like object
49
+ # from the response)
50
+ file_ob = furl(url) # furl(url, params)
51
+
52
+ # Make a request
53
+ response = cors_proxy_get(url, params)
43
54
 
44
55
  # Use like requests
45
56
  print(response.text)
@@ -47,7 +58,7 @@ data = response.json()
47
58
  raw = response.content
48
59
  ```
49
60
 
50
- The `robust_get_request()` will first try a simple reuqst, then a proxied request: `robust_get_request(url, params)`
61
+ The `robust_get_request()` will first try a simple request, then a proxied request: `robust_get_request(url, params)`
51
62
 
52
63
  ## Features
53
64
 
@@ -0,0 +1,43 @@
1
+ # jupyterlite-simple-cors-proxy
2
+ Simple CORS proxy for making http requests from JupyterLite
3
+
4
+ ## Installation
5
+
6
+ ```bash
7
+ pip install jupyterlite-simple-cors-proxy
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```python
13
+ from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl
14
+
15
+ # Set up
16
+ url = "https://api.example.com/data"
17
+ # Optional params
18
+ params = {"key": "value"}
19
+
20
+ # Get a cross-origin proxied url
21
+ cross_origin_url = xurl(url) # xurl(url, params)
22
+
23
+ # Get a file like object
24
+ # (Make the request, then create a file like object
25
+ # from the response)
26
+ file_ob = furl(url) # furl(url, params)
27
+
28
+ # Make a request
29
+ response = cors_proxy_get(url, params)
30
+
31
+ # Use like requests
32
+ print(response.text)
33
+ data = response.json()
34
+ raw = response.content
35
+ ```
36
+
37
+ The `robust_get_request()` will first try a simple request, then a proxied request: `robust_get_request(url, params)`
38
+
39
+ ## Features
40
+
41
+ - Simple CORS proxy wrapper
42
+ - Requests response object
43
+ - Support for URL parameters
@@ -1,6 +1,25 @@
1
1
  # File: simple_cors_proxy/proxy.py
2
2
  from urllib.parse import urlencode, quote
3
3
  import requests
4
+ import io
5
+
6
+ import platform
7
+ PLATFORM = platform.system().lower()
8
+
9
+ def xurl(url, params=None):
10
+ if PLATFORM=="emscripten":
11
+ if params:
12
+ url = f"{url}?{urlencode(params)}"
13
+ url = f"https://corsproxy.io/{quote(url)}"
14
+
15
+ return url
16
+
17
+ def furl(url, params=None):
18
+ """Return file like object."""
19
+ r = cors_proxy_get(url, params)
20
+
21
+ # Return a file-like object from the JSON string
22
+ return io.BytesIO(r.content)
4
23
 
5
24
 
6
25
  def cors_proxy_get(url, params=None):
@@ -14,12 +33,7 @@ def cors_proxy_get(url, params=None):
14
33
  Returns:
15
34
  A requests response object.
16
35
  """
17
- if params:
18
- full_url = f"{url}?{urlencode(params)}"
19
- else:
20
- full_url = url
21
-
22
- proxy_url = f"https://corsproxy.io/{quote(full_url)}"
36
+ proxy_url = xurl(url, params)
23
37
 
24
38
  # Do a simple requests get and
25
39
  # just pass through the entire response object
@@ -33,4 +47,4 @@ def robust_get_request(url, params=None):
33
47
  r = requests.get(url, params=params)
34
48
  except:
35
49
  r = cors_proxy_get(url, params=params)
36
- return r
50
+ return r
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jupyterlite-simple-cors-proxy
3
- Version: 0.1.3
3
+ Version: 0.1.5
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
@@ -8,10 +8,10 @@ Author-email: tony.hirst@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
11
+ Requires-Python: >=3.8
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: requests>=2.32.0
14
+ Requires-Dist: requests
15
15
  Dynamic: author
16
16
  Dynamic: author-email
17
17
  Dynamic: classifier
@@ -34,12 +34,23 @@ pip install jupyterlite-simple-cors-proxy
34
34
  ## Usage
35
35
 
36
36
  ```python
37
- from simple_cors_proxy import cors_proxy_get, robust_get_request
37
+ from jupyterlite_simple_cors_proxy.proxy import cors_proxy_get, robust_get_request, furl, xurl
38
38
 
39
- # Make a request
39
+ # Set up
40
40
  url = "https://api.example.com/data"
41
+ # Optional params
41
42
  params = {"key": "value"}
42
- response = cors_proxy(url, params)
43
+
44
+ # Get a cross-origin proxied url
45
+ cross_origin_url = xurl(url) # xurl(url, params)
46
+
47
+ # Get a file like object
48
+ # (Make the request, then create a file like object
49
+ # from the response)
50
+ file_ob = furl(url) # furl(url, params)
51
+
52
+ # Make a request
53
+ response = cors_proxy_get(url, params)
43
54
 
44
55
  # Use like requests
45
56
  print(response.text)
@@ -47,7 +58,7 @@ data = response.json()
47
58
  raw = response.content
48
59
  ```
49
60
 
50
- The `robust_get_request()` will first try a simple reuqst, then a proxied request: `robust_get_request(url, params)`
61
+ The `robust_get_request()` will first try a simple request, then a proxied request: `robust_get_request(url, params)`
51
62
 
52
63
  ## Features
53
64
 
@@ -3,10 +3,10 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="jupyterlite-simple-cors-proxy",
6
- version="0.1.3",
6
+ version="0.1.5",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
- "requests>=2.32.0",
9
+ "requests",
10
10
  ],
11
11
  author="Tony Hirst",
12
12
  author_email="tony.hirst@gmail.com",
@@ -19,5 +19,5 @@ setup(
19
19
  "License :: OSI Approved :: MIT License",
20
20
  "Operating System :: OS Independent",
21
21
  ],
22
- python_requires=">=3.6",
22
+ python_requires=">=3.8",
23
23
  )
@@ -1,32 +0,0 @@
1
- # jupyterlite-simple-cors-proxy
2
- Simple CORS proxy for making http requests from JupyterLite
3
-
4
- ## Installation
5
-
6
- ```bash
7
- pip install jupyterlite-simple-cors-proxy
8
- ```
9
-
10
- ## Usage
11
-
12
- ```python
13
- from simple_cors_proxy import cors_proxy_get, robust_get_request
14
-
15
- # Make a request
16
- url = "https://api.example.com/data"
17
- params = {"key": "value"}
18
- response = cors_proxy(url, params)
19
-
20
- # Use like requests
21
- print(response.text)
22
- data = response.json()
23
- raw = response.content
24
- ```
25
-
26
- The `robust_get_request()` will first try a simple reuqst, then a proxied request: `robust_get_request(url, params)`
27
-
28
- ## Features
29
-
30
- - Simple CORS proxy wrapper
31
- - Requests response object
32
- - Support for URL parameters