Frace - Python Functions in a Race
Welcome to the Frace Project, a powerful Python library designed to execute multiple functions concurrently. Frace ensures rapid and reliable execution by prioritizing latency and aiming for quick success across functions intended to accomplish the same goal. Even if some functions encounter failures, others continue to run, offering results as soon as possible.
Key Features
- Resilient Execution: Automatically transitions to alternate functions upon failures, ensuring the best chance of success.
- Concurrency: Executes one function from each bucket concurrently, enhancing overall performance.
- Customizable Timeouts: Allows specific timeouts for individual functions to manage long-running tasks.
- Failure Management: Monitors function performance, optimizing subsequent executions by marking functions that fail.
- Exponential Backoff: Employs exponential backoff for failed functions to prevent system overloads and disables functions that fail repeatedly.
Why Choose Frace?
When dealing with operations that may experience intermittent failures and where getting a result quickly is more important than which function succeeds, Frace is ideal. Its concurrent execution and automatic failover to alternate functions ensure your application remains responsive and reliable.
Frace at a Glance
Frace executes one function from each bucket concurrently, allowing multiple functions to run simultaneously, If a function fails, Frace automatically switches to the next available function in the bucket. This process continues until a successful function is found or all functions in the bucket fail.. while execution if any bucket gives a successful response, the execution stops and returns the result.
Installation
Install the frace package using pip:
$ pip install frace
Or install the latest package directly from GitHub:
$ pip install git+https://github.com/searchX/frace
Handling Failures
Frace automatically handles function failures by attempting to execute the next available function within the defined bucket. If all functions in a bucket fail, a FraceException is raised.
Use Case: Large Language Model Completions
Suppose you need to get a response from large language models and multiple models are available. It doesn't matter which model provides the output as long as it returns quickly. You can use Frace to manage this redundancy efficiently by running calls to different models concurrently, taking the first successful response.
import asyncio
import pytest
from frace import FunctionModel
def get_fast_llm_response():
race_caller = FunctionRaceCaller(max_failures=2, function_timeouts={})
async def llm_model_a():
await asyncio.sleep(1) # Simulate delay for Model A
return "Model A Response"
async def llm_model_b():
await asyncio.sleep(0.5) # Simulate faster delay for Model B
return "Model B Response"
# Register the functions as models
model_a = FunctionModel(id="model_a", func=llm_model_a)
model_b = FunctionModel(id="model_b", func=llm_model_b)
race_caller.register_function(model_a)
race_caller.register_function(model_b)
# Use buckets to create a group of functions to race
buckets = [["model_a", "model_b"]]
# Start the event loop to run the asynchronous function
result = asyncio.run(race_caller.call_functions(buckets))
assert result == "Model B Response" # Expect the fastest function result
Contributing
Frace is an essential tool for achieving resilience in concurrent function execution. Contributions are welcome to extend its capabilities and improve its robustness. Feel free to submit issues or pull requests on GitHub.
Metadata
Release files for frace 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| frace-0.1.0.tar.gz | 9.3 kB | Without provenance | Details for frace-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| frace-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for frace-0.1.0-py3-none-any.whl |
Total release size: 15.7 kB
Release files / frace-0.1.0.tar.gz
| Download URL | frace-0.1.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eec2015702d97c6cf7e375669a772f942c6c689645c7e122cb22a1976f0a1f26
|
|
BLAKE2b-256 checksum How to use checksums |
b567bfe55d7a2e453b52c28d1a2873aed7708a9da96f3a0fbb5ab1d0fec88dfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.2 CPython/3.13.1 Linux/6.12.8-200.fc41.x86_64
|
Release files / frace-0.1.0-py3-none-any.whl
| Download URL | frace-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b4aa7f8ebd6646d34c205a8aad62ad02c07467cde85e601d46ee9a85c3389b4
|
|
BLAKE2b-256 checksum How to use checksums |
62b790f1bc838b1dfc33e4bcb90e3dccc157d045ba17dc92005be2ac862a2350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.22.2 CPython/3.13.1 Linux/6.12.8-200.fc41.x86_64
|
Security for frace 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.