Package: resumable
resumable.py provides chunked uploading of files to a compatible server,
emulating the popularresumable.jsJavaScript library.Installationresumable.py can be installed from PyPI withpip:$pipinstallresumableUsageConstruct aResumableobject with the URL of the upload target server, and
useadd_file()to queue files for upload. It’s recommended to use it as a
context manager:fromresumableimportResumablewithResumable('https://example.com/upload')assession:session.add_file('my_file.dat')You can queue mutiple files for upload in a single session, and thewithblock will not complete until the upload is finished (or an exception is
raised).It’s also possible to use aResumablesession without awithblock, and
manuallyjoin()the session:session=Resumable('https://example.com/upload')session.add_file('my_file.dat')do_something_else()session.join()Backendresumable.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 inresumable.js. For details on how to set up a compatible
backend, please see theresumable.jsdocumentation or the backend sampleson GitHub.Configurationresumable.py supports a subset of the options provided byresumable.js:targetThe target URL for the multipart POST request (required)chunk_sizeThe size in bytes of each uploaded chunk of data (default:1*1024*1024)simultaneous_uploadsNumber of simultaneous uploads (default:3)headersExtra headers to include in the multipart POST with data
(default:{})test_chunksMake 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 theResumableclass.Callbacks and Progress Reportingresumable.py provides the ability to register arbitrary functions as callbacks
in response to certain events. These are:On theResumableobject:file_addedTriggered when a file is added, with the file objectfile_completedTriggered when a file is completed, with the file objectchunk_completedTriggered when a chunk is completed, with the file and
chunk objectsOn aResumableFile(returned byResumable.add_file()):completedTriggered when the file is completed, without argumentschunk_completedTriggered when a chunk is completed, with the chunk
objectEach of these callback dispatchers has aregister()method that you can use
to register callbacks. For example, to print a simple progress message that
updates as chunks are uploaded:withResumable('https://example.com/upload')assession:file=session.add_file('my_file.dat')defprint_progress(chunk):template='\rPercent complete:{:.1%}'print(template.format(file.fraction_completed),end='')file.chunk_completed.register(print_progress)print()# new lineContributeresumable.py’s design is informed byresumable.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, thesimultaneousUploadsconfiguration parameter becomessimultaneous_uploadsin Python).