semvec/pypi-packages huggingface dataset:
cirbreak 0.1.3
A Python library implementing a circuit breaker pattern
Requires Python: >=3.6

# CirBreak

This Python library provides a `circuit_breaker` decorator for implementing the circuit breaker pattern in your applications.

The circuit breaker pattern is a resiliency mechanism that helps protect external dependencies from cascading failures. It works by monitoring the success and failure rates of calls to a function and taking preventive measures to avoid overloading the dependency.

### How it Works

The `circuit_breaker` decorator takes several optional arguments:

* `failure_threshold`: The number of consecutive failures allowed before the circuit opens (defaults to 3).
* `recovery_timeout`: The time window in seconds after which the circuit attempts recovery (defaults to 10).
* `replace_function`:  A function to execute during the circuit open state. This function should accept the same arguments as the decorated function (optional).
* `consecutive`: A flag indicating whether consecutive failures trigger opening (defaults to False).

Here's a basic example of using the decorator:

```python
import time
from cirbreak import circuit_breaker

def replace(number):
    print("Another function", number)

@circuit_breaker(
    failure_threshold=5, recovery_timeout=10, replace_function=replace, consecutive=False
)
def test_circuit_breaker(number):
    if number % 3 == 0:
        raise Exception("Number is divisible by 3")
    else:
        print(number)

for i in range(1, 30):
    try:
        test_circuit_breaker(i)
    except Exception as e:
        print(e)
    time.sleep(1)
```

In this example, the replace function is provided as the replace_function argument to the circuit_breaker decorator. The replacement function should receive the same arguments as the decorated function. This setup allows for custom handling during the circuit open state, such as logging or alternative processing.
python-okx-async-django 0.2.11
Python SDK for OKX async

### Overview
This is an unofficial Python wrapper for the [OKX exchange v5 API](https://www.okx.com/okx-api)

If you came here looking to purchase cryptocurrencies from the OKX exchange, please go [here](https://www.okx.com/).

#### Source code
https://github.com/okxapi/python-okx
#### OKX API Telegram
https://t.me/OKXAPI
#### API trading tutorials
- Spot trading: https://www.okx.com/help/how-can-i-do-spot-trading-with-the-jupyter-notebook
- Derivative trading: https://www.okx.com/help/how-can-i-do-derivatives-trading-with-the-jupyter-notebook

Make sure you update often and check the [Changelog](https://www.okx.com/docs-v5/log_en/) for new features and bug fixes.

### Features
- Implementation of all Rest API endpoints.
- Private and Public Websocket implementation
- Testnet support 
- Websocket handling with reconnection and multiplexed connections

### Quick start
#### Prerequisites

`python version：>=3.9`

`WebSocketAPI： websockets package advise version 6.0`

#### Step 1: register an account on OKX and apply for an API key
- Register for an account: https://www.okx.com/account/register
- Apply for an API key: https://www.okx.com/account/users/myApi

#### Step 2: install python-okx

```python
pip install python-okx
```

#### Step 3: Run examples

- Fill in API credentials in the corresponding examples
```python 
api_key = ""
secret_key = ""
passphrase = ""
```
- RestAPI
  - For spot trading: run example/get_started_en.ipynb
  - For derivative trading: run example/trade_derivatives_en.ipynb
  - Tweak the value of the parameter `flag` (live trading: 0, demo trading: 1
) to switch between live and demo trading environment
- WebSocketAPI
  - Run test/WsPrivateTest.py for private websocket channels
  - Run test/WsPublicTest.py for public websocket channels
  - Use different URLs for different environment
      - Live trading URLs: https://www.okx.com/docs-v5/en/#overview-production-trading-services
      - Demo trading URLs: https://www.okx.com/docs-v5/en/#overview-demo-trading-services

Note 

- To learn more about OKX API, visit official [OKX API documentation](https://www.okx.com/docs-v5/en/)

- If you face any questions when using `WebSocketAPI`,you can consult the following links

  - `asyncio`、`websockets` document/`github`：

    ```python 
    https://docs.python.org/3/library/asyncio-dev.html
    https://websockets.readthedocs.io/en/stable/intro.html
    https://github.com/aaugustin/websockets
    ```

  - About `code=1006`：

    ```python 
    https://github.com/Rapptz/discord.py/issues/1996
    https://github.com/aaugustin/websockets/issues/587
    ```