Skip to main content

Collect objects and apply a function once the buffer is full or expired

Project description

   ___  __  _____________ 
  / _ )/ / / / __/ __/ _ \
 / _  / /_/ / _// _// , _/
/____/\____/_/ /_/ /_/|_| 

buffr: simple buffering mechanism for Python

Testing coverage
Package PyPI Latest Release PyPI Downloads
status dependencies
Meta GitHub License implementation versions
Social tweet xfollow

buffr provides a simple mechanism that allows you to collect values in a buffer. Once a certain time has passed or the buffer's capacity is reached, all values will pe processed with the provided function. As an analogy: don't process each drop, wait till the bucket is full and process that.

pip install buffr

Table of Contents

Main Features

  • 🐍 Pure Python
  • 🖌 Eadily configurable
  • 👨‍🎨 User-friendly

Use case

You listen to a queue for messages that you'll process and insert into the database. If we receive a message each second, this means that we have to perform an insert 60 times a second.

In this case we could use Buffr to collect messages for 30 seconds before batch inserting them. This reduces the number of costly database-operations from 60 per minute to just 2.

Usage Example

Creating a Buffr is easy.

from buffr import Buffr

# Define the processor
def processing_fn(items:List):
    for item in items:
        print(item * 2)

# Create a buffr
buffr = Buffr(max_capacity=100, buffer_ttl=30, flush_func=processing_fn)

# Add some values to the Buffr
for i in range(4):
    buffr.add(i)

The Buffr defined above will flush in three cases:

  1. the capacity of 100 items is exceeded
  2. 30 seconds pass (buffr_ttl)
  3. buffr.flush() is called

Installation

pip install buffr

The source code is currently hosted on GitHub at: https://github.com/mike-huls/buffr

Binary installers for the latest released version are available at the Python Package Index (PyPI).

Dependencies

Buffr has no dependencies

License

MIT

Documentation

🔨 Under construction

Development

Find the changelog and list of upcoming features here.
Contributions are always welcome; feel free to submit bug reports, bug fixes, feature requests, documentation improvements or enhancements!


Go to Top

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

buffr-0.0.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

buffr-0.0.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file buffr-0.0.3.tar.gz.

File metadata

  • Download URL: buffr-0.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.29

File hashes

Hashes for buffr-0.0.3.tar.gz
Algorithm Hash digest
SHA256 dfbc0c863810bd6b77f29e17910a81313671ba4018983a462eda819d39455be6
MD5 ffb13e1608e4cea116163f7cebea56fb
BLAKE2b-256 1f95e048470ea3bb4cfe6786ec9a507b2a65909c863a916874c6a4c7bb02846d

See more details on using hashes here.

File details

Details for the file buffr-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: buffr-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.29

File hashes

Hashes for buffr-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 50fe15eb82fa4f75d44e85255d14e7669500a107d9de138eca85a3c2e6f31997
MD5 f25effc3a9d4f28241192e52b3c04555
BLAKE2b-256 bab32f81f361da349014e2ee3f18db862367af40e22b45aae9a42c245215fe29

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