Skip to main content

Replacement or alternative for python copyfile() utilizing server side copy on network shares for faster copying.

Project description

speedcopy

Build Status PyPI version

Patched python shutil.copyfile using native call CopyFile2 on windows to accelerate transfer on windows shares. On Linux, it issues special ioctl command CIFS_IOC_COPYCHUNK_FILE to enable server-side copy.

This works only when both source and destination files are on same SMB1(CIFS)/2/3 filesystem.

See https://wiki.samba.org/index.php/Server-Side_Copy

Installation

Add speedcopy to PYTHONPATH or:

pip install speedcopy

Usage

If you want to monkeypatch shutil.copyfile() then:

import shutil
import speedcopy

speedcopy.patch_copyfile()

# your code ...
shutil.copyfile(src, dst)

This will make last call to use speedcopy.

Direct use:

import speedcopy

# some code ...

speedcopy.copyfile(src, dst)

There is also debug mode enabled by setting speedcopy.SPEEDCOPY_DEBUG = True. This will print more information during runtime.

Benchmark

Windows

Filesize Python Speedcopy Factor
1 0.0797 0.0222 3.59
2 0.1702 0.0254 6.69
4 0.3257 0.0271 12.01
8 0.6729 0.0337 19.94
16 1.335 0.0384 34.72
32 2.3612 0.0625 37.72
64 57.4549 0.9758 58.88
128 10.9294 0.1669 65.47
256 20.3843 2.276 8.96
512 35.9462 3.9966 8.99
1024 65.6285 28.0291 2.34

Linux

Filesize Python Speedcopy Factor
1 0.0682 0.0099 6.88
2 0.0894 0.0105 8.51
4 0.1337 0.012 11.14
8 0.1922 0.0145 13.25
16 0.2853 0.0193 14.78
32 0.4724 0.0288 16.4
64 8.0071 0.4724 16.94
128 1.3338 0.2311 5.77
256 2.6599 0.4788 5.55
512 5.3798 0.9796 5.49
1024 10.3328 2.9180 3.54

Note that Windows and Linux timing do not correlate, they are taken from different systems. Notice the spike on 64 Mb size file on both of them. Also note that these figures are not taken from production grade hardware and setup and can be completely off at other places.

You can test it yourself with included benchmark.py (and this will take some time as values are measured multiple times and then averaged).

Todo

  • Better error handling
  • Other platforms support
  • Conform behaviour to original shutil.copyfile()
  • Review benchmark code

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

speedcopy-2.1.5.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

speedcopy-2.1.5-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file speedcopy-2.1.5.tar.gz.

File metadata

  • Download URL: speedcopy-2.1.5.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for speedcopy-2.1.5.tar.gz
Algorithm Hash digest
SHA256 9d6c482300791f02462ad451730ae247901978eae9e25290ca352de964698c82
MD5 8500c40396838db9840502284cec1de0
BLAKE2b-256 5d64f4a9715998e4d9b0d679b8ac418c418bb8d4e4d30082390b7dd86aa1bad4

See more details on using hashes here.

File details

Details for the file speedcopy-2.1.5-py3-none-any.whl.

File metadata

  • Download URL: speedcopy-2.1.5-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for speedcopy-2.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 903d0b466c2bef7c07dfac17493cdfbc09aadd70e947199c81caa6c6da2c095f
MD5 f9bf46da1905aba6e5f6146dfa1b7af7
BLAKE2b-256 bbe9072654390b47e33fc84bc8fb593617d4b34431b6e78aa203d40343ae269a

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