{"id":20312644,"url":"https://github.com/danishprakash/py-splice","last_synced_at":"2025-08-22T22:23:54.677Z","repository":{"id":62583682,"uuid":"149873954","full_name":"danishprakash/py-splice","owner":"danishprakash","description":"A Python interface to splice(2) system call","archived":false,"fork":false,"pushed_at":"2018-12-14T01:04:43.000Z","size":43,"stargazers_count":5,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T12:53:34.694Z","etag":null,"topics":["gnu-linux","python","splice"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danishprakash.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-22T12:16:22.000Z","updated_at":"2024-10-25T18:25:44.000Z","dependencies_parsed_at":"2022-11-03T21:48:55.780Z","dependency_job_id":null,"html_url":"https://github.com/danishprakash/py-splice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishprakash%2Fpy-splice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishprakash%2Fpy-splice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishprakash%2Fpy-splice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danishprakash%2Fpy-splice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danishprakash","download_url":"https://codeload.github.com/danishprakash/py-splice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131465,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gnu-linux","python","splice"],"created_at":"2024-11-14T18:07:07.266Z","updated_at":"2025-04-11T16:51:29.959Z","avatar_url":"https://github.com/danishprakash.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: http://pepy.tech/badge/py-splice\n    :target: http://pepy.tech/project/py-splice/\n    :alt: Downloads\n\n.. image:: https://img.shields.io/pypi/v/py-splice.svg\n    :target: https://pypi.python.org/pypi/py-splice/\n    :alt: Latest version \n\n.. image:: https://img.shields.io/pypi/l/py-splice.svg\n    :target: https://pypi.python.org/pypi/py-splice/\n    :alt: License\n\n\nsplice\n======\n\nA Python interface to splice(2) system call.\n\nAbout\n-----\n`splice(2) \u003chttp://man7.org/linux/man-pages/man2/splice.2.html\u003e`__ moves\ndata between two file descriptors without copying between kernel\naddress space and user address space.  It transfers up to ``nbytes`` bytes\nof data from the file descriptor ``in`` to the file descriptor ``out``.\n\nzero-copy\n---------\nNormally when you copy data from one data stream to another, the data\nto be copied is first stored in a buffer in userspace and is then\ncopied back to the target data stream from the user space which\nintroduces a certain overhead.\n\nzero-copy allows us to operate on data without the use of copying \ndata to userspace. It essentialy transfers the data by remapping pages\nand not actually performing the copying of data, resulting in \nimproved performance.\n\nIllustrated below is a simple example of copying data from one file\nto another using the ``splice(2)`` system call. For the complete documentation\nsee `API Documentation`_.\n\n.. code-block:: python\n\n    # copy data from one file to another using splice\n\n    from splice import splice\n\n    to_read = open(\"read.txt\")\n    to_write = open(\"write.txt\", \"w+\")\n\n    splice(to_read.fileno(), to_write.fileno())\n\n\nThis copying of the data twice (once into the userland buffer, and once out\nfrom that userland buffer) imposes some performance and resource penalties.\n`splice(2) \u003chttp://linux.die.net/man/2/splice\u003e`__ syscall avoids these\npenalties by avoiding any use of userland buffers; it also results in a single\nsystem call (and thus only one context switch), rather than the series of\n`read(2) \u003chttp://linux.die.net/man/2/read\u003e`__ /\n`write(2) \u003chttp://linux.die.net/man/2/write\u003e`__ system calls (each system call\nrequiring a context switch) used internally for the data copying.\n\nInstallation\n------------\n\n**pip**\n\n.. code-block:: sh\n\n    $ pip install py-splice\n\n\n**manual**\n\n.. code-block:: sh\n\n    $ git clone https://github.com/danishprakash/py-splice \u0026\u0026 cd py-splice\n    $ python3 setup.py install\n\n\nAPI Documentation\n-----------------\n\nsendfile module provides a single function: sendfile().\n\n* ``splice.splice(out, in, offset, nbytes, flags)``\n\n  Copy *nbytes* bytes from file descriptor *in* (a regular file) to file\n  descriptor *out* (a regular file) starting at *offset*. Return the number of\n  bytes just being sent. When the end of file is reached return 0.\n  If *offset* is not specified, the bytes are read from the current\n  position of *in* and the position of *in* is updated. If *nbytes* is\n  not specified, the whole of *in* is copied over to *out*.\n\n  **Required arguments**\n  \n  - ``in``: file descriptor of the file from which data is to be read.\n  - ``out``: file descriptor of the file to which data is to be transferred.\n\n  **Optional positional arguments**\n  \n  - ``offset``: offset from where the input file is read from.\n  - ``nbytes``: number of bytes to be copied in total, default value\n  - ``flags``: a bit mask which can be composed by ORing together the following.\n  \n      + ``splice.SPLICE_F_MOVE``\n      + ``splice.SPLICE_F_NONBLOCK``\n      + ``splice.SPLICE_F_MORE``\n      + ``splice.SPLICE_F_GIFT``\n\n  More information on what each of the flag means can be found on the splice(2)\n  man page `here \u003chttp://man7.org/linux/man-pages/man2/splice.2.html\u003e`__.\n\n\nUsage\n-----\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from splice import splice\n\n    # init file objects\n    \u003e\u003e\u003e to_read = open(\"read.txt\") # file to read from\n    \u003e\u003e\u003e to_write = open(\"write.txt\", \"w+\") # file to write to\n\n    \u003e\u003e\u003e len(to_read.read())\n    50\n\n    # copying whole file\n    \u003e\u003e\u003e splice(to_read.fileno(), to_write.fileno())\n    50  # bytes copied\n\n    # copying file starting from an offset\n    \u003e\u003e\u003e splice(to_read.fileno(), to_write.fileno(), offset=10)\n    40\n\n    # copying certain amount of bytes\n    \u003e\u003e\u003e splice(to_read.fileno(), to_write.fileno(), nbytes=20)\n    20\n\n    # copying certain amount of bytes beginning from an offset\n    \u003e\u003e\u003e splice(to_read.fileno(), to_write.fileno(), offset=10, nbytes=20)\n    20\n\n    # specifying flags\n    \u003e\u003e\u003e import splice\n    \u003e\u003e\u003e splice(to_read.fileno(), to_write.fileno(), flags=splice.SPLICE_F_MORE)\n    50\n\n\nWhy would I use this?\n---------------------\n``splice(2)`` is supposed to be better in terms of performance when compared\nto traditional read/write methods since it avoids overhead of copying the\ndata to user address space and instead, does the transfer by remapping pages\nin kernel address space. There can be many uses for this especially if\nperformance is important to the task at hand.\n\n\nSupported platforms\n-------------------\nThe ``splice(2)`` system call is (GNU)Linux-specific.\n\n\nSupport\n-------\nFeel free to add improvements, report issues or contact me about anything related to the project.\n\n\nLICENSE\n-------\nGNU GPL\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanishprakash%2Fpy-splice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanishprakash%2Fpy-splice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanishprakash%2Fpy-splice/lists"}