murf 1.0.0__tar.gz
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.
Potentially problematic release.
This version of murf might be problematic. Click here for more details.
- murf-1.0.0/PKG-INFO +169 -0
- murf-1.0.0/README.md +142 -0
- murf-1.0.0/pyproject.toml +64 -0
- murf-1.0.0/src/murf/__init__.py +49 -0
- murf-1.0.0/src/murf/auth/__init__.py +2 -0
- murf-1.0.0/src/murf/auth/client.py +175 -0
- murf-1.0.0/src/murf/base_client.py +144 -0
- murf-1.0.0/src/murf/client.py +118 -0
- murf-1.0.0/src/murf/core/__init__.py +47 -0
- murf-1.0.0/src/murf/core/api_error.py +15 -0
- murf-1.0.0/src/murf/core/client_wrapper.py +65 -0
- murf-1.0.0/src/murf/core/datetime_utils.py +28 -0
- murf-1.0.0/src/murf/core/file.py +67 -0
- murf-1.0.0/src/murf/core/http_client.py +499 -0
- murf-1.0.0/src/murf/core/jsonable_encoder.py +101 -0
- murf-1.0.0/src/murf/core/pydantic_utilities.py +296 -0
- murf-1.0.0/src/murf/core/query_encoder.py +58 -0
- murf-1.0.0/src/murf/core/remove_none_from_dict.py +11 -0
- murf-1.0.0/src/murf/core/request_options.py +35 -0
- murf-1.0.0/src/murf/core/serialization.py +272 -0
- murf-1.0.0/src/murf/environment.py +7 -0
- murf-1.0.0/src/murf/errors/__init__.py +17 -0
- murf-1.0.0/src/murf/errors/bad_request_error.py +9 -0
- murf-1.0.0/src/murf/errors/forbidden_error.py +9 -0
- murf-1.0.0/src/murf/errors/internal_server_error.py +9 -0
- murf-1.0.0/src/murf/errors/payment_required_error.py +9 -0
- murf-1.0.0/src/murf/errors/service_unavailable_error.py +9 -0
- murf-1.0.0/src/murf/errors/unauthorized_error.py +9 -0
- murf-1.0.0/src/murf/py.typed +0 -0
- murf-1.0.0/src/murf/text_to_speech/__init__.py +5 -0
- murf-1.0.0/src/murf/text_to_speech/client.py +592 -0
- murf-1.0.0/src/murf/text_to_speech/types/__init__.py +5 -0
- murf-1.0.0/src/murf/text_to_speech/types/generate_speech_request_model_version.py +5 -0
- murf-1.0.0/src/murf/types/__init__.py +21 -0
- murf-1.0.0/src/murf/types/api_voice.py +49 -0
- murf-1.0.0/src/murf/types/api_voice_gender.py +5 -0
- murf-1.0.0/src/murf/types/auth_token_response.py +28 -0
- murf-1.0.0/src/murf/types/generate_speech_response.py +44 -0
- murf-1.0.0/src/murf/types/pronunciation_detail.py +29 -0
- murf-1.0.0/src/murf/types/pronunciation_detail_type.py +5 -0
- murf-1.0.0/src/murf/types/style_details.py +24 -0
- murf-1.0.0/src/murf/types/word_duration.py +30 -0
- murf-1.0.0/src/murf/version.py +3 -0
murf-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: murf
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary:
|
|
5
|
+
Requires-Python: >=3.8,<4.0
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Operating System :: MacOS
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Operating System :: POSIX
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Dist: httpx (>=0.21.2)
|
|
22
|
+
Requires-Dist: pydantic (>=1.9.2)
|
|
23
|
+
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
|
|
24
|
+
Requires-Dist: typing_extensions (>=4.0.0)
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Murf Python Library
|
|
28
|
+
|
|
29
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fmurf-ai%2Fmurf-python-sdk)
|
|
30
|
+
[](https://pypi.python.org/pypi/murf)
|
|
31
|
+
|
|
32
|
+
The Murf Python library provides convenient access to the Murf API from Python.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pip install murf
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Reference
|
|
41
|
+
|
|
42
|
+
A full reference for this library is available [here](./reference.md).
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
Instantiate and use the client with the following:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from murf import Murf
|
|
50
|
+
|
|
51
|
+
client = Murf(
|
|
52
|
+
api_key="YOUR_API_KEY",
|
|
53
|
+
)
|
|
54
|
+
client.text_to_speech.generate(
|
|
55
|
+
text="And off they went. Gently walking into the sunset, with not a single care in the world",
|
|
56
|
+
variation=5,
|
|
57
|
+
voice_id="en-US-julia",
|
|
58
|
+
)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Async Client
|
|
62
|
+
|
|
63
|
+
The SDK also exports an `async` client so that you can make non-blocking calls to our API.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import asyncio
|
|
67
|
+
|
|
68
|
+
from murf import AsyncMurf
|
|
69
|
+
|
|
70
|
+
client = AsyncMurf(
|
|
71
|
+
api_key="YOUR_API_KEY",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
async def main() -> None:
|
|
76
|
+
await client.text_to_speech.generate(
|
|
77
|
+
text="And off they went. Gently walking into the sunset, with not a single care in the world",
|
|
78
|
+
variation=5,
|
|
79
|
+
voice_id="en-US-julia",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
asyncio.run(main())
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Exception Handling
|
|
87
|
+
|
|
88
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
89
|
+
will be thrown.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from murf.core.api_error import ApiError
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
client.text_to_speech.generate(...)
|
|
96
|
+
except ApiError as e:
|
|
97
|
+
print(e.status_code)
|
|
98
|
+
print(e.body)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Advanced
|
|
102
|
+
|
|
103
|
+
### Retries
|
|
104
|
+
|
|
105
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
106
|
+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
|
|
107
|
+
retry limit (default: 2).
|
|
108
|
+
|
|
109
|
+
A request is deemed retriable when any of the following HTTP status codes is returned:
|
|
110
|
+
|
|
111
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
112
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
113
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
|
|
114
|
+
|
|
115
|
+
Use the `max_retries` request option to configure this behavior.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
client.text_to_speech.generate(..., request_options={
|
|
119
|
+
"max_retries": 1
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Timeouts
|
|
124
|
+
|
|
125
|
+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
|
|
129
|
+
from murf import Murf
|
|
130
|
+
|
|
131
|
+
client = Murf(
|
|
132
|
+
...,
|
|
133
|
+
timeout=20.0,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# Override timeout for a specific method
|
|
138
|
+
client.text_to_speech.generate(..., request_options={
|
|
139
|
+
"timeout_in_seconds": 1
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Custom Client
|
|
144
|
+
|
|
145
|
+
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
|
|
146
|
+
and transports.
|
|
147
|
+
```python
|
|
148
|
+
import httpx
|
|
149
|
+
from murf import Murf
|
|
150
|
+
|
|
151
|
+
client = Murf(
|
|
152
|
+
...,
|
|
153
|
+
httpx_client=httpx.Client(
|
|
154
|
+
proxies="http://my.test.proxy.example.com",
|
|
155
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
156
|
+
),
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Contributing
|
|
161
|
+
|
|
162
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
163
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
164
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
165
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
166
|
+
an issue first to discuss with us!
|
|
167
|
+
|
|
168
|
+
On the other hand, contributions to the README are always very welcome!
|
|
169
|
+
|
murf-1.0.0/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Murf Python Library
|
|
2
|
+
|
|
3
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fmurf-ai%2Fmurf-python-sdk)
|
|
4
|
+
[](https://pypi.python.org/pypi/murf)
|
|
5
|
+
|
|
6
|
+
The Murf Python library provides convenient access to the Murf API from Python.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pip install murf
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Reference
|
|
15
|
+
|
|
16
|
+
A full reference for this library is available [here](./reference.md).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Instantiate and use the client with the following:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from murf import Murf
|
|
24
|
+
|
|
25
|
+
client = Murf(
|
|
26
|
+
api_key="YOUR_API_KEY",
|
|
27
|
+
)
|
|
28
|
+
client.text_to_speech.generate(
|
|
29
|
+
text="And off they went. Gently walking into the sunset, with not a single care in the world",
|
|
30
|
+
variation=5,
|
|
31
|
+
voice_id="en-US-julia",
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Async Client
|
|
36
|
+
|
|
37
|
+
The SDK also exports an `async` client so that you can make non-blocking calls to our API.
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import asyncio
|
|
41
|
+
|
|
42
|
+
from murf import AsyncMurf
|
|
43
|
+
|
|
44
|
+
client = AsyncMurf(
|
|
45
|
+
api_key="YOUR_API_KEY",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def main() -> None:
|
|
50
|
+
await client.text_to_speech.generate(
|
|
51
|
+
text="And off they went. Gently walking into the sunset, with not a single care in the world",
|
|
52
|
+
variation=5,
|
|
53
|
+
voice_id="en-US-julia",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
asyncio.run(main())
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Exception Handling
|
|
61
|
+
|
|
62
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
63
|
+
will be thrown.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from murf.core.api_error import ApiError
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
client.text_to_speech.generate(...)
|
|
70
|
+
except ApiError as e:
|
|
71
|
+
print(e.status_code)
|
|
72
|
+
print(e.body)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Advanced
|
|
76
|
+
|
|
77
|
+
### Retries
|
|
78
|
+
|
|
79
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
80
|
+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
|
|
81
|
+
retry limit (default: 2).
|
|
82
|
+
|
|
83
|
+
A request is deemed retriable when any of the following HTTP status codes is returned:
|
|
84
|
+
|
|
85
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
86
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
87
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
|
|
88
|
+
|
|
89
|
+
Use the `max_retries` request option to configure this behavior.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
client.text_to_speech.generate(..., request_options={
|
|
93
|
+
"max_retries": 1
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Timeouts
|
|
98
|
+
|
|
99
|
+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
|
|
103
|
+
from murf import Murf
|
|
104
|
+
|
|
105
|
+
client = Murf(
|
|
106
|
+
...,
|
|
107
|
+
timeout=20.0,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# Override timeout for a specific method
|
|
112
|
+
client.text_to_speech.generate(..., request_options={
|
|
113
|
+
"timeout_in_seconds": 1
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Custom Client
|
|
118
|
+
|
|
119
|
+
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
|
|
120
|
+
and transports.
|
|
121
|
+
```python
|
|
122
|
+
import httpx
|
|
123
|
+
from murf import Murf
|
|
124
|
+
|
|
125
|
+
client = Murf(
|
|
126
|
+
...,
|
|
127
|
+
httpx_client=httpx.Client(
|
|
128
|
+
proxies="http://my.test.proxy.example.com",
|
|
129
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Contributing
|
|
135
|
+
|
|
136
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
137
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
138
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
139
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
140
|
+
an issue first to discuss with us!
|
|
141
|
+
|
|
142
|
+
On the other hand, contributions to the README are always very welcome!
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "murf"
|
|
3
|
+
|
|
4
|
+
[tool.poetry]
|
|
5
|
+
name = "murf"
|
|
6
|
+
version = "1.0.0"
|
|
7
|
+
description = ""
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
authors = []
|
|
10
|
+
keywords = []
|
|
11
|
+
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.8",
|
|
17
|
+
"Programming Language :: Python :: 3.9",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Operating System :: POSIX",
|
|
23
|
+
"Operating System :: MacOS",
|
|
24
|
+
"Operating System :: POSIX :: Linux",
|
|
25
|
+
"Operating System :: Microsoft :: Windows",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
"Typing :: Typed"
|
|
28
|
+
]
|
|
29
|
+
packages = [
|
|
30
|
+
{ include = "murf", from = "src"}
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Repository = 'https://github.com/murf-ai/murf-python-sdk'
|
|
35
|
+
|
|
36
|
+
[tool.poetry.dependencies]
|
|
37
|
+
python = "^3.8"
|
|
38
|
+
httpx = ">=0.21.2"
|
|
39
|
+
pydantic = ">= 1.9.2"
|
|
40
|
+
pydantic-core = "^2.18.2"
|
|
41
|
+
typing_extensions = ">= 4.0.0"
|
|
42
|
+
|
|
43
|
+
[tool.poetry.dev-dependencies]
|
|
44
|
+
mypy = "1.0.1"
|
|
45
|
+
pytest = "^7.4.0"
|
|
46
|
+
pytest-asyncio = "^0.23.5"
|
|
47
|
+
python-dateutil = "^2.9.0"
|
|
48
|
+
types-python-dateutil = "^2.9.0.20240316"
|
|
49
|
+
ruff = "^0.5.6"
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
testpaths = [ "tests" ]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
|
|
55
|
+
[tool.mypy]
|
|
56
|
+
plugins = ["pydantic.mypy"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 120
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[build-system]
|
|
63
|
+
requires = ["poetry-core"]
|
|
64
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from .types import (
|
|
4
|
+
ApiVoice,
|
|
5
|
+
ApiVoiceGender,
|
|
6
|
+
AuthTokenResponse,
|
|
7
|
+
GenerateSpeechResponse,
|
|
8
|
+
PronunciationDetail,
|
|
9
|
+
PronunciationDetailType,
|
|
10
|
+
StyleDetails,
|
|
11
|
+
WordDuration,
|
|
12
|
+
)
|
|
13
|
+
from .errors import (
|
|
14
|
+
BadRequestError,
|
|
15
|
+
ForbiddenError,
|
|
16
|
+
InternalServerError,
|
|
17
|
+
PaymentRequiredError,
|
|
18
|
+
ServiceUnavailableError,
|
|
19
|
+
UnauthorizedError,
|
|
20
|
+
)
|
|
21
|
+
from . import auth, text_to_speech
|
|
22
|
+
from .client import AsyncMurf, Murf
|
|
23
|
+
from .environment import MurfEnvironment
|
|
24
|
+
from .text_to_speech import GenerateSpeechRequestModelVersion
|
|
25
|
+
from .version import __version__
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"ApiVoice",
|
|
29
|
+
"ApiVoiceGender",
|
|
30
|
+
"AsyncMurf",
|
|
31
|
+
"AuthTokenResponse",
|
|
32
|
+
"BadRequestError",
|
|
33
|
+
"ForbiddenError",
|
|
34
|
+
"GenerateSpeechRequestModelVersion",
|
|
35
|
+
"GenerateSpeechResponse",
|
|
36
|
+
"InternalServerError",
|
|
37
|
+
"Murf",
|
|
38
|
+
"MurfEnvironment",
|
|
39
|
+
"PaymentRequiredError",
|
|
40
|
+
"PronunciationDetail",
|
|
41
|
+
"PronunciationDetailType",
|
|
42
|
+
"ServiceUnavailableError",
|
|
43
|
+
"StyleDetails",
|
|
44
|
+
"UnauthorizedError",
|
|
45
|
+
"WordDuration",
|
|
46
|
+
"__version__",
|
|
47
|
+
"auth",
|
|
48
|
+
"text_to_speech",
|
|
49
|
+
]
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from ..core.client_wrapper import SyncClientWrapper
|
|
4
|
+
import typing
|
|
5
|
+
from ..core.request_options import RequestOptions
|
|
6
|
+
from ..types.auth_token_response import AuthTokenResponse
|
|
7
|
+
from ..core.pydantic_utilities import parse_obj_as
|
|
8
|
+
from ..errors.bad_request_error import BadRequestError
|
|
9
|
+
from ..errors.unauthorized_error import UnauthorizedError
|
|
10
|
+
from ..errors.service_unavailable_error import ServiceUnavailableError
|
|
11
|
+
from json.decoder import JSONDecodeError
|
|
12
|
+
from ..core.api_error import ApiError
|
|
13
|
+
from ..core.client_wrapper import AsyncClientWrapper
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuthClient:
|
|
17
|
+
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
18
|
+
self._client_wrapper = client_wrapper
|
|
19
|
+
|
|
20
|
+
def generate_token(self, *, request_options: typing.Optional[RequestOptions] = None) -> AuthTokenResponse:
|
|
21
|
+
"""
|
|
22
|
+
Generates an auth token for authenticating your requests
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
request_options : typing.Optional[RequestOptions]
|
|
27
|
+
Request-specific configuration.
|
|
28
|
+
|
|
29
|
+
Returns
|
|
30
|
+
-------
|
|
31
|
+
AuthTokenResponse
|
|
32
|
+
Ok
|
|
33
|
+
|
|
34
|
+
Examples
|
|
35
|
+
--------
|
|
36
|
+
from murf import Murf
|
|
37
|
+
|
|
38
|
+
client = Murf(
|
|
39
|
+
api_key="YOUR_API_KEY",
|
|
40
|
+
)
|
|
41
|
+
client.auth.generate_token()
|
|
42
|
+
"""
|
|
43
|
+
_response = self._client_wrapper.httpx_client.request(
|
|
44
|
+
"v1/auth/token",
|
|
45
|
+
method="GET",
|
|
46
|
+
request_options=request_options,
|
|
47
|
+
)
|
|
48
|
+
try:
|
|
49
|
+
if 200 <= _response.status_code < 300:
|
|
50
|
+
return typing.cast(
|
|
51
|
+
AuthTokenResponse,
|
|
52
|
+
parse_obj_as(
|
|
53
|
+
type_=AuthTokenResponse, # type: ignore
|
|
54
|
+
object_=_response.json(),
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
if _response.status_code == 400:
|
|
58
|
+
raise BadRequestError(
|
|
59
|
+
typing.cast(
|
|
60
|
+
typing.Optional[typing.Any],
|
|
61
|
+
parse_obj_as(
|
|
62
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
63
|
+
object_=_response.json(),
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
if _response.status_code == 401:
|
|
68
|
+
raise UnauthorizedError(
|
|
69
|
+
typing.cast(
|
|
70
|
+
typing.Optional[typing.Any],
|
|
71
|
+
parse_obj_as(
|
|
72
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
73
|
+
object_=_response.json(),
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
if _response.status_code == 503:
|
|
78
|
+
raise ServiceUnavailableError(
|
|
79
|
+
typing.cast(
|
|
80
|
+
typing.Optional[typing.Any],
|
|
81
|
+
parse_obj_as(
|
|
82
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
83
|
+
object_=_response.json(),
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
_response_json = _response.json()
|
|
88
|
+
except JSONDecodeError:
|
|
89
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
90
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class AsyncAuthClient:
|
|
94
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
95
|
+
self._client_wrapper = client_wrapper
|
|
96
|
+
|
|
97
|
+
async def generate_token(self, *, request_options: typing.Optional[RequestOptions] = None) -> AuthTokenResponse:
|
|
98
|
+
"""
|
|
99
|
+
Generates an auth token for authenticating your requests
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
request_options : typing.Optional[RequestOptions]
|
|
104
|
+
Request-specific configuration.
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
AuthTokenResponse
|
|
109
|
+
Ok
|
|
110
|
+
|
|
111
|
+
Examples
|
|
112
|
+
--------
|
|
113
|
+
import asyncio
|
|
114
|
+
|
|
115
|
+
from murf import AsyncMurf
|
|
116
|
+
|
|
117
|
+
client = AsyncMurf(
|
|
118
|
+
api_key="YOUR_API_KEY",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
async def main() -> None:
|
|
123
|
+
await client.auth.generate_token()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
asyncio.run(main())
|
|
127
|
+
"""
|
|
128
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
129
|
+
"v1/auth/token",
|
|
130
|
+
method="GET",
|
|
131
|
+
request_options=request_options,
|
|
132
|
+
)
|
|
133
|
+
try:
|
|
134
|
+
if 200 <= _response.status_code < 300:
|
|
135
|
+
return typing.cast(
|
|
136
|
+
AuthTokenResponse,
|
|
137
|
+
parse_obj_as(
|
|
138
|
+
type_=AuthTokenResponse, # type: ignore
|
|
139
|
+
object_=_response.json(),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
if _response.status_code == 400:
|
|
143
|
+
raise BadRequestError(
|
|
144
|
+
typing.cast(
|
|
145
|
+
typing.Optional[typing.Any],
|
|
146
|
+
parse_obj_as(
|
|
147
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
148
|
+
object_=_response.json(),
|
|
149
|
+
),
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
if _response.status_code == 401:
|
|
153
|
+
raise UnauthorizedError(
|
|
154
|
+
typing.cast(
|
|
155
|
+
typing.Optional[typing.Any],
|
|
156
|
+
parse_obj_as(
|
|
157
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
158
|
+
object_=_response.json(),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
if _response.status_code == 503:
|
|
163
|
+
raise ServiceUnavailableError(
|
|
164
|
+
typing.cast(
|
|
165
|
+
typing.Optional[typing.Any],
|
|
166
|
+
parse_obj_as(
|
|
167
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
168
|
+
object_=_response.json(),
|
|
169
|
+
),
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
_response_json = _response.json()
|
|
173
|
+
except JSONDecodeError:
|
|
174
|
+
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
175
|
+
raise ApiError(status_code=_response.status_code, body=_response_json)
|