Skip to main content

pyfuncbuffer

Build status pypi pypi license

A simple to use decorator to buffer function calls. Supports python versions 3.7 and up. Works for both regular and async functions.

Install

$ pip install pyfuncbuffer

Example usage

Let's say you have a scraper, and don't want sites to timeout you. You can use the @buffer() wrapper to make your function calls buffered!

from pyfuncbuffer import buffer

# We specify scrape_links to always buffer at least 0.5 seconds
# and by a random delay of 0 to 0.5
@buffer(seconds=0.5, random_delay=0.5)
def scrape_links(url) -> []: ...

links = scrape_links("https://example.org")

while True:
    link = links.pop(0)
    links.append(scrape_links(link))

The @buffer() wrapper works both for regular functions, and instance methods!

Parameters

  • seconds: Required

Seconds to buffer. Can be an int or a float.

  • random_delay: Optional

Seconds to define a random delay between 0 and random_delay. Can be an int or a float. Alternativelly if a tuple is passed, delay is chosen between random_delay[0] and random_delay[1].

  • always_buffer: Optional

Whether or not to always buffer. If specified, buffer_on_same_arguments is ignored.

  • buffer_on_same_arguments: Optional

Only buffer if the arguments on the buffered function are the same. False by default.

  • share_buffer: Optional

Share buffer between processes. This is only useful when using multiprocessing, and still wanting to have function calls buffered even if called in seperate processes.

Testing

Testing is done using pytest and pytest-asyncio.

Run

$ python -m pytest tests/test_pyfuncbuffer.py

in the project root to run all the tests.

Release files for pyfuncbuffer 0.2.2

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

Source distribution (sdist)

Source distribution for pyfuncbuffer 0.2.2
File Size Uploaded
pyfuncbuffer-0.2.2.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfuncbuffer 0.2.2
File Interpreter ABI Platform
pyfuncbuffer-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / pyfuncbuffer-0.2.2.tar.gz

Download URL pyfuncbuffer-0.2.2.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c29234cbeadbdd19e2264ec8f19c11fc22f694bcb655cd50111cac8592946fe4
BLAKE2b-256 checksum
How to use checksums
49d574d9e2c7413d1ebaeb5efffcec89f8f8237f841cda058e06a6e8b259ea60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / pyfuncbuffer-0.2.2-py3-none-any.whl

Download URL pyfuncbuffer-0.2.2-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f517fc18ce2407f0289afdc09b96b29798b657834e13a30979ac46cecca322cd
BLAKE2b-256 checksum
How to use checksums
78d3a880c4817c7b8f213ca87368f5cbddd3f70ed58c388c7d8442f1dfa6ecbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

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