No project description provided
Project description
rustflight
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rustflight-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rustflight-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 267.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db49ad17dd705b14ab084305726f70bd1a25e11fca0b1b600672d931cd0408f3
|
|
| MD5 |
1bd4cbaf89a4302f1d69313c95feb185
|
|
| BLAKE2b-256 |
445a8136f0b31318d845f80ef4ebd04625f09b4c6eb4509a9fd33bcc6f37c1c3
|
File details
Details for the file rustflight-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rustflight-0.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 268.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34b73c8b8770b12acd48214f6a0a95b97c1ad306b0c175eeb34a8c588429cd51
|
|
| MD5 |
3bc9649115ee60470e95709e3367e293
|
|
| BLAKE2b-256 |
f540d7cf93fce86454f61cb383a0704adcd83c57ffd4b3749c289c378c89f095
|
File details
Details for the file rustflight-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rustflight-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 268.5 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55a6f7f4d808c9df00bafe859e6ea6d26d4b6447d7162cfe3cc0b6ffe8e0774b
|
|
| MD5 |
e65f1ffffb8174f90d3866d3b220c2c2
|
|
| BLAKE2b-256 |
d6e52c33f4e5f5b0c80fefb23227685a665eb20938c73e0f2d05ef60de739ace
|
File details
Details for the file rustflight-0.1.1-cp39-cp39-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rustflight-0.1.1-cp39-cp39-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 268.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
192d4bd111c070f2a292205dfc35648ba90e1d686685a0a14d0fec2ea47c905b
|
|
| MD5 |
ea1bba21658565b4a62c5eb0673d60c0
|
|
| BLAKE2b-256 |
f107bff43b6d36de1243cc6470eefccbb7749d94bba564804201eb5d48358306
|
File details
Details for the file rustflight-0.1.1-cp38-cp38-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: rustflight-0.1.1-cp38-cp38-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 268.7 kB
- Tags: CPython 3.8, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6a32abf0abbb1ba399be89591b265dcf4998add05f06e88335e702f92e29880
|
|
| MD5 |
a1ca1e5f4af759842548a25e45871356
|
|
| BLAKE2b-256 |
dafe6ffec9a6002f95770787993b7b77cda34f190b29115ce61b8009473f6958
|