Skip to main content

Catbox Uploader

Catbox Uploader is a simple Python library to upload files and URLs to Catbox.moe, including its temporary storage feature, Litterbox, and album management.

Installation

pip install catbox-uploader

Usage

Using Userhash

CatboxUploader supports using a userhash directly. You can pass the userhash when initializing the CatboxUploader and use it for authenticated uploads and album management.

Initialize with Userhash

from catbox import CatboxUploader

uploader = CatboxUploader(userhash='your_userhash_here')

Initialize without Userhash

from catbox import CatboxUploader

uploader = CatboxUploader()

Upload a File

link = uploader.upload_file('path/to/your/file.jpg')
print(f'Uploaded file: {link}')

Upload a File to Litterbox (Temporary Storage)

Litterbox allows you to upload files for a temporary period, after which the files will be deleted automatically. Use the upload_to_litterbox method to upload files with a specified expiration time.

Available expiration times:

  • 1h: 1 hour
  • 12h: 12 hours
  • 24h: 24 hours
  • 72h: 3 days
link = uploader.upload_to_litterbox('path/to/your/file.jpg', time='24h')
print(f'Uploaded file (available for 24 hours): {link}')

Upload Multiple Files as an Album

You can upload multiple files as an album to Catbox.moe using the upload_album method. This allows you to upload several files at once, and it will return the links for all uploaded files.

file_paths = ['file1.jpg', 'file2.jpg', 'file3.jpg']
links = uploader.upload_album(file_paths)
for link in links:
    print(f'Uploaded file link: {link}')

Create and Manage Albums

Create an Album

You can create an album with uploaded files, a title, and a description using the create_album method:

album_shortcode = uploader.create_album(file_links, "My Album", "This is a test album")
print(f"Album created: https://catbox.moe/c/{album_shortcode}")

Edit an Album

You can edit an album by changing its title, description, or the files it contains:

uploader.edit_album(album_shortcode, file_links, "Updated Album Title", "Updated description")

Delete an Album

You can delete an album by its shortcode:

uploader.delete_album(album_shortcode)

Error Handling

The library comes with built-in exception handling to manage common errors such as timeouts, connection issues, or HTTP errors.

Handling Timeout

If the upload takes too long and exceeds the specified timeout, a TimeoutError will be raised.

from catbox import CatboxUploader, TimeoutError

uploader = CatboxUploader(userhash='your_userhash_here')
try:
    link = uploader.upload_file('path/to/your/file.jpg', timeout=10)
    print(f'Uploaded file: {link}')
except TimeoutError:
    print("The upload took too long and timed out.")

Handling Connection Issues

If there's a problem connecting to the Catbox.moe or Litterbox server, a ConnectionError will be raised.

from catbox import CatboxUploader, ConnectionError

uploader = CatboxUploader(userhash='your_userhash_here')
try:
    link = uploader.upload_file('path/to/your/file.jpg')
    print(f'Uploaded file: {link}')
except ConnectionError:
    print("Failed to connect to the server.")

Handling HTTP Errors

In case of HTTP errors (such as 404 or 500), an HTTPError will be raised.

from catbox import CatboxUploader, HTTPError

uploader = CatboxUploader(userhash='your_userhash_here')
try:
    link = uploader.upload_file('path/to/your/file.jpg')
    print(f'Uploaded file: {link}')
except HTTPError as he:
    print(f"HTTP error occurred: {he}")

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for catbox-uploader 2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for catbox-uploader 2.9
File Size Uploaded
catbox_uploader-2.9.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for catbox-uploader 2.9
File Interpreter ABI Platform
catbox_uploader-2.9-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / catbox_uploader-2.9.tar.gz

Download URL catbox_uploader-2.9.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b4ee423acd3397dfb14e937ce76aeaa5e304de497ceb21f9cd0f771ff736ad9a
BLAKE2b-256 checksum
How to use checksums
2bee2fa66d2b74cfb2ea00cb0155e57f9bb1ef77e7ee21f0f9470a31cf1c9452
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / catbox_uploader-2.9-py3-none-any.whl

Download URL catbox_uploader-2.9-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ec8a349f917bfd5ed485ac368420a148012e46e5d77a355e887cadf09e7a4c1
BLAKE2b-256 checksum
How to use checksums
9b2aa27d58819333904d3f138595364d559d0cbe22139c9a15c8a40d5140c73d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

2.9 This release

2 release files

2.7

2 release files

2.6

2 release files

2.5

2 release files

2.3

2 release files

2.1

2 release files

2.0

2 release files

1.7

2 release files

1.6

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page