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.0-cp312-cp312-manylinux_2_34_x86_64.whl (267.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

rustflight-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (268.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

rustflight-0.1.0-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.0-cp39-cp39-manylinux_2_34_x86_64.whl (268.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

rustflight-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl (268.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

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

File metadata

File hashes

Hashes for rustflight-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e0d9d410ea2e50817df036da2e9dc78f273574ae9eaaf77e8c952711e448799e
MD5 64d0cc5d22f13a095e8c7944144ccfa0
BLAKE2b-256 bf5653872e03c24de4ec880ec3858142647351804689b768654ce6f583fb3e64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustflight-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f9e4da30b97cdc0438ea7eb615260efb0ea92d0fa1a303a317c0c7a5b467ec6
MD5 60406bce9eb257d7291cc6eb9ab9af78
BLAKE2b-256 1f63a60710f473968623e3e2b9a0cdcba6b8469b25716dbd42dda59728a02d29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustflight-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 76252de735a00b44adbffc93a364c854e85c423155f84f09601ede57d977cb9d
MD5 fdf0105a15235dbc16e513adbf95c54e
BLAKE2b-256 0ad53a08df6b9aa98995bb175720558d01199bdc08bb7d390f7e0a0d331a17df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustflight-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ed736d160dc20058006d08333a899d5623ede40f7e5c48e3893b229d18c00b70
MD5 6b3092c2203ac649f7553a10e7b7bca8
BLAKE2b-256 f251402037759aae6c6ef93bef86d8c03ad86238d90599ccad13fac09627a8a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustflight-0.1.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f026fbd82dc3b8e129252899f2bccecd884cab82115eeee867d2308bf3629aa
MD5 b9b6c6f150ce1deb8e5b70cda95368f3
BLAKE2b-256 f15f3fb9a09d76b7940758a33ca87f50c0ff02a6e812c24025e41ff095cd1d6d

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