fastpix-python 0.1.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.
- fastpix_python-0.1.0/LICENSE +21 -0
- fastpix_python-0.1.0/PKG-INFO +28 -0
- fastpix_python-0.1.0/README.md +471 -0
- fastpix_python-0.1.0/fastpix/__init__.py +4 -0
- fastpix_python-0.1.0/fastpix/async_client/__init__.py +3 -0
- fastpix_python-0.1.0/fastpix/async_client/api.py +33 -0
- fastpix_python-0.1.0/fastpix/async_client/client.py +52 -0
- fastpix_python-0.1.0/fastpix/async_client/live_streams.py +147 -0
- fastpix_python-0.1.0/fastpix/async_client/media.py +121 -0
- fastpix_python-0.1.0/fastpix/async_client/playback_ids.py +79 -0
- fastpix_python-0.1.0/fastpix/client/__init__.py +3 -0
- fastpix_python-0.1.0/fastpix/client/api.py +28 -0
- fastpix_python-0.1.0/fastpix/client/client.py +57 -0
- fastpix_python-0.1.0/fastpix/client/live_streams.py +150 -0
- fastpix_python-0.1.0/fastpix/client/media.py +110 -0
- fastpix_python-0.1.0/fastpix/client/playback_ids.py +80 -0
- fastpix_python-0.1.0/fastpix/utilis/__init__.py +4 -0
- fastpix_python-0.1.0/fastpix/utilis/constants.py +1 -0
- fastpix_python-0.1.0/fastpix/utilis/exceptions.py +14 -0
- fastpix_python-0.1.0/fastpix/utilis/utilis.py +17 -0
- fastpix_python-0.1.0/fastpix_python.egg-info/PKG-INFO +28 -0
- fastpix_python-0.1.0/fastpix_python.egg-info/SOURCES.txt +25 -0
- fastpix_python-0.1.0/fastpix_python.egg-info/dependency_links.txt +1 -0
- fastpix_python-0.1.0/fastpix_python.egg-info/requires.txt +4 -0
- fastpix_python-0.1.0/fastpix_python.egg-info/top_level.txt +1 -0
- fastpix_python-0.1.0/setup.cfg +4 -0
- fastpix_python-0.1.0/setup.py +29 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 FastPix
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastpix-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: FastPix SDK with both sync and async support
|
|
5
|
+
Home-page: https://github.com/fastpix-io/fastpix-python-server-sdk
|
|
6
|
+
Author: FastPix
|
|
7
|
+
Author-email: dev@fastpix.io
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Requires-Python: >=3.7
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.25.0
|
|
18
|
+
Provides-Extra: async
|
|
19
|
+
Requires-Dist: aiohttp>=3.8.0; extra == "async"
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: provides-extra
|
|
26
|
+
Dynamic: requires-dist
|
|
27
|
+
Dynamic: requires-python
|
|
28
|
+
Dynamic: summary
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
# Introduction:
|
|
2
|
+
|
|
3
|
+
The FastPix Python SDK simplifies integration with the FastPix platform. This SDK is designed for secure and efficient communication with the FastPix API, enabling easy management of media uploads, live streaming, and simulcasting. It is intended for use with Python 3.7 or later.
|
|
4
|
+
|
|
5
|
+
## Key Features:
|
|
6
|
+
|
|
7
|
+
- ### Media API:
|
|
8
|
+
|
|
9
|
+
- **Upload Media**: Upload media files seamlessly from URLs or devices.
|
|
10
|
+
- **Manage Media**: Perform operations such as listing, fetching, updating, and deleting media assets.
|
|
11
|
+
- **Playback IDs**: Generate and manage playback IDs for media access.
|
|
12
|
+
|
|
13
|
+
- ### Live API:
|
|
14
|
+
|
|
15
|
+
- **Create & Manage Live Streams:**: Create, list, update, and delete live streams effortlessly.
|
|
16
|
+
- **Control Stream Access**: Generate playback IDs for live streams to control and manage access.
|
|
17
|
+
- **Simulcast to Multiple Platforms**: Stream content to multiple platforms simultaneously.
|
|
18
|
+
|
|
19
|
+
For detailed usage, refer to the [FastPix API Reference](https://docs.fastpix.io/reference).
|
|
20
|
+
|
|
21
|
+
## Latest Release
|
|
22
|
+
- Current Version: 0.1.0
|
|
23
|
+
- View our [changelog](CHANELOG.md) for details on recent updates
|
|
24
|
+
- Download the latest release from our [releases page](https://github.com/FastPix/python-server-sdk/releases/tag/v1.0.0)
|
|
25
|
+
|
|
26
|
+
## Prerequisites:
|
|
27
|
+
|
|
28
|
+
### Getting started with FastPix:
|
|
29
|
+
|
|
30
|
+
To get started with the **FastPix Python SDK**, ensure you have the following:
|
|
31
|
+
|
|
32
|
+
- The FastPix APIs are authenticated using an **Access Token** and a **Secret Key**. You must generate these credentials to use the SDK.
|
|
33
|
+
|
|
34
|
+
- Follow the steps in the [Authentication with Access Tokens](https://docs.fastpix.io/docs/authentication-with-access-tokens) guide to obtain your credentials.
|
|
35
|
+
|
|
36
|
+
## Installation:
|
|
37
|
+
|
|
38
|
+
To install the SDK, use pip with the GitHub repository URL to easily download and install the required libraries.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install git+https://github.com/FastPix/fastpix-python
|
|
42
|
+
```
|
|
43
|
+
(you may need to run `pip` with root permission)
|
|
44
|
+
|
|
45
|
+
## Basic Usage:
|
|
46
|
+
|
|
47
|
+
### Importing the SDK
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from fastpix-python import Client
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Initialization:
|
|
54
|
+
|
|
55
|
+
Initialize the FastPix SDK with your API credentials.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from fastpix-python import Client
|
|
59
|
+
|
|
60
|
+
client = Client(username="your-access-token-id", password="your-secret-key")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Example Usage:
|
|
64
|
+
|
|
65
|
+
Below is an example of configuring `FastPix Python SDK` into your project.
|
|
66
|
+
|
|
67
|
+
`Note:-` For Async SDK Users: When using the AsyncClient, all SDK methods must be prefixed with the await keyword.
|
|
68
|
+
```python
|
|
69
|
+
# Sync Usage
|
|
70
|
+
from fastpix-python import Client
|
|
71
|
+
|
|
72
|
+
client = Client(username="your-access-token-id", password="your-secret-key")
|
|
73
|
+
|
|
74
|
+
# Define the parameters for fetching media assets in a separate variable.
|
|
75
|
+
media_request_params = {
|
|
76
|
+
"limit": 10, # Number of media assets to fetch in one request.
|
|
77
|
+
"offset": 1, # Starting position for the list of media assets (useful for pagination).
|
|
78
|
+
"orderBy": "desc" # Sort order for the media assets ("desc" for descending, "asc" for ascending).
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
media = client.media.get_all_media(params=media_request_params)
|
|
83
|
+
print("Media:", media)
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(f"Error fetching media: {str(e)}")
|
|
86
|
+
|
|
87
|
+
# Async Usage
|
|
88
|
+
from fastpix import AsyncClient as Client
|
|
89
|
+
import asyncio
|
|
90
|
+
|
|
91
|
+
async def main():
|
|
92
|
+
# Initialize the AsyncClient with username and password.
|
|
93
|
+
client = Client(username="your-access-token-id", password="your-secret-key")
|
|
94
|
+
|
|
95
|
+
# Define the parameters for fetching media assets in a separate variable.
|
|
96
|
+
media_request_params = {
|
|
97
|
+
"limit": 10, # Number of media assets to fetch in one request.
|
|
98
|
+
"offset": 1, # Starting position for the list of media assets (useful for pagination).
|
|
99
|
+
"orderBy": "desc" # Sort order for the media assets ("desc" for descending, "asc" for ascending).
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
# Fetch media assets asynchronously using the await keyword.
|
|
104
|
+
media = await client.media.get_all_media(params=media_request_params)
|
|
105
|
+
print("Media:", media)
|
|
106
|
+
except Exception as e:
|
|
107
|
+
print(f"Error fetching media: {str(e)}")
|
|
108
|
+
|
|
109
|
+
# Run the async function
|
|
110
|
+
asyncio.run(main())
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Usage:
|
|
114
|
+
|
|
115
|
+
### 1. Media Operations:
|
|
116
|
+
|
|
117
|
+
#### 1.1. Media Uploads:
|
|
118
|
+
|
|
119
|
+
##### Upload Media from a URL:
|
|
120
|
+
|
|
121
|
+
Use the `client.media.create_pull_video()` method to upload media directly from a URL. For detailed configuration options, refer to the [Create media from URL](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/UploadMedia.md#method-clientmediacreate_pull_video) API documentation.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
# Define the request payload for uploading media from a URL.
|
|
125
|
+
media_from_url_request = {
|
|
126
|
+
"inputs": [{
|
|
127
|
+
"type": "video", # Specifies the type of media being uploaded (e.g., "video").
|
|
128
|
+
"url": "https://static.fastpix.io/sample.mp4" # URL of the media file to be uploaded.
|
|
129
|
+
}],
|
|
130
|
+
"metadata": {
|
|
131
|
+
"video_title": "Big_Buck_Bunny" # Metadata to associate with the media, such as its title.
|
|
132
|
+
},
|
|
133
|
+
"accessPolicy": "public", # Access policy for the media ("public" or "private").
|
|
134
|
+
"maxResolution": "1080p"
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
media_response = client.media.create_pull_video(media_from_url_request)
|
|
138
|
+
print("media_response", media_response)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
##### Upload Media from a Local Device:
|
|
142
|
+
|
|
143
|
+
Use the `client.media.get_presigned_url()` method to obtain a `signedUrl` and upload media directly from a local device. For more details on configuration options, refer to the [Upload media from device](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/UploadMedia.md#method-clientmediaget_presigned_url) API documentation.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# Define the request payload for uploading media from a device.
|
|
147
|
+
media_from_device_request = {
|
|
148
|
+
"corsOrigin": "*", # Specifies the allowed origin for CORS (Cross-Origin Resource Sharing). "*" allows all origins.
|
|
149
|
+
"pushMediaSettings": {
|
|
150
|
+
"accessPolicy": "private", # Sets the access policy for the uploaded media (e.g., "private" or "public").
|
|
151
|
+
"optimizeAudio": True, # Enables audio optimization for the uploaded media.
|
|
152
|
+
"maxResolution": "1080p" # Specifies the maximum resolution allowed for the uploaded media.
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
media_from_device_response = client.media.get_presigned_url(media_from_device_request)
|
|
157
|
+
print("Upload Response:", media_from_device_response)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### 1.2. Media Management:
|
|
161
|
+
|
|
162
|
+
##### Get List of All Media:
|
|
163
|
+
|
|
164
|
+
Use the `client.media.get_all_media()` method to fetch a list of all media assets. You can customize the query by modifying parameters such as `limit`, `offset`, and `orderBy`. Refer to the [Get list of all media](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMedia.md#method-clientmediaget_all_media) API documentation for the accepted values.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
# Define the parameters for fetching media assets in a separate variable.
|
|
168
|
+
media_request_params = {
|
|
169
|
+
"limit": 10, # Number of media assets to fetch in one request.
|
|
170
|
+
"offset": 1, # Starting position for the list of media assets (useful for pagination).
|
|
171
|
+
"orderBy": "desc" # Sort order for the media assets ("desc" for descending, "asc" for ascending).
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# Assuming `client` is already initialized with the proper credentials
|
|
175
|
+
all_media_assets = client.media.get_all_media(media_request_params)
|
|
176
|
+
|
|
177
|
+
# Print the fetched media assets
|
|
178
|
+
print("All Media Assets:", all_media_assets)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
##### Get Media Asset by ID:
|
|
182
|
+
|
|
183
|
+
Use the `client.media.get_by_mediaId()` method to retrieve a specific media asset by its ID. Provide `media_id`of the asset to fetch its details. Refer to the [Get a media by ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMedia.md#method-clientmediaget_by_mediaid) API documentation for more details.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
media_id = "media_id" # Unique identifier for the media asset to be retrieved
|
|
187
|
+
|
|
188
|
+
get_media_asset = client.media.get_by_mediaId(media_id)
|
|
189
|
+
|
|
190
|
+
# Print the retrieved media asset by ID
|
|
191
|
+
print("Retrieved media asset by ID:", get_media_asset)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
##### Update Media Asset:
|
|
195
|
+
|
|
196
|
+
Use the `client.media.update()` method to update metadata or other properties of a specific media asset. Provide the `media_id` of the asset along with the metadata to be updated. Refer to the [Update a media by ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMedia.md#method-clientmediaupdate) API documentation for more details.
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
media_id = "media_id" # Unique identifier for the media asset to be retrieved
|
|
200
|
+
|
|
201
|
+
# Define the payload with the updates to be applied to the media asset.
|
|
202
|
+
update_payload = {
|
|
203
|
+
"metadata": {
|
|
204
|
+
"key": "value" # Replace "key" and "value" with actual metadata keys and values
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
update_media_asset = client.media.update(media_id, update_payload)
|
|
209
|
+
|
|
210
|
+
# Print the updated media asset details
|
|
211
|
+
print("Updated Media Asset:", update_media_asset)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
##### Delete Media Asset:
|
|
215
|
+
|
|
216
|
+
Use the `client.media.delete()` method to delete a specific media asset by its ID. Pass the `media_id` of the asset you want to delete. Refer to the [Delete a media by ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMedia.md#method-clientmediadelete) API documentation for more information.
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
media_id = "media_id" # Unique identifier for the media asset to be retrieved
|
|
220
|
+
|
|
221
|
+
# Assuming `client` is already initialized with the necessary credentials
|
|
222
|
+
delete_media_asset = client.media.delete(media_id)
|
|
223
|
+
|
|
224
|
+
# Print the response indicating the media asset has been deleted
|
|
225
|
+
print("Deleted Media Asset:", delete_media_asset)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
##### Get Media Asset Info:
|
|
229
|
+
|
|
230
|
+
Use the `client.media.get_media_info()` method to retrieve detailed information about a specific media asset. Pass the `media_id` to fetch its details. Refer to the [Get info of media inputs](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMedia.md#method-clientmediaget_media_info) API documentation for more details.
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
media_id = "media_id" # Unique identifier for the media asset to be retrieved
|
|
234
|
+
|
|
235
|
+
get_media_info = client.media.get_media_info(media_id)
|
|
236
|
+
print("Media Asset Info:", get_media_info)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### 1.3. Manage Media Playback:
|
|
240
|
+
|
|
241
|
+
##### Generate Media Playback ID:
|
|
242
|
+
|
|
243
|
+
Use the `client.media_playback_ids.create()` method to generate a playback ID for a specific media asset. You can pass an `media_id` and configure options such as the `accessPolicy`. For detailed configuration options, refer to the [Create a playback ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMediaPlayback.md#method-clientmedia_playback_idscreate) API documentation.
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
# Define the media_id and accessPolicy dynamically
|
|
247
|
+
media_type = "video_on_demand"
|
|
248
|
+
media_id = "media-id" # Unique identifier for the media asset.
|
|
249
|
+
|
|
250
|
+
playback_options = {
|
|
251
|
+
"accessPolicy": "public", # Can be 'public' or 'private'.
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
playback_id_response = client.playback_ids.create(media_type, media_id, playback_options)
|
|
255
|
+
|
|
256
|
+
print("Playback ID Creation Response:", playback_id_response)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
##### Delete Media Playback ID:
|
|
260
|
+
|
|
261
|
+
Use the `client.media_playback_ids.delete()` method to delete a playback ID for a specific media asset. You need to pass both the `media_id` and the `playback_id` to delete the playback ID. For detailed configuration options, refer to the [Delete a playback ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/VideoOnDemand/ManageMediaPlayback.md#method-clientmedia_playback_idsdelete) API documentation.
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
# Define the media_id and playback_id dynamically
|
|
265
|
+
media_type = "video_on_demand"
|
|
266
|
+
media_id = "media-id"; # The ID of the media asset for which you want to delete the playback ID.
|
|
267
|
+
playback_ids = ["id1", "id2"]; # The playback ID that you want to delete.
|
|
268
|
+
|
|
269
|
+
delete_playback_response = client.playback_ids.delete(media_type, media_id, playback_ids)
|
|
270
|
+
|
|
271
|
+
print("Playback ID Deletion Response:", delete_playback_response)
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
----
|
|
275
|
+
|
|
276
|
+
### 2. Live Stream Operations:
|
|
277
|
+
|
|
278
|
+
#### 2.1. Start Live Stream:
|
|
279
|
+
|
|
280
|
+
Use the `client.livestreams.create()` method to start a live stream with specific configurations. For detailed configuration options, refer to the [Create a new stream](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/CreateLiveStream.md#method-clientlivestreamscreate) API documentation.
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
livestream_request = {
|
|
284
|
+
"playbackSettings": {
|
|
285
|
+
"accessPolicy": "public", # Defines the access level of the live stream (public or private)
|
|
286
|
+
},
|
|
287
|
+
"inputMediaSettings": {
|
|
288
|
+
"maxResolution": "1080p", # Set the maximum resolution of the live stream
|
|
289
|
+
"reconnectWindow": 1800, # Set the duration for reconnecting the stream in seconds
|
|
290
|
+
"mediaPolicy": "private", # Define media policy (private or public)
|
|
291
|
+
"metadata": {
|
|
292
|
+
"liveStream": "fp_livestream", # Custom metadata for the live stream
|
|
293
|
+
},
|
|
294
|
+
"enableDvrMode": True, # Enable DVR mode to allow viewers to rewind the live stream
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
# Initiating the live stream
|
|
299
|
+
generate_livestream = client.livestreams.create(livestream_request)
|
|
300
|
+
print("Live Stream initiated successfully:", generate_livestream)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
#### 2.2. Live Stream Management:
|
|
304
|
+
|
|
305
|
+
##### Get List of All Live Streams:
|
|
306
|
+
|
|
307
|
+
Use the `client.livestreams.list()` method to fetch a list of all live streams. You can customize the query by modifying parameters such as `limit`, `offset`, and `orderBy`. For detailed configuration options, refer to the [Get all live streams](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageLiveStreams.md#method-clientlivestreamslist) API documentation.
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
get_all_livestream_pagination = {
|
|
311
|
+
"limit": 10, # Limit the number of live streams retrieved.
|
|
312
|
+
"offset": 1, # Skip a specified number of streams for pagination.
|
|
313
|
+
"orderBy": "asc", # Order the results based on the specified criteria ("asc" or "desc").
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
get_all_livestreams = client.livestreams.list(get_all_livestream_pagination)
|
|
317
|
+
print("All Live Streams:", get_all_livestreams)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
##### Get Live Stream by ID:
|
|
321
|
+
|
|
322
|
+
Use the `client.livestreams.get()` method to retrieve a specific live stream by its ID. Provide the `stream_id` of the stream you wish to fetch. For more details, refer to the [Get stream by ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageLiveStreams.md#method-clientlivestreamsget) API documentation.
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
326
|
+
get_livestream_by_id = client.livestreams.get(stream_id)
|
|
327
|
+
|
|
328
|
+
print("Live Stream Details:", get_livestream_by_id)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
##### Update Live Stream:
|
|
332
|
+
|
|
333
|
+
Use the `client.livestreams.update()` method to update a live stream's configuration. Provide the `stream_id` of the stream and specify the fields you want to update. For more details, refer to the [Update a stream](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageLiveStreams.md#method-clientlivestreamsupdate) API documentation.
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Provide the stream ID for the live stream to update
|
|
337
|
+
update_livestream_request = {
|
|
338
|
+
"metadata": {
|
|
339
|
+
"livestream_name": "Game_streaming",
|
|
340
|
+
},
|
|
341
|
+
"reconnectWindow": 100,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
update_livestream = client.livestreams.update(stream_id,update_livestream_request)
|
|
345
|
+
|
|
346
|
+
print("Updated Live Stream:", update_livestream)
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
##### Delete Live Stream:
|
|
350
|
+
|
|
351
|
+
Use the `client.livestreams.delete()` method to delete a live stream by its ID. Provide `stream_id` of the stream you want to delete. For more details, refer to the [Delete a stream](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageLiveStreams.md#method-clientlivestreamsdelete) API documentation.
|
|
352
|
+
|
|
353
|
+
```python
|
|
354
|
+
delete_livestream = client.livestreams.delete("a09f3e958c16ed00e85bfe798abd9845") # Provide the stream ID of the live stream to delete
|
|
355
|
+
print("Deleted Live Stream:", delete_livestream)
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### 2.3. Manage Live Stream Playback:
|
|
359
|
+
|
|
360
|
+
##### Generate Live Stream Playback ID:
|
|
361
|
+
|
|
362
|
+
Use the `client.livestream_playback_ids.create()` method to generate a playback ID for a live stream. Replace `stream_id` with the actual ID of the live stream and specify the desired `accessPolicy`. For more details, refer to the [Create a playback ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamPlayback.md#method-clientlivestream_playback_idscreate) API documentation.
|
|
363
|
+
|
|
364
|
+
```python
|
|
365
|
+
media_type = "livestream"
|
|
366
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
367
|
+
body = { "accessPolicy": "public" }
|
|
368
|
+
|
|
369
|
+
generate_livestream_playback_id = client.playback_ids.create(media_type, stream_id, body)
|
|
370
|
+
|
|
371
|
+
print("Generated Live Stream Playback ID:", generate_livestream_playback_id)
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
##### Delete Live Stream Playback ID:
|
|
375
|
+
|
|
376
|
+
Use the `client.livestream_playback_ids.delete()` method to delete a specific playback ID for a live stream. You need to provide both the `stream_id` of the live stream and the `playback_id` to delete. For more details, refer to the [Delete a playback ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamPlayback.md#method-clientlivestream_playback_idsdelete) API documentation.
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
media_type = "livestream"
|
|
380
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
381
|
+
playback_id = "632029b4-7c53-4dcf-a4d3-1884c29e90f8" # Replace with actual playback ID
|
|
382
|
+
|
|
383
|
+
delete_livestream_playback_id = client.playback_ids.delete(media_type, stream_id, playback_id)
|
|
384
|
+
|
|
385
|
+
print("Deleted Live Stream Playback ID:", delete_livestream_playback_id)
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
##### Get Live Stream Playback Policy:
|
|
389
|
+
|
|
390
|
+
Use the `client.livestream_playback_ids.get()` method to retrieve the playback policy for a specific live stream playback ID. Replace `stream_id` with the stream's ID and `playback_id` with the actual playback ID to fetch the policy. For more details, refer to the [Get stream's playback ID](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamPlayback.md#method-clientlivestream_playback_idsget) API documentation.
|
|
391
|
+
|
|
392
|
+
```python
|
|
393
|
+
media_type = "livestream"
|
|
394
|
+
stream_id = "1c5e8abcc2080cba74f5d0ac91c7833e" # Replace with the actual stream ID
|
|
395
|
+
playback_id = "95ce872d-0b58-44f3-be72-8ed8b97ee2c9" # Replace with the actual playback ID
|
|
396
|
+
|
|
397
|
+
get_livestream_playback_policy = client.playback_ids.get(media_type, stream_id, playback_id)
|
|
398
|
+
|
|
399
|
+
print("Live Stream Playback Policy:", get_livestream_playback_policy )
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
#### 2.4. Manage Live Stream Simulcast:
|
|
403
|
+
|
|
404
|
+
##### Initiate Live Stream Simulcast:
|
|
405
|
+
|
|
406
|
+
Use the `client.livestreams.create_simulcast()` method to create a new simulcast for a live stream. Provide the stream ID and simulcast payload with the URL and stream key. For more details, refer to the [Create a simulcast](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamSimulcast.md#method-clientlivestreamscreate_simulcast) API documentation.
|
|
407
|
+
|
|
408
|
+
```python
|
|
409
|
+
simulcast_payload = {
|
|
410
|
+
"url": "rtmps://live.fastpix.io:443/live",
|
|
411
|
+
"streamKey": "46c3457fa8a579b2d4da64125a2b6e83ka09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream key
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
415
|
+
|
|
416
|
+
generate_simulcast = client.livestreams.create_simulcast(stream_id, simulcast_payload)
|
|
417
|
+
|
|
418
|
+
print("Generate Simulcast:", generate_simulcast)
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
##### Get Live Stream Simulcast:
|
|
422
|
+
|
|
423
|
+
Use the `client.livestreams.get_simulcast()` method to retrieve details of a specific simulcast stream. Provide the `stream_id` and `simulcast_id` of the simulcast you want to fetch. For more details, refer to the [Get a specific simulcast of a stream](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamSimulcast.md#method-clientlivestreamsget_simulcast) API documentation.
|
|
424
|
+
|
|
425
|
+
```python
|
|
426
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
427
|
+
simulcast_id = "7269209ff0299319b6321c9a6e7850ff" # Replace with actual simulcast ID
|
|
428
|
+
|
|
429
|
+
get_livestream_simulcast = client.livestreams.get_simulcast(stream_id, simulcast_id)
|
|
430
|
+
|
|
431
|
+
print("Live Stream Simulcast Details:", get_livestream_simulcast )
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
##### Update Live Stream Simulcast:
|
|
435
|
+
|
|
436
|
+
Use the `client.livestreams.update_simulcast()` method to update the configuration of a simulcast stream. Provide the `stream_id`, `simulcast_id`, and the fields you want to update. For more details, refer to the [Update a specific simulcast of a stream](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamSimulcast.md#method-clientlivestreamsupdate_simulcast) API documentation.
|
|
437
|
+
|
|
438
|
+
```python
|
|
439
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
440
|
+
simulcast_id = "7269209ff0299319b6321c9a6e7850ff" # Replace with actual simulcast ID
|
|
441
|
+
|
|
442
|
+
update_payload = {
|
|
443
|
+
"isEnabled": False, # Disable the simulcast stream (set to True to enable)
|
|
444
|
+
"metadata": {
|
|
445
|
+
"simulcast2": "media" # Update the metadata as needed
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
update_live_simulcast = client.livestreams.update_simulcast(stream_id, simulcast_id, update_payload)
|
|
450
|
+
|
|
451
|
+
print("Updated Live Stream Simulcast:", update_live_simulcast)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
##### Delete Live Stream Simulcast:
|
|
455
|
+
|
|
456
|
+
Use the `client.livestreams.delete_simulcast()` method to remove a specific simulcast from a live stream. Provide the `stream_id` and `simulcast_id` for the simulcast you want to delete. For more details, refer to the [Delete a simulcast](https://github.com/FastPix/python-server-sdk/blob/main/fastpix/docs/Live/ManageStreamSimulcast.md#method-deletelivestreamsimulcast) API documentation.
|
|
457
|
+
|
|
458
|
+
```python
|
|
459
|
+
stream_id = "a09f3e958c16ed00e85bfe798abd9845" # Replace with actual stream ID
|
|
460
|
+
simulcast_id = "7269209ff0299319b6321c9a6e7850ff" # Replace with actual simulcast ID
|
|
461
|
+
|
|
462
|
+
delete_live_simulcast = client.livestreams.delete_simulcast(stream_id, simulcast_id)
|
|
463
|
+
|
|
464
|
+
print("Deleted Live Stream Simulcast:", delete_live_simulcast)
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Detailed Usage:
|
|
468
|
+
|
|
469
|
+
For a complete understanding of each API's functionality, including request and response details, parameter descriptions, and additional examples, please refer to the [FastPix API Reference](https://docs.fastpix.io/reference/signingkeys-overview).
|
|
470
|
+
|
|
471
|
+
The API reference provides comprehensive documentation for all available endpoints and features, ensuring developers can integrate and utilize FastPix APIs efficiently.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
from fastpix.utilis.exceptions import APIError
|
|
3
|
+
from fastpix.utilis.constants import BASE_URL
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def make_request(method, endpoint, headers=None, data=None, params=None):
|
|
7
|
+
url = f"{BASE_URL}{endpoint}"
|
|
8
|
+
headers = headers or {}
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
async with aiohttp.ClientSession() as session:
|
|
12
|
+
async with session.request(
|
|
13
|
+
method=method,
|
|
14
|
+
url=url,
|
|
15
|
+
headers=headers,
|
|
16
|
+
json=data,
|
|
17
|
+
params=params,
|
|
18
|
+
) as response:
|
|
19
|
+
try:
|
|
20
|
+
response_data = await response.json()
|
|
21
|
+
except aiohttp.ContentTypeError:
|
|
22
|
+
response_data = await response.text()
|
|
23
|
+
|
|
24
|
+
if response.ok:
|
|
25
|
+
return response_data
|
|
26
|
+
else:
|
|
27
|
+
raise APIError(
|
|
28
|
+
message=f"Request failed with status {response.status}",
|
|
29
|
+
status_code=response.status,
|
|
30
|
+
details=response_data
|
|
31
|
+
)
|
|
32
|
+
except aiohttp.ClientError as e:
|
|
33
|
+
raise APIError(f"Request failed: {str(e)}")
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from fastpix.utilis.exceptions import APIError
|
|
3
|
+
from fastpix.async_client.media import MediaResource
|
|
4
|
+
from fastpix.async_client.playback_ids import PlaybackIDs
|
|
5
|
+
from fastpix.async_client.live_streams import Livestream
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Client:
|
|
9
|
+
def __init__(self, username=None, password=None, api_key=None):
|
|
10
|
+
"""
|
|
11
|
+
Initialize the client with flexible authentication.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
username (str, optional): Username for authentication
|
|
15
|
+
password (str, optional): Password for authentication
|
|
16
|
+
api_key (str, optional): Pre-generated base64 encoded API key
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
# Validate and prepare API key
|
|
20
|
+
if api_key:
|
|
21
|
+
self.api_key = api_key
|
|
22
|
+
elif username and password:
|
|
23
|
+
# Encode credentials to base64
|
|
24
|
+
credentials = f"{username}:{password}"
|
|
25
|
+
self.api_key = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
|
|
26
|
+
else:
|
|
27
|
+
raise ValueError("Must provide either username and password or a pre-generated API key")
|
|
28
|
+
|
|
29
|
+
# Prepare headers
|
|
30
|
+
self.headers = {
|
|
31
|
+
"accept": "application/json",
|
|
32
|
+
"content-type": "application/json",
|
|
33
|
+
"Authorization": f"Basic {self.api_key}",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Initialize resources
|
|
37
|
+
self.media = MediaResource(self)
|
|
38
|
+
self.playback_ids = PlaybackIDs(self)
|
|
39
|
+
self.livestreams = Livestream(self)
|
|
40
|
+
|
|
41
|
+
async def _validate_credentials(self):
|
|
42
|
+
"""
|
|
43
|
+
Validate credentials by attempting to fetch media.
|
|
44
|
+
Raises an APIError if authentication fails.
|
|
45
|
+
"""
|
|
46
|
+
try:
|
|
47
|
+
# Attempt to fetch media to verify credentials (async)
|
|
48
|
+
response = await self.media.get_all()
|
|
49
|
+
return response
|
|
50
|
+
|
|
51
|
+
except APIError as e:
|
|
52
|
+
raise APIError(f"Authentication failed: {str(e)}") from e
|