catboxpy
is a Python wrapper for Catbox, which allows you to easily upload files, manage albums, and interact with the Catbox service. This package supports both synchronous
and asynchronous usage
.
You can easily install the stable version of catboxpy
from PyPI using pip:
pip install catboxpy
Alternatively, if you wish to access the latest (potentially unstable) version directly from the GitHub repository, you can execute the following command:
pip install git+https://github.com/anshonweb/catboxpy.git
- Upload files to Catbox.
- Create and manage albums (synchronous and asynchronous support).
- Delete files from Catbox.
- Both synchronous and asynchronous methods for flexible usage.
To install catboxpy
, simply use pip:
pip install catboxpy
The synchronous interface is simple to use for blocking operations. Here is how to use it:
from catboxpy.catbox import CatboxClient
client = CatboxClient(userhash="your_userhash_here")
file_url = client.upload("path/to/your/file.jpg")
print(f"File uploaded to: {file_url}")
You can upload files directly from a URL:
url = client.upload('https://example.com/your_image.jpg')
print(f"URL uploaded to: {url}")
To create an album:
album_url = client.album.create("My Album", "Album description", ["file1.jpg", "file2.jpg"])
print(f"Album created at: {album_url}")
To delete a file by its URL:
client.delete_file("file_url")
The asynchronous interface allows you to perform operations without blocking the execution of other tasks, making it ideal for applications that need to handle multiple requests concurrently.
import asyncio
from catboxpy.catbox import AsyncCatboxClient
async def upload_file():
client = AsyncCatboxClient(userhash="your_userhash_here")
file_url = await client.upload("path/to/your/file.jpg")
print(f"File uploaded to: {file_url}")
# Running the async function
asyncio.run(upload_file())
import asyncio
from catboxpy.catbox import AsyncCatboxClient
async def upload_url():
client = AsyncCatboxClient(userhash="your_userhash_here")
url = await client.upload('https://example.com/your_image.jpg')
print(f"URL uploaded to: {url}")
# Running the async function
asyncio.run(upload_url())
import asyncio
from catboxpy.catbox import AsyncCatboxClient
async def create_album():
client = AsyncCatboxClient(userhash="your_userhash_here")
album_url = await client.album.create("My Album", "Album description", ["file1.jpg", "file2.jpg"])
print(f"Album created at: {album_url}")
# Running the async function
asyncio.run(create_album())
import asyncio
from catboxpy.catbox import AsyncCatboxClient
async def delete_file():
client = AsyncCatboxClient(userhash="your_userhash_here")
await client.delete_file("file_url")
# Running the async function
asyncio.run(delete_file())
from catboxpy import LitterboxClient
uploader = LitterboxClient()
try:
url = uploader.upload_file("filepath", expire_time="1h")
print(f"Uploaded to: {url}")
except Exception as e:
print(f"Upload failed: {e}")
For most operations, such as uploading or managing albums, you need a valid userhash. You can obtain the userhash
by logging in to Catbox and accessing your user settings.
- If you're performing anonymous uploads, you can omit the
userhash
. However, operations like creating and managing albums require a validuserhash
.
- Album Limitations: Catbox albums currently allow a maximum of 500 files. This limit may change in the future.
- Anonymous Albums: Anonymous albums cannot be edited or deleted, and they also cannot contain more than 500 files.
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, bugs, or suggestions, please open an issue on the GitHub repository.