cf-share-file 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gabrys
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,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: cf-share-file
3
+ Version: 0.1.0
4
+ Summary: Share a single file through a Cloudflare quick tunnel.
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/gabrys/cf-share-file
7
+ Project-URL: Issues, https://github.com/gabrys/cf-share-file/issues
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Topic :: Utilities
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: license-file
17
+
18
+ # cf-share-file
19
+
20
+ Share one file over the internet using a Cloudflare quick tunnel. The command
21
+ starts a local HTTP server, launches `cloudflared`, and prints the public file
22
+ URL to standard output. Press Ctrl+C to stop sharing.
23
+
24
+ ## Installation
25
+
26
+ Requires Python 3.10 or newer and the standalone
27
+ [`cloudflared` executable](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
28
+ on your `PATH`. Installing this package does not install `cloudflared`.
29
+
30
+ ```sh
31
+ uvx cf-share-file --help
32
+ ```
33
+
34
+ Requires [uv](https://docs.astral.sh/uv/getting-started/installation/).
35
+ `uvx` downloads the package and runs it in an isolated environment.
36
+ For a persistent command, use `uv tool install cf-share-file`.
37
+
38
+ ## Usage
39
+
40
+ ```sh
41
+ uvx cf-share-file ./report.pdf
42
+ uvx cf-share-file ./report.pdf --auth 'alice:change-this-password'
43
+ uvx cf-share-file ./report.pdf --port 8080
44
+ uvx cf-share-file --help
45
+ ```
46
+
47
+ With a persistent installation, you can run `cf-share-file` directly.
48
+ The local server listens on `127.0.0.1`; the default port is chosen automatically.
49
+ Only the selected file path is served. GET and HEAD are supported.
50
+ Logs go to standard error; the public URL goes to standard output.
51
+
52
+ Without `--auth`, anyone who knows the public URL can download the file.
53
+ With `--auth`, requests require HTTP Basic authentication. Command-line
54
+ credentials may be visible in shell history or process listings.
55
+ The temporary tunnel depends on Cloudflare's service. The URL may need a few
56
+ seconds before it becomes reachable.
57
+
58
+ ## Development
59
+
60
+ ```sh
61
+ uv run python -m unittest discover -s tests -v
62
+ uvx --from build pyproject-build
63
+ uvx twine check --strict dist/*
64
+ ```
65
+
66
+ ## Publishing
67
+
68
+ Check that `cf-share-file` is available on PyPI and TestPyPI before the first
69
+ release. Availability has not been verified. If necessary, change the project
70
+ name in `pyproject.toml` and the installation commands here.
71
+
72
+ The initial version is `0.1.0`. Build from a clean checkout using the commands
73
+ above, ensuring `dist/` contains only the current release. Upload to TestPyPI:
74
+
75
+ ```sh
76
+ uvx twine upload --repository testpypi dist/*
77
+ ```
78
+
79
+ Verify the TestPyPI release in an isolated environment:
80
+
81
+ ```sh
82
+ uvx --isolated --index-url https://test.pypi.org/simple/ cf-share-file@0.1.0 --help
83
+ ```
84
+
85
+ Then upload the same artifacts to PyPI:
86
+
87
+ ```sh
88
+ uvx twine upload dist/*
89
+ ```
90
+
91
+ Use an API token when Twine prompts for credentials. Never commit credentials.
92
+ For subsequent releases, update the version in `pyproject.toml` and build fresh
93
+ artifacts; PyPI does not allow replacing an existing release file.
94
+ GitHub Actions runs tests and validates distributions; publishing is manual.
95
+
96
+ ## License
97
+
98
+ MIT; see [LICENSE](LICENSE).
@@ -0,0 +1,81 @@
1
+ # cf-share-file
2
+
3
+ Share one file over the internet using a Cloudflare quick tunnel. The command
4
+ starts a local HTTP server, launches `cloudflared`, and prints the public file
5
+ URL to standard output. Press Ctrl+C to stop sharing.
6
+
7
+ ## Installation
8
+
9
+ Requires Python 3.10 or newer and the standalone
10
+ [`cloudflared` executable](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
11
+ on your `PATH`. Installing this package does not install `cloudflared`.
12
+
13
+ ```sh
14
+ uvx cf-share-file --help
15
+ ```
16
+
17
+ Requires [uv](https://docs.astral.sh/uv/getting-started/installation/).
18
+ `uvx` downloads the package and runs it in an isolated environment.
19
+ For a persistent command, use `uv tool install cf-share-file`.
20
+
21
+ ## Usage
22
+
23
+ ```sh
24
+ uvx cf-share-file ./report.pdf
25
+ uvx cf-share-file ./report.pdf --auth 'alice:change-this-password'
26
+ uvx cf-share-file ./report.pdf --port 8080
27
+ uvx cf-share-file --help
28
+ ```
29
+
30
+ With a persistent installation, you can run `cf-share-file` directly.
31
+ The local server listens on `127.0.0.1`; the default port is chosen automatically.
32
+ Only the selected file path is served. GET and HEAD are supported.
33
+ Logs go to standard error; the public URL goes to standard output.
34
+
35
+ Without `--auth`, anyone who knows the public URL can download the file.
36
+ With `--auth`, requests require HTTP Basic authentication. Command-line
37
+ credentials may be visible in shell history or process listings.
38
+ The temporary tunnel depends on Cloudflare's service. The URL may need a few
39
+ seconds before it becomes reachable.
40
+
41
+ ## Development
42
+
43
+ ```sh
44
+ uv run python -m unittest discover -s tests -v
45
+ uvx --from build pyproject-build
46
+ uvx twine check --strict dist/*
47
+ ```
48
+
49
+ ## Publishing
50
+
51
+ Check that `cf-share-file` is available on PyPI and TestPyPI before the first
52
+ release. Availability has not been verified. If necessary, change the project
53
+ name in `pyproject.toml` and the installation commands here.
54
+
55
+ The initial version is `0.1.0`. Build from a clean checkout using the commands
56
+ above, ensuring `dist/` contains only the current release. Upload to TestPyPI:
57
+
58
+ ```sh
59
+ uvx twine upload --repository testpypi dist/*
60
+ ```
61
+
62
+ Verify the TestPyPI release in an isolated environment:
63
+
64
+ ```sh
65
+ uvx --isolated --index-url https://test.pypi.org/simple/ cf-share-file@0.1.0 --help
66
+ ```
67
+
68
+ Then upload the same artifacts to PyPI:
69
+
70
+ ```sh
71
+ uvx twine upload dist/*
72
+ ```
73
+
74
+ Use an API token when Twine prompts for credentials. Never commit credentials.
75
+ For subsequent releases, update the version in `pyproject.toml` and build fresh
76
+ artifacts; PyPI does not allow replacing an existing release file.
77
+ GitHub Actions runs tests and validates distributions; publishing is manual.
78
+
79
+ ## License
80
+
81
+ MIT; see [LICENSE](LICENSE).
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: cf-share-file
3
+ Version: 0.1.0
4
+ Summary: Share a single file through a Cloudflare quick tunnel.
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/gabrys/cf-share-file
7
+ Project-URL: Issues, https://github.com/gabrys/cf-share-file/issues
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Topic :: Utilities
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: license-file
17
+
18
+ # cf-share-file
19
+
20
+ Share one file over the internet using a Cloudflare quick tunnel. The command
21
+ starts a local HTTP server, launches `cloudflared`, and prints the public file
22
+ URL to standard output. Press Ctrl+C to stop sharing.
23
+
24
+ ## Installation
25
+
26
+ Requires Python 3.10 or newer and the standalone
27
+ [`cloudflared` executable](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)
28
+ on your `PATH`. Installing this package does not install `cloudflared`.
29
+
30
+ ```sh
31
+ uvx cf-share-file --help
32
+ ```
33
+
34
+ Requires [uv](https://docs.astral.sh/uv/getting-started/installation/).
35
+ `uvx` downloads the package and runs it in an isolated environment.
36
+ For a persistent command, use `uv tool install cf-share-file`.
37
+
38
+ ## Usage
39
+
40
+ ```sh
41
+ uvx cf-share-file ./report.pdf
42
+ uvx cf-share-file ./report.pdf --auth 'alice:change-this-password'
43
+ uvx cf-share-file ./report.pdf --port 8080
44
+ uvx cf-share-file --help
45
+ ```
46
+
47
+ With a persistent installation, you can run `cf-share-file` directly.
48
+ The local server listens on `127.0.0.1`; the default port is chosen automatically.
49
+ Only the selected file path is served. GET and HEAD are supported.
50
+ Logs go to standard error; the public URL goes to standard output.
51
+
52
+ Without `--auth`, anyone who knows the public URL can download the file.
53
+ With `--auth`, requests require HTTP Basic authentication. Command-line
54
+ credentials may be visible in shell history or process listings.
55
+ The temporary tunnel depends on Cloudflare's service. The URL may need a few
56
+ seconds before it becomes reachable.
57
+
58
+ ## Development
59
+
60
+ ```sh
61
+ uv run python -m unittest discover -s tests -v
62
+ uvx --from build pyproject-build
63
+ uvx twine check --strict dist/*
64
+ ```
65
+
66
+ ## Publishing
67
+
68
+ Check that `cf-share-file` is available on PyPI and TestPyPI before the first
69
+ release. Availability has not been verified. If necessary, change the project
70
+ name in `pyproject.toml` and the installation commands here.
71
+
72
+ The initial version is `0.1.0`. Build from a clean checkout using the commands
73
+ above, ensuring `dist/` contains only the current release. Upload to TestPyPI:
74
+
75
+ ```sh
76
+ uvx twine upload --repository testpypi dist/*
77
+ ```
78
+
79
+ Verify the TestPyPI release in an isolated environment:
80
+
81
+ ```sh
82
+ uvx --isolated --index-url https://test.pypi.org/simple/ cf-share-file@0.1.0 --help
83
+ ```
84
+
85
+ Then upload the same artifacts to PyPI:
86
+
87
+ ```sh
88
+ uvx twine upload dist/*
89
+ ```
90
+
91
+ Use an API token when Twine prompts for credentials. Never commit credentials.
92
+ For subsequent releases, update the version in `pyproject.toml` and build fresh
93
+ artifacts; PyPI does not allow replacing an existing release file.
94
+ GitHub Actions runs tests and validates distributions; publishing is manual.
95
+
96
+ ## License
97
+
98
+ MIT; see [LICENSE](LICENSE).
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ cf_share_file.py
4
+ pyproject.toml
5
+ cf_share_file.egg-info/PKG-INFO
6
+ cf_share_file.egg-info/SOURCES.txt
7
+ cf_share_file.egg-info/dependency_links.txt
8
+ cf_share_file.egg-info/entry_points.txt
9
+ cf_share_file.egg-info/top_level.txt
10
+ tests/test_cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cf-share-file = cf_share_file:main
@@ -0,0 +1 @@
1
+ cf_share_file
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env python3
2
+ """Share one file over the internet through a Cloudflare quick tunnel.
3
+
4
+ Serves FILE on a local HTTP server (127.0.0.1, random port), starts
5
+ `cloudflared tunnel --url ...` and prints the public URL of the file.
6
+ With --auth USER:PASSWORD every request needs HTTP Basic Auth.
7
+ Ctrl+C stops the server and the tunnel.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import base64
14
+ import hmac
15
+ import mimetypes
16
+ import os
17
+ import re
18
+ import shutil
19
+ import subprocess
20
+ import sys
21
+ import threading
22
+ import urllib.parse
23
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
24
+
25
+ TUNNEL_URL = re.compile(r"https://(?!api\.)[a-z0-9-]+\.trycloudflare\.com")
26
+
27
+
28
+ def make_handler(path: str, url_path: str, auth: str | None):
29
+ expected = "Basic " + base64.b64encode(auth.encode()).decode() if auth else None
30
+ ctype = mimetypes.guess_type(path)[0] or "application/octet-stream"
31
+ name = os.path.basename(path)
32
+ disposition = "inline; filename*=UTF-8''" + urllib.parse.quote(name)
33
+
34
+ class Handler(BaseHTTPRequestHandler):
35
+ def _serve(self, body: bool) -> None:
36
+ if expected and not hmac.compare_digest(
37
+ self.headers.get("Authorization", "").encode(), expected.encode()
38
+ ):
39
+ self.send_response(401)
40
+ self.send_header("WWW-Authenticate", 'Basic realm="restricted"')
41
+ self.send_header("Content-Length", "0")
42
+ self.end_headers()
43
+ return
44
+ if urllib.parse.urlsplit(self.path).path != url_path:
45
+ self.send_error(404)
46
+ return
47
+ try:
48
+ f = open(path, "rb")
49
+ except OSError:
50
+ self.send_error(404)
51
+ return
52
+ with f:
53
+ self.send_response(200)
54
+ self.send_header("Content-Type", ctype)
55
+ self.send_header("Content-Length", str(os.fstat(f.fileno()).st_size))
56
+ self.send_header("Content-Disposition", disposition)
57
+ self.end_headers()
58
+ if body:
59
+ try:
60
+ shutil.copyfileobj(f, self.wfile)
61
+ except (BrokenPipeError, ConnectionResetError):
62
+ pass
63
+
64
+ def do_GET(self) -> None:
65
+ self._serve(True)
66
+
67
+ def do_HEAD(self) -> None:
68
+ self._serve(False)
69
+
70
+ return Handler
71
+
72
+
73
+ def main() -> int:
74
+ p = argparse.ArgumentParser(description=__doc__.splitlines()[0])
75
+ p.add_argument("file", help="file to share")
76
+ p.add_argument("--auth", metavar="USER:PASSWORD", help="require HTTP Basic Auth")
77
+ p.add_argument("--port", type=int, default=0, help="local port (default: random)")
78
+ args = p.parse_args()
79
+
80
+ if not os.path.isfile(args.file):
81
+ p.error(f"not a file: {args.file}")
82
+ if args.auth is not None and ":" not in args.auth:
83
+ p.error("--auth must be USER:PASSWORD")
84
+ if not shutil.which("cloudflared"):
85
+ p.error("cloudflared not found in PATH")
86
+
87
+ path = os.path.abspath(args.file)
88
+ url_path = "/" + urllib.parse.quote(os.path.basename(path))
89
+ server = ThreadingHTTPServer(
90
+ ("127.0.0.1", args.port), make_handler(path, url_path, args.auth)
91
+ )
92
+ port = server.server_address[1]
93
+ threading.Thread(target=server.serve_forever, daemon=True).start()
94
+ print(f"Local: http://127.0.0.1:{port}{url_path}", file=sys.stderr)
95
+
96
+ proc = subprocess.Popen(
97
+ ["cloudflared", "tunnel", "--no-autoupdate", "--url", f"http://127.0.0.1:{port}"],
98
+ stdout=subprocess.DEVNULL,
99
+ stderr=subprocess.PIPE,
100
+ text=True,
101
+ errors="replace",
102
+ )
103
+ try:
104
+ found = False
105
+ log = []
106
+ for line in proc.stderr: # keep draining so cloudflared never blocks
107
+ if not found:
108
+ log.append(line)
109
+ m = TUNNEL_URL.search(line)
110
+ if m:
111
+ found = True
112
+ print(m.group(0) + url_path, flush=True)
113
+ print("(DNS may need a few seconds; Ctrl+C to stop)", file=sys.stderr)
114
+ code = proc.wait()
115
+ if not found:
116
+ sys.stderr.write("".join(log[-20:]))
117
+ print(f"cloudflared exited with code {code}", file=sys.stderr)
118
+ return code or 1
119
+ except KeyboardInterrupt:
120
+ return 0
121
+ finally:
122
+ if proc.poll() is None:
123
+ proc.terminate()
124
+ try:
125
+ proc.wait(timeout=5)
126
+ except subprocess.TimeoutExpired:
127
+ proc.kill()
128
+ server.shutdown()
129
+
130
+
131
+ if __name__ == "__main__":
132
+ sys.exit(main())
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cf-share-file"
7
+ version = "0.1.0"
8
+ description = "Share a single file through a Cloudflare quick tunnel."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ dependencies = []
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Topic :: Utilities",
20
+ ]
21
+
22
+ [project.urls]
23
+ Repository = "https://github.com/gabrys/cf-share-file"
24
+ Issues = "https://github.com/gabrys/cf-share-file/issues"
25
+
26
+ [project.scripts]
27
+ cf-share-file = "cf_share_file:main"
28
+
29
+ [tool.setuptools]
30
+ py-modules = ["cf_share_file"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,22 @@
1
+ import subprocess
2
+ import sys
3
+ import unittest
4
+
5
+
6
+ class CommandTests(unittest.TestCase):
7
+ def test_help_without_cloudflared(self):
8
+ result = subprocess.run(
9
+ [sys.executable, "-m", "cf_share_file", "--help"],
10
+ capture_output=True, text=True, check=False,
11
+ )
12
+ self.assertEqual(result.returncode, 0)
13
+ self.assertIn("--auth", result.stdout)
14
+ self.assertIn("--port", result.stdout)
15
+
16
+ def test_missing_file_is_rejected(self):
17
+ result = subprocess.run(
18
+ [sys.executable, "-m", "cf_share_file", "nonexistent-file-for-test"],
19
+ capture_output=True, text=True, check=False,
20
+ )
21
+ self.assertEqual(result.returncode, 2)
22
+ self.assertIn("not a file", result.stderr)