Skip to main content

Python client for upload to a server supporting resumable.js

Project description

https://travis-ci.org/acroz/resumable.py.svg?branch=master https://coveralls.io/repos/github/acroz/resumable.py/badge.svg?branch=master

resumable.py provides chunked uploading of files to a compatible server, emulating the popular resumable.js JavaScript library.

Installation

resumable.py can be installed from PyPI with pip:

$ pip install resumable

Usage

Construct a Resumable object with the URL of the upload target server, and use add_file() to queue files for upload. It’s recommended to use it as a context manager:

from resumable import Resumable

with Resumable('https://example.com/upload') as session:
    session.add_file('my_file.dat')

You can queue mutiple files for upload in a single session, and the with block will not complete until the upload is finished (or an exception is raised).

It’s also possible to use a Resumable session without a with block, and manually join() the session:

session = Resumable('https://example.com/upload')
session.add_file('my_file.dat')
do_something_else()
session.join()

Backend

resumable.py handles most of the logic needed for resumable file uploads on the client side, but the files still need to be reassembled from chunks on the server side, as in resumable.js. For details on how to set up a compatible backend, please see the resumable.js documentation or the backend samples on GitHub.

Configuration

resumable.py supports a subset of the options provided by resumable.js:

  • target The target URL for the multipart POST request (required)

  • chunk_size The size in bytes of each uploaded chunk of data (default: 1*1024*1024)

  • simultaneous_uploads Number of simultaneous uploads (default: 3)

  • headers Extra headers to include in the multipart POST with data (default: {})

  • test_chunks Make a GET request to the server for each chunks to see if it already exists. If implemented on the server-side, this will allow for upload resumes even after a browser crash or even a computer restart. (default: True)

Some additional low level options are available - these are documented in the docstring of the Resumable class.

Callbacks and Progress Reporting

resumable.py provides the ability to register arbitrary functions as callbacks in response to certain events. These are:

On the Resumable object:

  • file_added Triggered when a file is added, with the file object

  • file_completed Triggered when a file is completed, with the file object

  • chunk_completed Triggered when a chunk is completed, with the file and chunk objects

On a ResumableFile (returned by Resumable.add_file()):

  • completed Triggered when the file is completed, without arguments

  • chunk_completed Triggered when a chunk is completed, with the chunk object

Each of these callback dispatchers has a register() method that you can use to register callbacks. For example, to print a simple progress message that updates as chunks are uploaded:

with Resumable('https://example.com/upload') as session:
    file = session.add_file('my_file.dat')

    def print_progress(chunk):
        template = '\rPercent complete: {:.1%}'
        print(template.format(file.fraction_completed), end='')

    file.chunk_completed.register(print_progress)

print()  # new line

Contribute

resumable.py’s design is informed by resumable.js, however only a core subset of features have yet been implemented. Patches implementing resumable.js features are welcome, and contributors should attempt to retain consistency with the resumable.js interface, mapping JavaScript style and idioms to Python equivalents as appropriate (for example, the simultaneousUploads configuration parameter becomes simultaneous_uploads in Python).

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

resumable-0.1.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

resumable-0.1.1-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file resumable-0.1.1.tar.gz.

File metadata

  • Download URL: resumable-0.1.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for resumable-0.1.1.tar.gz
Algorithm Hash digest
SHA256 57c85753eafc617570918d2c2c24c55898cde09b110054e0dcceb689a00c9b02
MD5 1139431fb254f1701adb35ad79b72b12
BLAKE2b-256 0b059281b5783e9aa0c1b8d14d6444dd5f5aba6e9bc67d0e745754810b2f95d2

See more details on using hashes here.

File details

Details for the file resumable-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for resumable-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f20f7bea5a830abf6bef2f88009c63cb57382c4ae59d21a3494616713ba0e3a7
MD5 ca6fcd72a9f99a788ac76d36c6cc1aa5
BLAKE2b-256 cd72f66381996e14579821a8f488e056b9223e7c58f000aaea76ddc322192488

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