Skip to main content

No project description provided

Project description

rustflight

License: MIT PyPI

A fast, Rust-powered Python package for inflight deduplication of multithreaded requests.

Overview

Rustflight implements inflight deduplication of multithreaded requests in python.

Installation

Install from PyPI with:

pip install rustflight

Example Usage

import asyncio
import datetime as dt
import random
import time
from typing import Callable

from rustflight import PyCache

cache = PyCache(timeout=5000)  # Wait 5 seconds


def call_with_cache(func: Callable):
    def wrapper(*args, **kwargs):
        entry_key = str(
            hash(args + tuple(kwargs.items()))
        )  # -> Arbitrary hashing logic
        result = cache.py_call(func, args, kwargs, entry_key)
        return result

    return wrapper


@call_with_cache
def get_random_number_after_seconds(lower, upper, seconds, **kwargs) -> int:
    print("Starting sleep...")
    time.sleep(seconds)
    print("Sleep ended!")
    number = random.randint(lower, upper)
    return number * kwargs.get("multiplier", 1)


async def run_in_parallel():
    start = dt.datetime.now()

    # Launch both calls concurrently
    results = await asyncio.gather(
        asyncio.to_thread(get_random_number_after_seconds, 1, 10, 1, multiplier=100),
        asyncio.to_thread(get_random_number_after_seconds, 1, 10, 1, multiplier=100),
    )

    time_for_first_two_calls = dt.datetime.now()
    third_number = get_random_number_after_seconds(1, 10, 1, multiplier=100)
    end = dt.datetime.now()

    # Assertions and results
    assert results[0] == results[1] == third_number, "Unexpected: %s, %s, %s" % (results[0], results[1], third_number)

    print("Time for first two calls: %ss" % (time_for_first_two_calls - start).seconds)
    print("Total time: %ss" % (end - start).seconds)


if __name__ == "__main__":
    asyncio.run(run_in_parallel())

License

This project is licensed under the MIT License – see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rustflight-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl (267.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

rustflight-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl (268.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

rustflight-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl (268.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

rustflight-0.1.1-cp39-cp39-manylinux_2_34_x86_64.whl (268.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

rustflight-0.1.1-cp38-cp38-manylinux_2_34_x86_64.whl (268.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

Details for the file rustflight-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rustflight-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 db49ad17dd705b14ab084305726f70bd1a25e11fca0b1b600672d931cd0408f3
MD5 1bd4cbaf89a4302f1d69313c95feb185
BLAKE2b-256 445a8136f0b31318d845f80ef4ebd04625f09b4c6eb4509a9fd33bcc6f37c1c3

See more details on using hashes here.

File details

Details for the file rustflight-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rustflight-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 34b73c8b8770b12acd48214f6a0a95b97c1ad306b0c175eeb34a8c588429cd51
MD5 3bc9649115ee60470e95709e3367e293
BLAKE2b-256 f540d7cf93fce86454f61cb383a0704adcd83c57ffd4b3749c289c378c89f095

See more details on using hashes here.

File details

Details for the file rustflight-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rustflight-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 55a6f7f4d808c9df00bafe859e6ea6d26d4b6447d7162cfe3cc0b6ffe8e0774b
MD5 e65f1ffffb8174f90d3866d3b220c2c2
BLAKE2b-256 d6e52c33f4e5f5b0c80fefb23227685a665eb20938c73e0f2d05ef60de739ace

See more details on using hashes here.

File details

Details for the file rustflight-0.1.1-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rustflight-0.1.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 192d4bd111c070f2a292205dfc35648ba90e1d686685a0a14d0fec2ea47c905b
MD5 ea1bba21658565b4a62c5eb0673d60c0
BLAKE2b-256 f107bff43b6d36de1243cc6470eefccbb7749d94bba564804201eb5d48358306

See more details on using hashes here.

File details

Details for the file rustflight-0.1.1-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for rustflight-0.1.1-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f6a32abf0abbb1ba399be89591b265dcf4998add05f06e88335e702f92e29880
MD5 a1ca1e5f4af759842548a25e45871356
BLAKE2b-256 dafe6ffec9a6002f95770787993b7b77cda34f190b29115ce61b8009473f6958

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page