cartesia 1.0.1__py2.py3-none-any.whl → 1.0.3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,53 @@
1
+ import os
2
+ import warnings
3
+ from typing import Any, Callable, TypeVar
4
+
5
+ TCallable = TypeVar("TCallable", bound=Callable[..., Any])
6
+
7
+ # List of statistics of deprecated functions.
8
+ # This should only be used by the test suite to find any deprecated functions
9
+ # that should be removed for this version.
10
+ _TRACK_DEPRECATED_FUNCTION_STATS = os.environ.get("CARTESIA_TEST_DEPRECATED", "").lower() == "true"
11
+ _DEPRECATED_FUNCTION_STATS = []
12
+
13
+
14
+ def deprecated(
15
+ reason=None, vdeprecated=None, vremove=None, replacement=None
16
+ ) -> Callable[[TCallable], TCallable]:
17
+ local_vars = locals()
18
+
19
+ def fn(func: TCallable) -> TCallable:
20
+ msg = _get_deprecated_msg(func, reason, vdeprecated, vremove, replacement)
21
+ warnings.warn(msg, DeprecationWarning)
22
+ return func
23
+
24
+ if _TRACK_DEPRECATED_FUNCTION_STATS: # pragma: no cover
25
+ _DEPRECATED_FUNCTION_STATS.append(local_vars)
26
+
27
+ return fn
28
+
29
+
30
+ def _get_deprecated_msg(wrapped, reason, vdeprecated, vremoved, replacement=None):
31
+ fmt = "{name} is deprecated"
32
+ if vdeprecated:
33
+ fmt += " since v{vdeprecated}"
34
+ if vremoved:
35
+ fmt += " and will be removed in v{vremoved}"
36
+ fmt += "."
37
+
38
+ if reason:
39
+ fmt += " ({reason})"
40
+ if replacement:
41
+ fmt += " -- Use {replacement} instead."
42
+
43
+ return fmt.format(
44
+ name=wrapped.__name__,
45
+ reason=reason or "",
46
+ vdeprecated=vdeprecated or "",
47
+ vremoved=vremoved or "",
48
+ replacement=replacement or "",
49
+ )
50
+
51
+
52
+ # This method is taken from the following source:
53
+ # https://github.com/ad12/meddlr/blob/main/meddlr/utils/deprecated.py
@@ -0,0 +1,87 @@
1
+ import time
2
+
3
+ from aiohttp.client_exceptions import ServerDisconnectedError
4
+ import asyncio
5
+ from functools import wraps
6
+ from http.client import RemoteDisconnected
7
+ from httpx import TimeoutException
8
+ from requests.exceptions import ConnectionError
9
+
10
+
11
+ def retry_on_connection_error(max_retries=3, backoff_factor=1, logger=None):
12
+ """Retry a function if a ConnectionError, RemoteDisconnected, ServerDisconnectedError, or TimeoutException occurs.
13
+
14
+ Args:
15
+ max_retries (int): The maximum number of retries.
16
+ backoff_factor (int): The factor to increase the delay between retries.
17
+ logger (logging.Logger): The logger to use for logging.
18
+ """
19
+
20
+ def decorator(func):
21
+ @wraps(func)
22
+ def wrapper(*args, **kwargs):
23
+ retry_count = 0
24
+ while retry_count < max_retries:
25
+ try:
26
+ return func(*args, **kwargs)
27
+ except (
28
+ ConnectionError,
29
+ RemoteDisconnected,
30
+ ServerDisconnectedError,
31
+ TimeoutException,
32
+ ) as e:
33
+ logger.info(f"Retrying after exception: {e}")
34
+ retry_count += 1
35
+ if retry_count < max_retries:
36
+ delay = backoff_factor * (2 ** (retry_count - 1))
37
+ logger.warn(
38
+ f"Attempt {retry_count + 1}/{max_retries} in {delay} seconds..."
39
+ )
40
+ time.sleep(delay)
41
+ else:
42
+ raise Exception(f"Exception occurred after {max_retries} tries.") from e
43
+
44
+ return wrapper
45
+
46
+ return decorator
47
+
48
+
49
+ def retry_on_connection_error_async(max_retries=3, backoff_factor=1, logger=None):
50
+ """Retry an asynchronous function if a ConnectionError, RemoteDisconnected, ServerDisconnectedError, or TimeoutException occurs.
51
+
52
+ Args:
53
+ max_retries (int): The maximum number of retries.
54
+ backoff_factor (int): The factor to increase the delay between retries.
55
+ logger (logging.Logger): The logger to use for logging.
56
+ """
57
+
58
+ def decorator(func):
59
+ @wraps(func)
60
+ async def wrapper(*args, **kwargs):
61
+ retry_count = 0
62
+ while retry_count < max_retries:
63
+ try:
64
+ async for chunk in func(*args, **kwargs):
65
+ yield chunk
66
+ # If the function completes without raising an exception return
67
+ return
68
+ except (
69
+ ConnectionError,
70
+ RemoteDisconnected,
71
+ ServerDisconnectedError,
72
+ TimeoutException,
73
+ ) as e:
74
+ logger.info(f"Retrying after exception: {e}")
75
+ retry_count += 1
76
+ if retry_count < max_retries:
77
+ delay = backoff_factor * (2 ** (retry_count - 1))
78
+ logger.warn(
79
+ f"Attempt {retry_count + 1}/{max_retries} in {delay} seconds..."
80
+ )
81
+ await asyncio.sleep(delay)
82
+ else:
83
+ raise Exception(f"Exception occurred after {max_retries} tries.") from e
84
+
85
+ return wrapper
86
+
87
+ return decorator
cartesia/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.0.1"
1
+ __version__ = "1.0.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cartesia
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: The official Python library for the Cartesia API.
5
5
  Home-page:
6
6
  Author: Cartesia, Inc.
@@ -0,0 +1,11 @@
1
+ cartesia/__init__.py,sha256=jMIf2O7dTGxvTA5AfXtmh1H_EGfMtQseR5wXrjNRbLs,93
2
+ cartesia/_types.py,sha256=msXRqNwVx_mbcLIQgRJYEl8U-hO9LRPWmscnX89cBCY,3747
3
+ cartesia/client.py,sha256=jMlFDPRtKVDelqevHlv7YZJgOES3ws9BFN_6uUyN0W8,32720
4
+ cartesia/version.py,sha256=2plzdEEb24FLjE2I2XyBBcJEPYWHccNL4SgtLC_6erg,22
5
+ cartesia/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ cartesia/utils/deprecated.py,sha256=QSM-ld_g1r-JlT571SSt6-w650jVm9mJmmI2MSScLPw,1599
7
+ cartesia/utils/retry.py,sha256=nuwWRfu3MOVTxIQMLjYf6WLaxSlnu_GdE3QjTV0zisQ,3339
8
+ cartesia-1.0.3.dist-info/METADATA,sha256=y5_HREGB417qL69qMFYtKrIRQAQJ1WDxqObaAg6-V6U,12394
9
+ cartesia-1.0.3.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
10
+ cartesia-1.0.3.dist-info/top_level.txt,sha256=rTX4HnnCegMxl1FK9czpVC7GAvf3SwDzPG65qP-BS4w,9
11
+ cartesia-1.0.3.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- cartesia/__init__.py,sha256=jMIf2O7dTGxvTA5AfXtmh1H_EGfMtQseR5wXrjNRbLs,93
2
- cartesia/_types.py,sha256=msXRqNwVx_mbcLIQgRJYEl8U-hO9LRPWmscnX89cBCY,3747
3
- cartesia/client.py,sha256=jMlFDPRtKVDelqevHlv7YZJgOES3ws9BFN_6uUyN0W8,32720
4
- cartesia/version.py,sha256=d4QHYmS_30j0hPN8NmNPnQ_Z0TphDRbu4MtQj9cT9e8,22
5
- cartesia-1.0.1.dist-info/METADATA,sha256=rwqWm86ez9EzEovMQGPqClXh7U7cTsMGgDwl6DVO42o,12394
6
- cartesia-1.0.1.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
7
- cartesia-1.0.1.dist-info/top_level.txt,sha256=rTX4HnnCegMxl1FK9czpVC7GAvf3SwDzPG65qP-BS4w,9
8
- cartesia-1.0.1.dist-info/RECORD,,