https://github.com/althonos/iocursor

A zero-copy file-like wrapper for Python byte buffers, inspired by Rust's std::io::Cursor.

https://github.com/althonos/iocursor

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary

Keywords

buffer file-like python python-c-extension python-extension sans-io zero-copy
Last synced: 5 months ago · JSON representation

Repository

A zero-copy file-like wrapper for Python byte buffers, inspired by Rust's std::io::Cursor.

Basic Info
  • Host: GitHub
  • Owner: althonos
  • License: mit
  • Language: C
  • Default Branch: master
  • Homepage:
  • Size: 63.5 KB
Statistics
  • Stars: 16
  • Watchers: 2
  • Forks: 2
  • Open Issues: 1
  • Releases: 5
Topics
buffer file-like python python-c-extension python-extension sans-io zero-copy
Created about 5 years ago · Last pushed almost 3 years ago
Metadata Files
Readme Changelog Contributing License

README.md

io‸cursor

A zero-copy file-like wrapper for Python byte buffers, inspired by Rust's std::io::Cursor.

Actions Coverage PyPI Wheel Python Versions Python Implementations License Source GitHub issues Downloads Changelog

🗺️ Overview

iocursor.Cursor lets you wrap an allocated buffer (i.e. a Python object implementing the buffer protocol), and interfacing with it through the API of a file-like object. It shares some common points with io.BytesIO but with the following main differences:

  • zero-copy VS copy: Cursor will not copy the data you give it at initialisation, while BytesIO will. This makes Cursor more efficient when you are using it for read-only operations.
  • static VS growable: Cursor will only use the buffer you give it at static memory, while BytesIO will use its dedicated, growable buffer.

🔧 Installing

Install directly from PyPI, using pip:

console $ pip install iocursor

Pre-built wheels are available on Linux and OSX for all supported Python3 versions. Otherwise, building from source only requires a working C compiler.

🧶 Thread-safety

iocursor.Cursor instances are not thread-safe. Using several Cursor instances with the same backend memory only for reading should be fine. Use a lock when interfacing otherwise.

💡 Examples

  • Use iocursor.Cursor when you have bytes you need to pass to an interface that only accepts file-like objects. For instance, pass a PNG image decoded from base64 to PIL, without copy: ```python import base64 from iocursor import Cursor from PIL import Image

imgdata = base64.b64decode("iVBORw0KGgoAAAANSUhEU...") img = Image.open(Cursor(imgdata)) - Use `iocursor.Cursor` when you want to use the file-like API to write to a buffer of known size. For instance, retrieve a file using the [`pysmb`](https://miketeo.net/blog/projects/pysmb) API, which only accepts file-like objects: python from SMB.SMBConnection import SMBConnectSMBConnection

smb = SMBConnection('guest', '', 'client', 'server') smb.connect("192.168.0.1")

info = smb.getAttributes("Music", "The Clash/Rock the Casbah.mp3") cursor = Cursor(bytearray(sharedfile.filesize)) smb.retrieveFile("Music", "The Clash/Rock the Casbah.mp3", cursor)

buffer = cursor.getvalue() - Use `iocursor.Cursor` when you want to do direct I/O on a type implementing the buffer protocol. For instance, initialize a [`numpy`](https://numpy.org/) [array](https://numpy.org/doc/stable/reference/arrays.html) by writing bytes to it: python import numpy

array = numpy.empty(4, dtype="int16") cursor = Cursor(array) cursor.write(b"\x01\x00\x02\x00\x03\x00\x04\x00") print(array) # array([1, 2, 3, 4], dtype=int16) ```

💭 Feedback

⚠️ Issue Tracker

Found a bug ? Have an enhancement request ? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.

🏗️ Contributing

Contributions are more than welcome! See CONTRIBUTING.md for more details.

⚖️ License

This library is provided under the MIT License.

Owner

  • Name: Martin Larralde
  • Login: althonos
  • Kind: user
  • Location: Heidelberg, Germany
  • Company: EMBL / LUMC, @zellerlab

PhD candidate in Bioinformatics, passionate about programming, SIMD-enthusiast, Pythonista, Rustacean. I write poems, and sometimes they are executable.

GitHub Events

Total
  • Watch event: 3
  • Pull request event: 1
  • Fork event: 1
Last Year
  • Watch event: 3
  • Pull request event: 1
  • Fork event: 1

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 54
  • Total Committers: 1
  • Avg Commits per committer: 54.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Martin Larralde m****e@e****e 54
Committer Domains (Top 20 + Academic)
embl.de: 1

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: about 12 hours
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Holdlang (1)
Pull Request Authors
  • takluyver (2)
Top Labels
Issue Labels
bug (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 364 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 5
  • Total maintainers: 1
pypi.org: iocursor

A zero-copy file-like wrapper for byte buffers, inspired by Rust's std::io::Cursor.

  • Versions: 5
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 364 Last month
Rankings
Dependent packages count: 4.7%
Stargazers count: 16.0%
Average: 16.8%
Downloads: 19.1%
Dependent repos count: 21.7%
Forks count: 22.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/publish.yml actions
  • RalfG/python-wheels-manylinux-build v0.5.0 composite
  • actions/checkout v1 composite
  • actions/checkout v2 composite
  • actions/download-artifact v2 composite
  • actions/setup-python v2 composite
  • actions/setup-python v1 composite
  • actions/upload-artifact v2 composite
  • pypa/gh-action-pypi-publish master composite
  • rasmus-saks/release-a-changelog-action v1.0.1 composite
.github/workflows/test.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v1 composite
setup.py pypi