jupyterlite-simple-cors-proxy 0.0.1__py3-none-any.whl
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/__init__.py +5 -0
- jupyterlite_simple_cors_proxy/proxy.py +41 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/LICENSE +21 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/METADATA +46 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/RECORD +7 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/WHEEL +5 -0
- jupyterlite_simple_cors_proxy-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# File: simple_cors_proxy/proxy.py
|
2
|
+
from urllib.parse import urlencode, quote
|
3
|
+
import requests
|
4
|
+
|
5
|
+
class ProxyResponse:
|
6
|
+
def __init__(self, content):
|
7
|
+
self._content = content
|
8
|
+
|
9
|
+
@property
|
10
|
+
def text(self):
|
11
|
+
return self._content
|
12
|
+
|
13
|
+
def json(self):
|
14
|
+
import json
|
15
|
+
|
16
|
+
return json.loads(self._content)
|
17
|
+
|
18
|
+
@property
|
19
|
+
def content(self):
|
20
|
+
return self._content.encode()
|
21
|
+
|
22
|
+
|
23
|
+
def cors_proxy(url, params=None):
|
24
|
+
"""
|
25
|
+
CORS proxy for GET resources with requests-like response.
|
26
|
+
|
27
|
+
Args:
|
28
|
+
url (str): The URL to fetch
|
29
|
+
params (dict, optional): Query parameters to include
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
ProxyResponse: A response object with .text, .json(), and .content methods
|
33
|
+
"""
|
34
|
+
if params:
|
35
|
+
full_url = f"{url}?{urlencode(params)}"
|
36
|
+
else:
|
37
|
+
full_url = url
|
38
|
+
|
39
|
+
proxy_url = f"https://corsproxy.io/?{quote(full_url)}"
|
40
|
+
response = requests.get(proxy_url).content.decode().strip()
|
41
|
+
return ProxyResponse(response)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 innovationOUtside
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: jupyterlite-simple-cors-proxy
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: A simple CORS proxy utility with requests-like response
|
5
|
+
Home-page: https://github.com/innovationOUtside/jupyterlite-simple-cors-proxy
|
6
|
+
Author: Tony Hirst
|
7
|
+
Author-email: tony.hirst@gmail.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.6
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: requests>=2.32.0
|
15
|
+
|
16
|
+
# jupyterlite-simple-cors-proxy
|
17
|
+
Simple CORS proxy for making http requests from JupyterLite
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
```bash
|
22
|
+
pip install simple-cors-proxy
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```python
|
28
|
+
from simple_cors_proxy import cors_proxy
|
29
|
+
|
30
|
+
# Make a request
|
31
|
+
url = "https://api.example.com/data"
|
32
|
+
params = {"key": "value"}
|
33
|
+
response = cors_proxy(url, params)
|
34
|
+
|
35
|
+
# Use like requests
|
36
|
+
print(response.text)
|
37
|
+
data = response.json()
|
38
|
+
raw = response.content
|
39
|
+
```
|
40
|
+
|
41
|
+
## Features
|
42
|
+
|
43
|
+
- Simple CORS proxy wrapper
|
44
|
+
- Requests-like response object
|
45
|
+
- Support for URL parameters
|
46
|
+
- JSON parsing
|
@@ -0,0 +1,7 @@
|
|
1
|
+
jupyterlite_simple_cors_proxy/__init__.py,sha256=wiS7zPJSmqeRn4N3oXw_I6-3fcob3zmHNYPajNzJBC8,160
|
2
|
+
jupyterlite_simple_cors_proxy/proxy.py,sha256=ccWngd54cCctn84VLRqS1n68CLcAau-m1UMGKzdTDHQ,977
|
3
|
+
jupyterlite_simple_cors_proxy-0.0.1.dist-info/LICENSE,sha256=Ogw7GUmeZIxmDNiKWsu_N07svNoGnPB7lWyiXHX_rMY,1074
|
4
|
+
jupyterlite_simple_cors_proxy-0.0.1.dist-info/METADATA,sha256=WHxay6lOzsMur4XI-dd7pLkIXW6QiNqQ5NmSiy2itK8,1074
|
5
|
+
jupyterlite_simple_cors_proxy-0.0.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
6
|
+
jupyterlite_simple_cors_proxy-0.0.1.dist-info/top_level.txt,sha256=Oh0oQrSmRnBq5u675coiKMbkb2ASg8AGF8ZiZTzUS5Q,30
|
7
|
+
jupyterlite_simple_cors_proxy-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
jupyterlite_simple_cors_proxy
|