CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-tuspy

A Python client for the tus resumable upload protocol enabling pause and resume of file uploads

Overview
Eval results
Files

client-management.mddocs/

Client Management

Core client functionality for connecting to tus servers, managing authentication headers, and creating uploader instances. The TusClient class serves as the entry point for all tus protocol operations.

Capabilities

TusClient Class

The main client class for interacting with tus resumable upload servers.

class TusClient:
    """
    Object representation of Tus client.
    
    Attributes:
        url (str): The tus server's create extension URL
        headers (dict): Server-specific headers sent with every request
        client_cert (str | tuple[str, str]): Path to PEM encoded client certificate
    """
    
    def __init__(self, url: str, headers: Optional[Dict[str, str]] = None, 
                 client_cert: Optional[Union[str, Tuple[str, str]]] = None):
        """
        Initialize TusClient.
        
        Parameters:
        - url (str): The tus server's create extension URL
        - headers (Optional[Dict[str, str]]): Custom headers for authentication
        - client_cert (Optional[Union[str, Tuple[str, str]]]): Client certificate path(s)
        """

Header Management

Update client headers for authentication and custom server requirements.

def set_headers(self, headers: Dict[str, str]):
    """
    Set tus client headers.
    
    Update and/or set new headers that would be sent along with every request
    made to the server.
    
    Parameters:
    - headers (dict): Key-value pairs of headers to be set
    """

Uploader Creation

Factory methods for creating uploader instances.

def uploader(self, *args, **kwargs) -> Uploader:
    """
    Return synchronous uploader instance pointing at current client.
    
    Return uploader instance with which you can control the upload of a specific
    file. The current instance of the tus client is passed to the uploader on creation.
    
    Parameters:
    See tusclient.uploader.Uploader for required and optional arguments.
    
    Returns:
    Uploader: Configured uploader instance
    """

def async_uploader(self, *args, **kwargs) -> AsyncUploader:
    """
    Return asynchronous uploader instance pointing at current client.
    
    Parameters:
    See tusclient.uploader.AsyncUploader for required and optional arguments.
    
    Returns:
    AsyncUploader: Configured async uploader instance
    """

Usage Examples

Basic Client Setup

from tusclient import client

# Simple client
my_client = client.TusClient('http://tusd.tusdemo.net/files/')

# Client with authentication headers
my_client = client.TusClient(
    'http://tusd.tusdemo.net/files/',
    headers={'Authorization': 'Bearer your-token-here'}
)

# Client with client certificate
my_client = client.TusClient(
    'https://secure-tus-server.com/files/',
    client_cert='/path/to/client.pem'
)

# Client with certificate and separate key file
my_client = client.TusClient(
    'https://secure-tus-server.com/files/',
    client_cert=('/path/to/client.crt', '/path/to/client.key')
)

Header Management

# Update headers after client creation
my_client.set_headers({'Authorization': 'Bearer new-token'})

# Add additional headers
my_client.set_headers({
    'X-Custom-Header': 'custom-value',
    'X-Upload-Metadata': 'filename dGVzdC5kYXQ='
})

Creating Uploaders

# Create synchronous uploader
uploader = my_client.uploader(
    '/path/to/file.ext',
    chunk_size=1024*1024,
    metadata={'filename': 'test.dat'}
)

# Create asynchronous uploader
async_uploader = my_client.async_uploader(
    '/path/to/file.ext',
    chunk_size=1024*1024,  
    retries=3,
    retry_delay=5
)

Install with Tessl CLI

npx tessl i tessl/pypi-tuspy

docs

client-management.md

exception-handling.md

index.md

request-handling.md

storage-resumability.md

upload-operations.md

tile.json