https://github.com/althonos/iocursor
A zero-copy file-like wrapper for Python byte buffers, inspired by Rust's std::io::Cursor.
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
Repository
A zero-copy file-like wrapper for Python byte buffers, inspired by Rust's std::io::Cursor.
Basic Info
Statistics
- Stars: 16
- Watchers: 2
- Forks: 2
- Open Issues: 1
- Releases: 5
Topics
Metadata Files
README.md
io‸cursor
A zero-copy
file-like wrapper
for Python byte buffers,
inspired by Rust's std::io::Cursor.
🗺️ 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:
Cursorwill not copy the data you give it at initialisation, whileBytesIOwill. This makesCursormore efficient when you are using it for read-only operations. - static VS growable:
Cursorwill only use the buffer you give it at static memory, whileBytesIOwill 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.Cursorwhen you havebytesyou 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
- Twitter: althonos
- Repositories: 91
- Profile: https://github.com/althonos
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
Top Committers
| Name | Commits | |
|---|---|---|
| Martin Larralde | m****e@e****e | 54 |
Committer Domains (Top 20 + Academic)
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
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.
- Homepage: https://github.com/althonos/iocursor
- Documentation: https://iocursor.readthedocs.io/
- License: MIT
-
Latest release: 0.1.4
published over 3 years ago
Rankings
Maintainers (1)
Dependencies
- 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
- actions/checkout v1 composite
- actions/setup-python v2 composite
- codecov/codecov-action v1 composite