From 3bdf277975d86477e91e6ade1e4771edc153b3b1 Mon Sep 17 00:00:00 2001 From: Ulus Vatansever Date: Thu, 22 May 2025 22:21:30 +0300 Subject: [PATCH] pyzxz v1.0 tested, no known issues --- LICENSE | 21 +++++++++++++++ README.md | 42 +++++++++++++++++++++++++++++ pyproject.toml | 22 ++++++++++++++++ pyzxz/__init__.py | 3 +++ pyzxz/pyzxz.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 pyzxz/__init__.py create mode 100644 pyzxz/pyzxz.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..992aa52 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Ulus Vatansever + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d1c013f --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# pyzxz + +`pyzxz` is a lightweight Python client library for uploading files and text to [0x0.st](https://0x0.st), a simple and free file hosting service. + +## Features + +- Upload files from disk +- Upload in-memory bytes +- Upload plain text +- Check 0x0.st availability + +## Installation + +```bash +pip install pyzxz +``` + +## Usage + +```python +from pyzxz import ZeroXZero + +# Upload a local file +url = ZeroXZero.upload("path/to/file.txt") +print("Uploaded file URL:", url) + +# Upload bytes from memory +url = ZeroXZero.upload_from_bytes(b"hello world", "hello.txt") +print("Uploaded bytes URL:", url) + +# Upload a text string as a file +url = ZeroXZero.upload_text("Hello from pyzxz!") +print("Uploaded text URL:", url) + +# Check if 0x0.st is online +is_online = ZeroXZero.is_available() +print("0x0.st online?", is_online) +``` + +## License + +MIT License © 2025 Ulus Vatansever \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9805053 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[project] +name = "pyzxz" +version = "0.1.0" +description = "A Python client for 0x0.st file hosting service." +readme = "README.md" +requires-python = ">=3.7" +authors = [ + { name = "cvcvka5", email = "cvcvka5@gmail.com" } +] +license = { file = "LICENSE" } +dependencies = [ + "requests" +] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent" +] + +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/pyzxz/__init__.py b/pyzxz/__init__.py new file mode 100644 index 0000000..80e9672 --- /dev/null +++ b/pyzxz/__init__.py @@ -0,0 +1,3 @@ +from .pyzxz import ZeroXZero + +__all__ = ["ZeroXZero"] \ No newline at end of file diff --git a/pyzxz/pyzxz.py b/pyzxz/pyzxz.py new file mode 100644 index 0000000..08ec3f3 --- /dev/null +++ b/pyzxz/pyzxz.py @@ -0,0 +1,67 @@ +import requests +from pathlib import Path +from typing import Union + + +class ZeroXZero: + """ + A static utility class for interacting with the 0x0.st file hosting service. + + Features: + - Upload files from disk + - Upload in-memory data + - Upload plain text + - Check service availability + """ + + ENDPOINT_URL = "https://0x0.st" + HEADERS = { + "User-Agent": "pyzxz-uploader/1.0 (https://github.com/yourrepo)" + } + + @staticmethod + def upload(file_path: Union[str, Path]) -> str: + file_path = Path(file_path) + + if not file_path.exists(): + raise FileNotFoundError(f"No such file: {file_path}") + + with file_path.open("rb") as f: + response = requests.post( + ZeroXZero.ENDPOINT_URL, + files={"file": f}, + headers=ZeroXZero.HEADERS + ) + + if response.ok and response.text.startswith("https://"): + return response.text.strip() + raise ValueError(f"Upload failed: {response.text.strip()}") + + @staticmethod + def upload_from_bytes(data: bytes, filename: str) -> str: + files = {"file": (filename, data)} + response = requests.post( + ZeroXZero.ENDPOINT_URL, + files=files, + headers=ZeroXZero.HEADERS + ) + + if response.ok and response.text.startswith("https://"): + return response.text.strip() + raise ValueError(f"Upload failed: {response.text.strip()}") + + @staticmethod + def upload_text(text: str, filename: str = "text.txt") -> str: + return ZeroXZero.upload_from_bytes(text.encode("utf-8"), filename) + + @staticmethod + def is_available() -> bool: + try: + response = requests.head( + ZeroXZero.ENDPOINT_URL, + timeout=3, + headers=ZeroXZero.HEADERS + ) + return response.status_code == 200 + except requests.RequestException: + return False