pyfex 0.1.0__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.
pyfex-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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.
pyfex-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfex
3
+ Version: 0.1.0
4
+ Summary: Lightweight zero-dependency utility to fetch and execute remote Python scripts.
5
+ License: MIT
6
+ Keywords: fetch,exec,http,remote,script,loader
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: license-file
21
+
22
+ # pyfex
23
+
24
+ Lightweight, zero-dependency Python library & CLI to fetch and execute remote Python scripts over HTTP/HTTPS.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install pyfex
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Python API
35
+
36
+ ```python
37
+ from pyfex import fex, fetch
38
+
39
+ # Fetch and execute (https:// is optional)
40
+ fex("example.com/script.py")
41
+
42
+ # Pass variables into the executed script namespace
43
+ ns = {"x": 42}
44
+ if fex("https://example.com/script.py", namespace=ns, timeout=15):
45
+ print("Done!", ns.get("result"))
46
+
47
+ # Only fetch without executing
48
+ status, text = fetch("example.com")
49
+ ```
50
+
51
+ ### CLI
52
+
53
+ ```bash
54
+ pyfex example.com/script.py --timeout 10
55
+ ```
56
+
57
+ ## Security Notice
58
+
59
+ `fex()` executes arbitrary Python code via `exec()`. Only use it with trusted URLs over HTTPS.
pyfex-0.1.0/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # pyfex
2
+
3
+ Lightweight, zero-dependency Python library & CLI to fetch and execute remote Python scripts over HTTP/HTTPS.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install pyfex
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Python API
14
+
15
+ ```python
16
+ from pyfex import fex, fetch
17
+
18
+ # Fetch and execute (https:// is optional)
19
+ fex("example.com/script.py")
20
+
21
+ # Pass variables into the executed script namespace
22
+ ns = {"x": 42}
23
+ if fex("https://example.com/script.py", namespace=ns, timeout=15):
24
+ print("Done!", ns.get("result"))
25
+
26
+ # Only fetch without executing
27
+ status, text = fetch("example.com")
28
+ ```
29
+
30
+ ### CLI
31
+
32
+ ```bash
33
+ pyfex example.com/script.py --timeout 10
34
+ ```
35
+
36
+ ## Security Notice
37
+
38
+ `fex()` executes arbitrary Python code via `exec()`. Only use it with trusted URLs over HTTPS.
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pyfex"
7
+ version = "0.1.0"
8
+ description = "Lightweight zero-dependency utility to fetch and execute remote Python scripts."
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.9"
12
+ keywords = ["fetch", "exec", "http", "remote", "script", "loader"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ ]
25
+ dependencies = []
26
+
27
+ [project.scripts]
28
+ pyfex = "pyfex.cli:main"
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
pyfex-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ from .core import fetch, fex
4
+
5
+ __all__ = ["fex", "fetch", "__version__"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,24 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+
6
+ from .core import fex
7
+
8
+
9
+ def main(argv: list[str] | None = None) -> int:
10
+ parser = argparse.ArgumentParser(
11
+ prog="pyfex",
12
+ description="Fetch and execute a Python script from a URL.",
13
+ )
14
+ parser.add_argument("url", help="Target URL (https:// is added automatically if omitted)")
15
+ parser.add_argument("-t", "--timeout", type=int, default=10, help="Request timeout in seconds (default: 10)")
16
+ parser.add_argument("-s", "--silent", action="store_true", help="Suppress error output")
17
+ args = parser.parse_args(argv)
18
+
19
+ ok = fex(args.url, timeout=args.timeout, silent=args.silent)
20
+ return 0 if ok else 1
21
+
22
+
23
+ if __name__ == "__main__":
24
+ sys.exit(main())
@@ -0,0 +1,89 @@
1
+ from __future__ import annotations
2
+
3
+ import urllib.request
4
+ from urllib.error import HTTPError, URLError
5
+
6
+ DEFAULT_HEADERS = {"User-Agent": "pyfex/0.1.0"}
7
+
8
+
9
+ def _normalize_url(url: str) -> str:
10
+ url = url.strip()
11
+ if not url:
12
+ raise ValueError("URL must not be empty.")
13
+ if not url.startswith(("http://", "https://")):
14
+ url = "https://" + url
15
+ return url
16
+
17
+
18
+ def fetch(
19
+ url: str,
20
+ timeout: int = 10,
21
+ headers: dict[str, str] | None = None,
22
+ ) -> tuple[int, str]:
23
+ """
24
+ Perform an HTTP GET request to `url` (auto-prepending `https://` if missing).
25
+ Returns `(status_code, response_text)`.
26
+ """
27
+ normalized = _normalize_url(url)
28
+ req_headers = {**DEFAULT_HEADERS, **(headers or {})}
29
+ req = urllib.request.Request(normalized, method="GET", headers=req_headers)
30
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
31
+ charset = resp.headers.get_content_charset() or "utf-8"
32
+ body = resp.read().decode(charset, errors="replace")
33
+ return resp.status, body
34
+
35
+
36
+ def fex(
37
+ url: str,
38
+ namespace: dict | None = None,
39
+ timeout: int = 10,
40
+ headers: dict[str, str] | None = None,
41
+ silent: bool = False,
42
+ ) -> bool:
43
+ """
44
+ Fetch Python code from `url` via GET and execute it with `exec()`.
45
+ Handles missing scheme, network/HTTP errors, timeouts, and empty responses safely.
46
+ Returns `True` on success, `False` otherwise.
47
+ """
48
+ def _log(msg: str) -> None:
49
+ if not silent:
50
+ print(msg)
51
+
52
+ try:
53
+ status, code = fetch(url, timeout=timeout, headers=headers)
54
+ except ValueError as e:
55
+ _log(f"[pyfex] {e}")
56
+ return False
57
+ except HTTPError as e:
58
+ _log(f"[pyfex] HTTP error: {e.code} {e.reason}")
59
+ return False
60
+ except URLError as e:
61
+ _log(f"[pyfex] Request failed: {e.reason}")
62
+ return False
63
+ except TimeoutError:
64
+ _log(f"[pyfex] Request timed out after {timeout}s.")
65
+ return False
66
+ except Exception as e:
67
+ _log(f"[pyfex] Unexpected request error: {e}")
68
+ return False
69
+
70
+ if status != 200:
71
+ _log(f"[pyfex] Unexpected HTTP status: {status}")
72
+ return False
73
+
74
+ code = code.strip()
75
+ if not code:
76
+ _log("[pyfex] Empty response body.")
77
+ return False
78
+
79
+ try:
80
+ exec_ns = {"__name__": "__main__"}
81
+ if namespace is not None:
82
+ exec_ns.update(namespace)
83
+ exec(code, exec_ns)
84
+ if namespace is not None:
85
+ namespace.update(exec_ns)
86
+ return True
87
+ except Exception as e:
88
+ _log(f"[pyfex] Execution error: {e}")
89
+ return False
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfex
3
+ Version: 0.1.0
4
+ Summary: Lightweight zero-dependency utility to fetch and execute remote Python scripts.
5
+ License: MIT
6
+ Keywords: fetch,exec,http,remote,script,loader
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: license-file
21
+
22
+ # pyfex
23
+
24
+ Lightweight, zero-dependency Python library & CLI to fetch and execute remote Python scripts over HTTP/HTTPS.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install pyfex
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Python API
35
+
36
+ ```python
37
+ from pyfex import fex, fetch
38
+
39
+ # Fetch and execute (https:// is optional)
40
+ fex("example.com/script.py")
41
+
42
+ # Pass variables into the executed script namespace
43
+ ns = {"x": 42}
44
+ if fex("https://example.com/script.py", namespace=ns, timeout=15):
45
+ print("Done!", ns.get("result"))
46
+
47
+ # Only fetch without executing
48
+ status, text = fetch("example.com")
49
+ ```
50
+
51
+ ### CLI
52
+
53
+ ```bash
54
+ pyfex example.com/script.py --timeout 10
55
+ ```
56
+
57
+ ## Security Notice
58
+
59
+ `fex()` executes arbitrary Python code via `exec()`. Only use it with trusted URLs over HTTPS.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/pyfex/__init__.py
5
+ src/pyfex/cli.py
6
+ src/pyfex/core.py
7
+ src/pyfex.egg-info/PKG-INFO
8
+ src/pyfex.egg-info/SOURCES.txt
9
+ src/pyfex.egg-info/dependency_links.txt
10
+ src/pyfex.egg-info/entry_points.txt
11
+ src/pyfex.egg-info/top_level.txt
12
+ tests/test_pyfex.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pyfex = pyfex.cli:main
@@ -0,0 +1 @@
1
+ pyfex
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ import threading
4
+ import unittest
5
+ from http.server import BaseHTTPRequestHandler, HTTPServer
6
+
7
+ from pyfex import fetch, fex
8
+ from pyfex.core import _normalize_url
9
+
10
+
11
+ class _Handler(BaseHTTPRequestHandler):
12
+ def do_GET(self):
13
+ if self.path == "/ok.py":
14
+ self.send_response(200)
15
+ self.end_headers()
16
+ self.wfile.write(b"result = x * 2\n")
17
+ elif self.path == "/empty.py":
18
+ self.send_response(200)
19
+ self.end_headers()
20
+ self.wfile.write(b" \n")
21
+ elif self.path == "/bad_code.py":
22
+ self.send_response(200)
23
+ self.end_headers()
24
+ self.wfile.write(b"raise RuntimeError('boom')\n")
25
+ else:
26
+ self.send_response(404)
27
+ self.end_headers()
28
+
29
+ def log_message(self, format, *args):
30
+ pass
31
+
32
+
33
+ class TestPyFex(unittest.TestCase):
34
+ @classmethod
35
+ def setUpClass(cls):
36
+ cls.server = HTTPServer(("127.0.0.1", 0), _Handler)
37
+ cls.port = cls.server.server_address[1]
38
+ cls.thread = threading.Thread(target=cls.server.serve_forever, daemon=True)
39
+ cls.thread.start()
40
+
41
+ @classmethod
42
+ def tearDownClass(cls):
43
+ cls.server.shutdown()
44
+ cls.server.server_close()
45
+
46
+ def test_normalize_url(self):
47
+ self.assertEqual(_normalize_url("example.com/a.py"), "https://example.com/a.py")
48
+ self.assertEqual(_normalize_url("http://example.com/a.py"), "http://example.com/a.py")
49
+ self.assertEqual(_normalize_url("https://example.com/a.py"), "https://example.com/a.py")
50
+ with self.assertRaises(ValueError):
51
+ _normalize_url(" ")
52
+
53
+ def test_fetch_ok(self):
54
+ status, body = fetch(f"http://127.0.0.1:{self.port}/ok.py")
55
+ self.assertEqual(status, 200)
56
+ self.assertIn("result = x * 2", body)
57
+
58
+ def test_fex_ok(self):
59
+ ns = {"x": 21}
60
+ ok = fex(f"http://127.0.0.1:{self.port}/ok.py", namespace=ns, silent=True)
61
+ self.assertTrue(ok)
62
+ self.assertEqual(ns["result"], 42)
63
+
64
+ def test_fex_empty(self):
65
+ self.assertFalse(fex(f"http://127.0.0.1:{self.port}/empty.py", silent=True))
66
+
67
+ def test_fex_404(self):
68
+ self.assertFalse(fex(f"http://127.0.0.1:{self.port}/missing.py", silent=True))
69
+
70
+ def test_fex_exec_error(self):
71
+ self.assertFalse(fex(f"http://127.0.0.1:{self.port}/bad_code.py", silent=True))
72
+
73
+
74
+ if __name__ == "__main__":
75
+ unittest.main()