Indices and tables

Quickstart

Installation

pip install tuspy

Now you are ready to use the api.

from tusclient import client

# Set Authorization headers if it is required
# by the tus server.
my_client = client.TusClient('http://master.tus.io/files/',
                              headers={'Authorization': 'Basic xxyyZZAAbbCC='})

# set more headers
my_client.set_headers({'HEADER_NAME': 'HEADER_VALUE'})

uploader = my_client.uploader('path/to/file.ext', chunk_size=200)

# A file stream may also be passed in place of a file path.
fs = open('path/to/file.ext')
uploader = my_client.uploader(file_stream=fs, chunk_size=200)

# upload a chunk i.e 200 bytes
uploader.upload_chunk()

# uploads the entire file.
# This uploads chunk by chunk.
uploader.upload()

# you could increase the chunk size to reduce the
# number of upload_chunk cycles.
uploader.chunk_size = 800
uploader.upload()

# Continue uploading chunks till total chunks uploaded reaches 1000 bytes.
uploader.upload(stop_at=1000)

If the upload url is known and the client headers are not required, uploaders can also be used standalone.

from tusclient.uploader import Uploader

my_uploader = Uploader('path/to/file.ext',
                        url='http://master.tus.io/files/abcdef123456',
                        chunk_size=200)

URL Storage

There is a simple filestorage implementation available to save upload URLs.

from tusclient.uploader import Uploader
from tusclient.storage import filestorage

storage = filestorage.FileStorage('storage_file')
my_uploader = Uploader('path/to/file.ext', store_url=True, url_storage=storage)
my_uploader.upload()

While the filestorage is implemented for simple usecases, you may create your own custom storage class by implementing the tusclient.storage.interface.Storage interface.