Skip to main content

A Python client for the tus resumable upload protocol -> http://tus.io

Project description

tus-py-client Build Status

tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of a network issue or server outage.

tus-py-client is a Python client for uploading files using the tus protocol to any remote server supporting it.

Documentation

See documentation here: http://tus-py-client.readthedocs.io/en/latest/

Get started

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://tusd.tusdemo.net/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', mode=)
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://tusd.tusdemo.net/files/abcdef123456',
                       chunk_size=200)

Development

If you want to work on tus-py-client internally, follow these few steps:

  1. Setup virtual environment and install dependencies

    python -m venv env/
    source env/bin/activate
    pip install -e .[test]
    
  2. Running tests

    pytest
    
  3. Releasing a new version (see https://realpython.com/pypi-publish-python-package/)

    # Update version in tusclient/__init__.py
    vim tusclient/__init__.py
    
    # Update changelogs
    vim CHANGELOG.md
    
    pytest
    
    # Commit and tag
    git commit -m 'v1.2.3'
    git tag v1.2.3
    
    # Build and release
    pip install build twine
    python -m build
    twine check dist/*
    twine upload dist/*
    
    # Then: make release on GitHub
    

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuspy-1.0.3.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

tuspy-1.0.3-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file tuspy-1.0.3.tar.gz.

File metadata

  • Download URL: tuspy-1.0.3.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for tuspy-1.0.3.tar.gz
Algorithm Hash digest
SHA256 003d24ee1a310266df507bbff9859120098c026abb5e7b77141292003b0aca12
MD5 492cefec656c00ffb352a8aee00ee4c2
BLAKE2b-256 618cbe3e83d87d8a03d9b6bcb87b394478a52272af367887218c8c7b8abf0611

See more details on using hashes here.

File details

Details for the file tuspy-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: tuspy-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for tuspy-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 024d3d1745120098a85635e42242039ca6b1bc787f561ec974fffb45fc775c1b
MD5 09a2acd0d0de034c1f821ec6c785ae67
BLAKE2b-256 5281ec2c616fc39202911d14e3adc4b2681e8c052a8981574a9f988cdd6b9212

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page