pyzxz v1.0 tested, no known issues

This commit is contained in:
Ulus Vatansever 2025-05-22 22:21:30 +03:00
commit 3bdf277975
5 changed files with 155 additions and 0 deletions

21
LICENSE Normal file
View file

@ -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.

42
README.md Normal file
View file

@ -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

22
pyproject.toml Normal file
View file

@ -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"

3
pyzxz/__init__.py Normal file
View file

@ -0,0 +1,3 @@
from .pyzxz import ZeroXZero
__all__ = ["ZeroXZero"]

67
pyzxz/pyzxz.py Normal file
View file

@ -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