Skip to main content

PyCircularBuffer

  • License : MIT

Summary

Simple circular buffer written in python extension.

CircularBuffer will allocate requested size + 2 bytes for two sections of null terminated strings.

May temporary allocate another half of the allocated bytes if you used buffer protocol, I mostly used them for regex.

Installation

Simply pip install pycircularbuffer, compilation from downloaded source is probably needed.

Using

from circularbuffer import CircularBuffer

buf = CircularBuffer(1024)

buf.write(b'some text')
while len(buf) > 0:
    buf.read(1)

from re import match

buf.write(b'hallo')

# python2
with buf:
    match_found = match(br'^ha', buf)

# python3
match_found = match(br'^ha', buf)

# use `result` immediately because regex didn't make memory copy of the
# internal buffer, or run another `match()` on a memory copy, for example:

match_found_str = buf.read(len(match_found.group(0)))
independent_match_found = match(br'^ha', match_found_str)

Warning

Don’t to this in python 3: ‘a’ in buf, instead: b’a’ in buf.

Check the return value of write() which is the actual length that was written into the buffer and also the exception that might be raised.

API

Regular methods:

  • clear()

  • read()

  • resize()

  • write()

  • write_available()

  • make_contiguous()

String methods:

  • count()

  • startswith()

  • find()

  • index()

Sequence methods:

  • __contains__()

  • __getitem__()

  • __len__()

  • __setitem__()

Magic methods:

  • __repr__()

  • __str__()

    Note: while string representation makes thing easier it always creates memory copy.

  • __enter__()

  • __exit__()

Buffer protocol:

Note: for python version < 3, you need to use context manager, the with statement, to let CircularBuffer know when you are releasing the buffer.

Using buffer protocol will throw ReservedError exception for CircularBuffer.read().

Metadata

Release files for pycircularbuffer 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycircularbuffer 0.0.9
File Size Uploaded Provenance Actions
pycircularbuffer-0.0.9.tar.gz 11.4 kB Without provenance Details for pycircularbuffer-0.0.9.tar.gz

Release files / pycircularbuffer-0.0.9.tar.gz

Download URL pycircularbuffer-0.0.9.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
189bc8793a8e9ec6de83332a5480613c63d48a5faf73235d75669aafd00504dc
BLAKE2b-256 checksum
How to use checksums
0012d37a1cb39f2388ba0d75b7a7b3f4144988605cf570bed8ddef7b810f56ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Security for pycircularbuffer 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page