### Install catboxpy from GitHub Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Install the latest version of catboxpy directly from its GitHub repository. This is useful for accessing the newest features or contributing to the project. ```bash pip install git+https://github.com/anshonweb/catboxpy.git ``` -------------------------------- ### Install catboxpy using pip Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Install the catboxpy package from PyPI for stable releases. This command uses pip to download and install the library and its dependencies. ```bash pip install catboxpy ``` -------------------------------- ### Litterbox File Upload with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Upload a file using the Litterbox service, which provides temporary file storage. This example shows how to upload a file and specify an expiration time. ```python 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}") ``` -------------------------------- ### Synchronous Album Creation with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Create a new album on Catbox with a specified name, description, and list of files using the synchronous client. Requires authentication. Returns the URL of the created album. ```python from catboxpy.catbox import CatboxClient client = CatboxClient(userhash="your_userhash_here") album_url = client.album.create("My Album", "Album description", ["file1.jpg", "file2.jpg"]) print(f"Album created at: {album_url}") ``` -------------------------------- ### Python: Create Album on Catbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Creates a new album on Catbox.moe with a title, description, and a list of uploaded file URLs. Requires the `catboxpy` library and a userhash for authentication. Albums can contain up to 500 files. Returns the URL of the created album. ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") # Upload multiple files first file_urls = [] for filepath in ["/path/to/photo1.jpg", "/path/to/photo2.jpg", "/path/to/photo3.jpg"]: try: url = client.upload(filepath) file_urls.append(url) except Exception as e: print(f"Failed to upload {filepath}: {e}") # Create album with uploaded files try: album_url = client.album.create( title="My Photo Collection", desc="Vacation photos from summer 2024", files=file_urls ) print(f"Album created: {album_url}") # Output: Album created: https://catbox.moe/c/abc123 except Exception as e: print(f"Album creation failed: {e}") ``` -------------------------------- ### POST /catbox.moe/album/create (Synchronous Album Creation) Source: https://context7.com/anshonweb/catboxpy/llms.txt Creates a new album on Catbox.moe with a title, description, and a list of uploaded file URLs. Requires authentication with userhash. ```APIDOC ## POST /catbox.moe/album/create (Album Creation) ### Description Creates a new album on Catbox.moe. The album can contain a title, description, and a list of file URLs that have already been uploaded. Requires authentication with userhash. ### Method POST ### Endpoint `/catbox.moe/album/create` ### Parameters #### Query Parameters - **userhash** (string) - Required - Your userhash for authenticated operations. #### Request Body - **title** (string) - Required - The title of the album. - **desc** (string) - Optional - The description of the album. - **files** (array of strings) - Required - A list of file URLs to include in the album. ### Request Example ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") # Assuming file_urls are obtained from previous uploads file_urls = ["https://files.catbox.moe/file1.jpg", "https://files.catbox.moe/file2.jpg"] album_url = client.album.create( title="My Photo Collection", desc="Vacation photos from summer 2024", files=file_urls ) ``` ### Response #### Success Response (200) - **url** (string) - The URL of the newly created album. #### Response Example ```json { "url": "https://catbox.moe/c/abc123" } ``` ``` -------------------------------- ### Asynchronous Album Creation with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Create a new album on Catbox asynchronously. This non-blocking method allows other tasks to run while the album is being created. Returns the URL of the created album. ```python 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}") asyncio.run(create_album()) ``` -------------------------------- ### PUT/POST /catbox.moe/album/{short} (Synchronous Album Management) Source: https://context7.com/anshonweb/catboxpy/llms.txt Manages existing albums on Catbox.moe, including editing details, adding or removing files, and deleting the entire album. Requires authentication with userhash. ```APIDOC ## Album Management Operations (PUT/POST) ### Description Provides endpoints for managing existing albums on Catbox.moe. Operations include editing album details, adding files, removing files, and deleting the entire album. All operations require authentication with a userhash. ### Methods and Endpoints - **Edit Album**: `PUT /catbox.moe/album/{short}` - **Add Files**: `POST /catbox.moe/album/{short}/add` - **Remove Files**: `POST /catbox.moe/album/{short}/remove` - **Delete Album**: `DELETE /catbox.moe/album/{short}` ### Parameters #### Path Parameters - **short** (string) - Required - The short ID of the album (e.g., 'abc123' from `https://catbox.moe/c/abc123`). #### Query Parameters - **userhash** (string) - Required - Your userhash for authenticated operations. #### Request Body (for PUT/POST operations) - **title** (string) - Optional - New title for the album. - **desc** (string) - Optional - New description for the album. - **files** (array of strings) - Optional - List of file URLs to set for the album (for edit) or to add/remove. ### Request Examples ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") album_short = "abc123" # Edit album result = client.album.edit( short=album_short, title="Updated Album Title", desc="Updated description", files=["https://files.catbox.moe/file1.jpg"] ) # Add files additional_files = ["https://files.catbox.moe/file2.jpg"] result = client.album.add_files(short=album_short, files=additional_files) # Remove files files_to_remove = ["https://files.catbox.moe/file1.jpg"] result = client.album.remove_files(short=album_short, files=files_to_remove) # Delete album result = client.album.delete(short=album_short) ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the success of the operation. #### Response Example ```json { "message": "Album updated successfully." } ``` ``` -------------------------------- ### Python: Manage Albums on Catbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Manages existing albums on Catbox.moe, including editing details, adding/removing files, and deleting the entire album. Requires the `catboxpy` library and a userhash for authentication. Operations use the 6-character album ID (short). ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") # Edit an existing album (short is the 6-character album ID from URL) try: album_short = "abc123" # From https://catbox.moe/c/abc123 new_files = ["https://files.catbox.moe/file1.jpg", "https://files.catbox.moe/file2.jpg"] result = client.album.edit( short=album_short, title="Updated Album Title", desc="Updated description", files=new_files ) print(f"Album updated: {result}") # Add more files to existing album additional_files = ["https://files.catbox.moe/file3.jpg"] result = client.album.add_files(short=album_short, files=additional_files) print(f"Files added: {result}") # Remove specific files from album files_to_remove = ["https://files.catbox.moe/file1.jpg"] result = client.album.remove_files(short=album_short, files=files_to_remove) print(f"Files removed: {result}") # Delete entire album result = client.album.delete(short=album_short) print(f"Album deleted: {result}") except ValueError as e: print(f"Authentication error: {e}") except Exception as e: print(f"Album operation failed: {e}") ``` -------------------------------- ### Async Album Operations Source: https://context7.com/anshonweb/catboxpy/llms.txt Performs asynchronous operations on albums, including creation, adding files, and editing. Requires uploaded file URLs and album short identifiers. Supports non-blocking album management. ```python import asyncio from catboxpy import AsyncCatboxClient async def manage_album(): client = AsyncCatboxClient(userhash="your_userhash_here") try: # Upload files concurrently files = ["/path/to/img1.jpg", "/path/to/img2.jpg"] upload_tasks = [client.upload(f) for f in files] file_urls = await asyncio.gather(*upload_tasks) # Create album album_url = await client.album.create( title="Async Album", desc="Created asynchronously", files=file_urls ) print(f"Album created: {album_url}") # Extract album short from URL (e.g., "abc123" from "https://catbox.moe/c/abc123") album_short = album_url.split("/")[-1] # Add more files new_file_url = await client.upload("/path/to/img3.jpg") await client.album.add_files(short=album_short, files=[new_file_url]) print(f"Added file to album") # Edit album await client.album.edit( short=album_short, title="Updated Async Album", desc="Modified description", files=file_urls + [new_file_url] ) print("Album updated") except Exception as e: print(f"Album operation failed: {e}") asyncio.run(manage_album()) ``` -------------------------------- ### Async URL Upload Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads files from provided URLs asynchronously. Takes a list of URLs as input and returns the corresponding upload URLs. Optimized for high-performance uploads. ```python import asyncio from catboxpy import AsyncCatboxClient async def upload_from_urls(): client = AsyncCatboxClient(userhash="your_userhash_here") urls = [ "https://example.com/image1.jpg", "https://example.com/image2.png", "https://example.com/image3.gif" ] try: # Upload all URLs concurrently upload_tasks = [client.upload(url) for url in urls] uploaded_urls = await asyncio.gather(*upload_tasks) for original, uploaded in zip(urls, uploaded_urls): print(f"{original} -> {uploaded}") except Exception as e: print(f"Async URL upload failed: {e}") asyncio.run(upload_from_urls()) ``` -------------------------------- ### Async File Upload Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads multiple files asynchronously using httpx. Requires file paths as input and returns upload URLs or exceptions. Handles concurrent uploads efficiently. ```python import asyncio from catboxpy import AsyncCatboxClient async def upload_multiple_files(): client = AsyncCatboxClient(userhash="your_userhash_here") files = ["/path/to/file1.jpg", "/path/to/file2.png", "/path/to/file3.pdf"] try: # Upload multiple files concurrently tasks = [client.upload(filepath) for filepath in files] results = await asyncio.gather(*tasks, return_exceptions=True) for filepath, result in zip(files, results): if isinstance(result, Exception): print(f"Failed to upload {filepath}: {result}") else: print(f"Uploaded {filepath} to {result}") except Exception as e: print(f"Upload process failed: {e}") # Run the async function asyncio.run(upload_multiple_files()) ``` -------------------------------- ### POST /catbox.moe/upload (Synchronous File Upload from Local Path) Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads a local file to Catbox.moe using the synchronous client. Authentication is optional via userhash. ```APIDOC ## POST /catbox.moe/upload (File Upload - Local Path) ### Description Uploads a local file to Catbox.moe. Returns the URL of the uploaded file. Supports authentication via userhash or anonymous uploads. ### Method POST ### Endpoint `/catbox.moe/upload` ### Parameters #### Query Parameters - **userhash** (string) - Optional - Your userhash for authenticated uploads. #### Request Body - **file** (file) - Required - The local file to upload. ### Request Example ```python from catboxpy import CatboxClient # Authenticated upload client = CatboxClient(userhash="your_userhash_here") file_url = client.upload("/path/to/image.jpg") # Anonymous upload anon_client = CatboxClient() file_url = anon_client.upload("/path/to/document.pdf") ``` ### Response #### Success Response (200) - **url** (string) - The URL of the uploaded file. #### Response Example ```json { "url": "https://files.catbox.moe/abc123.jpg" } ``` ``` -------------------------------- ### Python: Upload Local File to Catbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads a local file to Catbox.moe using the synchronous client. Requires the `catboxpy` library. Handles authenticated uploads with a userhash or anonymous uploads. Returns the URL of the uploaded file. ```python from catboxpy import CatboxClient # Initialize client with optional userhash for authenticated uploads client = CatboxClient(userhash="your_userhash_here") try: # Upload a local file file_url = client.upload("/path/to/image.jpg") print(f"File uploaded successfully: {file_url}") # Output: File uploaded successfully: https://files.catbox.moe/abc123.jpg except Exception as e: print(f"Upload failed: {e}") # Anonymous upload without userhash anon_client = CatboxClient() file_url = anon_client.upload("/path/to/document.pdf") print(f"Anonymous upload: {file_url}") ``` -------------------------------- ### POST /catbox.moe/upload (Synchronous URL Upload) Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads a file directly from a remote URL to Catbox.moe without downloading it locally first. Requires authentication via userhash. ```APIDOC ## POST /catbox.moe/upload (File Upload - URL) ### Description Uploads a file directly from a remote URL to Catbox.moe. Returns the URL of the uploaded file. Requires authentication via userhash. ### Method POST ### Endpoint `/catbox.moe/upload` ### Parameters #### Query Parameters - **userhash** (string) - Required - Your userhash for authenticated uploads. #### Request Body - **url** (string) - Required - The remote URL of the file to upload. ### Request Example ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") remote_url = "https://example.com/images/photo.png" uploaded_url = client.upload(remote_url) ``` ### Response #### Success Response (200) - **url** (string) - The URL of the uploaded file. #### Response Example ```json { "url": "https://files.catbox.moe/xyz789.png" } ``` ``` -------------------------------- ### Python: Upload File from URL to Catbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads a file directly from a URL to Catbox.moe without downloading it locally first. Requires the `catboxpy` library and an optional userhash for authentication. Returns the URL of the uploaded file. ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") try: # Upload from URL remote_url = "https://example.com/images/photo.png" uploaded_url = client.upload(remote_url) print(f"URL uploaded to: {uploaded_url}") # Output: URL uploaded to: https://files.catbox.moe/xyz789.png except Exception as e: print(f"URL upload failed: {e}") ``` -------------------------------- ### Implement Asynchronous File Upload with Retries Source: https://context7.com/anshonweb/catboxpy/llms.txt Defines an asynchronous function `async_upload_with_retry` for uploading files concurrently. It incorporates retry logic with exponential backoff for exceptions, specifically handling `ValueError` separately. Logs errors and retries, raising an exception if all attempts fail. Requires an `AsyncCatboxClient` instance. ```python from catboxpy import AsyncCatboxClient import asyncio import logging # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) async def async_upload_with_retry(client, filepath, max_retries=3): """Upload with retry logic for async operations""" for attempt in range(max_retries): try: url = await client.upload(filepath) logger.info(f"Upload successful: {url}") return url except ValueError as e: logger.error(f"Invalid input: {e}") raise # Don't retry on validation errors except Exception as e: logger.warning(f"Attempt {attempt + 1} failed: {e}") if attempt == max_retries - 1: logger.error(f"All {max_retries} attempts failed") raise await asyncio.sleep(2 ** attempt) # Usage example: # async def main(): # client = AsyncCatboxClient(userhash="your_userhash") # try: # url = await async_upload_with_retry(client, "/path/to/async_file.png") # except Exception as e: # logger.error(f"Final upload failure: {e}") # # asyncio.run(main()) ``` -------------------------------- ### Implement Synchronous File Upload with Retries Source: https://context7.com/anshonweb/catboxpy/llms.txt Provides a synchronous function `upload_with_retry` that uploads a file using a provided client instance. It includes a retry mechanism with exponential backoff for handling transient errors during the upload process. Logs warnings for failed attempts and raises an error if all retries are exhausted. ```python from catboxpy import CatboxClient import asyncio import logging # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def upload_with_retry(client, filepath, max_retries=3): """Upload with retry logic for synchronous operations""" for attempt in range(max_retries): try: url = client.upload(filepath) logger.info(f"Upload successful: {url}") return url except Exception as e: logger.warning(f"Attempt {attempt + 1} failed: {e}") if attempt == max_retries - 1: logger.error(f"All {max_retries} attempts failed for {filepath}") raise asyncio.sleep(2 ** attempt) # Exponential backoff # Usage example: # client = CatboxClient(userhash="your_userhash") # try: # url = upload_with_retry(client, "/path/to/file.jpg") # except Exception as e: # logger.error(f"Final upload failure: {e}") ``` -------------------------------- ### Synchronous File Upload with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Upload a local file to Catbox using the synchronous client. Requires a userhash for authenticated uploads. Returns the URL of the uploaded file. ```python 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}") ``` -------------------------------- ### Upload Files with Expiration using Catboxpy Source: https://context7.com/anshonweb/catboxpy/llms.txt Demonstrates uploading files with specific expiration times ('1h', '72h') and default expiration using the catboxpy uploader. Includes handling for potential ValueErrors, FileNotFoundError, and RuntimeErrors during the upload process. ```python from catboxpy import CatboxClient # Assuming 'uploader' is an instance of CatboxClient or a similar uploader class uploader = CatboxClient(userhash="your_userhash") # Example initialization # Valid expiration times: "1h", "12h", "24h", "72h" try: # Upload with 1 hour expiration url = uploader.upload_file("/path/to/temporary_file.zip", expire_time="1h") print(f"Temporary file uploaded: {url}") print("File will expire in 1 hour") # Upload with 72 hour expiration (maximum) url = uploader.upload_file("/path/to/document.pdf", expire_time="72h") print(f"File uploaded (expires in 72h): {url}") # Default is 24 hours url = uploader.upload_file("/path/to/image.jpg") print(f"File uploaded with default 24h expiration: {url}") except ValueError as e: print(f"Invalid expiration time: {e}") except FileNotFoundError as e: print(f"File not found: {e}") except RuntimeError as e: print(f"Upload failed: {e}") except Exception as e: print(f"Unexpected error: {e}") ``` -------------------------------- ### Synchronous URL Upload with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Upload a file from a given URL to Catbox using the synchronous client. This is useful for transferring existing online content. Returns the URL of the uploaded file. ```python from catboxpy.catbox import CatboxClient client = CatboxClient(userhash="your_userhash_here") url = client.upload('https://example.com/your_image.jpg') print(f"URL uploaded to: {url}") ``` -------------------------------- ### Async File Deletion Source: https://context7.com/anshonweb/catboxpy/llms.txt Deletes single or multiple files asynchronously from Catbox. Accepts a single filename string or a list of filenames. Returns deletion status. Requires authentication. ```python import asyncio from catboxpy import AsyncCatboxClient async def delete_files(): client = AsyncCatboxClient(userhash="your_userhash_here") try: # Delete a single file result = await client.delete_file("abc123.jpg") print(f"Single file deletion: {result}") # Delete multiple files at once files_to_delete = ["file1.jpg", "file2.png", "file3.pdf"] result = await client.delete_file(files_to_delete) print(f"Multiple files deletion: {result}") except ValueError as e: print(f"Authentication required: {e}") except Exception as e: print(f"Deletion failed: {e}") asyncio.run(delete_files()) ``` -------------------------------- ### Temporary File Upload with Litterbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Uploads files with automatic expiration using the Litterbox service. This method does not require authentication and is suitable for temporary file sharing. ```python from catboxpy import LitterboxClient uploader = LitterboxClient() # Example usage (assuming you have a file to upload): uploader.upload("/path/to/temporary_file.txt") ``` -------------------------------- ### Asynchronous URL Upload with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Upload a file from a URL to Catbox using the asynchronous client. This non-blocking operation is efficient for web applications. Returns the URL of the uploaded file. ```python 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}") asyncio.run(upload_url()) ``` -------------------------------- ### Asynchronous File Upload with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Upload a local file to Catbox using the asynchronous client. This method is non-blocking and suitable for concurrent applications. Returns the URL of the uploaded file. ```python 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}") asyncio.run(upload_file()) ``` -------------------------------- ### Synchronous File Deletion with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Delete a file from Catbox using its URL and the synchronous client. Requires authentication. This operation permanently removes the file. ```python from catboxpy.catbox import CatboxClient client = CatboxClient(userhash="your_userhash_here") client.delete_file("file_url") ``` -------------------------------- ### DELETE /catbox.moe/file/{filename} (Synchronous File Deletion) Source: https://context7.com/anshonweb/catboxpy/llms.txt Deletes one or more files from Catbox.moe using their filenames. Requires authentication with userhash. ```APIDOC ## DELETE /catbox.moe/file/{filename} (File Deletion) ### Description Deletes a specific file from Catbox.moe using its filename. This operation requires authentication with a userhash. ### Method DELETE ### Endpoint `/catbox.moe/file/{filename}` ### Parameters #### Path Parameters - **filename** (string) - Required - The name of the file to delete (e.g., 'abc123.jpg'). Do not include the full URL. #### Query Parameters - **userhash** (string) - Required - Your userhash for authenticated operations. ### Request Example ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") filename = "abc123.jpg" # e.g., from https://files.catbox.moe/abc123.jpg result = client.delete_file(filename) ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the success of the deletion. #### Response Example ```json { "message": "File abc123.jpg deleted successfully." } ``` ``` -------------------------------- ### Python: Delete File from Catbox Source: https://context7.com/anshonweb/catboxpy/llms.txt Deletes one or more files from Catbox.moe using their filenames. Requires the `catboxpy` library and a userhash for authentication. The filename should be extracted from the full URL. ```python from catboxpy import CatboxClient client = CatboxClient(userhash="your_userhash_here") try: # Delete a single file by filename (not full URL) filename = "abc123.jpg" # Extract from https://files.catbox.moe/abc123.jpg result = client.delete_file(filename) print(f"File deletion result: {result}") except ValueError as e: print(f"Userhash required: {e}") except Exception as e: print(f"Deletion failed: {e}") ``` -------------------------------- ### Asynchronous File Deletion with catboxpy Source: https://github.com/anshonweb/catboxpy/blob/main/README.md Delete a file from Catbox using its URL asynchronously. This non-blocking operation is ideal for high-concurrency applications. Permanently removes the file. ```python import asyncio from catboxpy.catbox import AsyncCatboxClient async def delete_file(): client = AsyncCatboxClient(userhash="your_userhash_here") await client.delete_file("file_url") asyncio.run(delete_file()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.