brightcove-async 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.
- brightcove_async-0.1.0/LICENSE.txt +21 -0
- brightcove_async-0.1.0/PKG-INFO +13 -0
- brightcove_async-0.1.0/README.md +0 -0
- brightcove_async-0.1.0/pyproject.toml +31 -0
- brightcove_async-0.1.0/setup.cfg +4 -0
- brightcove_async-0.1.0/src/brightcove_async/__init__.py +4 -0
- brightcove_async-0.1.0/src/brightcove_async/client.py +92 -0
- brightcove_async-0.1.0/src/brightcove_async/initalise.py +26 -0
- brightcove_async-0.1.0/src/brightcove_async/oauth/__init__.py +0 -0
- brightcove_async-0.1.0/src/brightcove_async/oauth/oauth.py +69 -0
- brightcove_async-0.1.0/src/brightcove_async/protocols.py +15 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/__init__.py +0 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/analytics_model/__init__.py +0 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/analytics_model/alltime_videos.py +5 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/cms_model/Image.py +11 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/cms_model/Videofields.py +40 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/cms_model/__init__.py +1370 -0
- brightcove_async-0.1.0/src/brightcove_async/schemas/syndication_model.py +134 -0
- brightcove_async-0.1.0/src/brightcove_async/services/__init__.py +0 -0
- brightcove_async-0.1.0/src/brightcove_async/services/analytics.py +40 -0
- brightcove_async-0.1.0/src/brightcove_async/services/base.py +126 -0
- brightcove_async-0.1.0/src/brightcove_async/services/cms.py +286 -0
- brightcove_async-0.1.0/src/brightcove_async/services/syndication.py +39 -0
- brightcove_async-0.1.0/src/brightcove_async/settings.py +21 -0
- brightcove_async-0.1.0/src/brightcove_async.egg-info/PKG-INFO +13 -0
- brightcove_async-0.1.0/src/brightcove_async.egg-info/SOURCES.txt +28 -0
- brightcove_async-0.1.0/src/brightcove_async.egg-info/dependency_links.txt +1 -0
- brightcove_async-0.1.0/src/brightcove_async.egg-info/requires.txt +5 -0
- brightcove_async-0.1.0/src/brightcove_async.egg-info/top_level.txt +1 -0
- brightcove_async-0.1.0/tests/test_client.py +119 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jeremy Winchester
|
|
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,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brightcove_async
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An asynchronous client for the Brightcove API.
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Requires-Dist: aiohttp>=3.12.14
|
|
9
|
+
Requires-Dist: aiolimiter>=1.2.1
|
|
10
|
+
Requires-Dist: pydantic>=2.11.7
|
|
11
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
12
|
+
Requires-Dist: tenacity>=9.1.2
|
|
13
|
+
Dynamic: license-file
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "brightcove_async"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "An asynchronous client for the Brightcove API."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.13"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"aiohttp>=3.12.14",
|
|
9
|
+
"aiolimiter>=1.2.1",
|
|
10
|
+
"pydantic>=2.11.7",
|
|
11
|
+
"pydantic-settings>=2.10.1",
|
|
12
|
+
"tenacity>=9.1.2",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"datamodel-code-generator>=0.31.2",
|
|
19
|
+
"mypy>=1.17.0",
|
|
20
|
+
"pre-commit>=4.2.0",
|
|
21
|
+
"pytest>=8.4.1",
|
|
22
|
+
"pytest-asyncio>=1.1.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.mypy]
|
|
26
|
+
plugins = [
|
|
27
|
+
"pydantic.mypy"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[tool.uv]
|
|
31
|
+
package = true
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from typing import ClassVar, Self, cast
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
from brightcove_async.protocols import OAuthClientProtocol
|
|
6
|
+
from brightcove_async.services.analytics import Analytics
|
|
7
|
+
from brightcove_async.services.base import Base
|
|
8
|
+
from brightcove_async.services.cms import CMS
|
|
9
|
+
from brightcove_async.services.syndication import Syndication
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BrightcoveClient:
|
|
13
|
+
_service_classes: ClassVar[dict[str, type[Base]]] = {
|
|
14
|
+
"cms": CMS,
|
|
15
|
+
"syndication": Syndication,
|
|
16
|
+
"analytics": Analytics,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
cms_base_url: str,
|
|
22
|
+
syndication_base_url: str,
|
|
23
|
+
analytics_base_url: str,
|
|
24
|
+
client_id: str,
|
|
25
|
+
client_secret: str,
|
|
26
|
+
oauth_cls: type[OAuthClientProtocol],
|
|
27
|
+
session: aiohttp.ClientSession | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
self._oauth_cls = oauth_cls
|
|
30
|
+
self._cms_base_url = cms_base_url
|
|
31
|
+
self._syndication_base_url = syndication_base_url
|
|
32
|
+
self._analytics_base_url = analytics_base_url
|
|
33
|
+
self._session: aiohttp.ClientSession | None = session
|
|
34
|
+
self._external_session = session
|
|
35
|
+
self._oauth: OAuthClientProtocol | None = None
|
|
36
|
+
self._client_id = client_id
|
|
37
|
+
self._client_secret = client_secret
|
|
38
|
+
self._services: dict[str, Base] = {}
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def oauth(self) -> OAuthClientProtocol:
|
|
42
|
+
if self._session is None:
|
|
43
|
+
raise RuntimeError(
|
|
44
|
+
"Client session not initialized. Use as an async context manager."
|
|
45
|
+
)
|
|
46
|
+
if self._oauth is None:
|
|
47
|
+
self._oauth = self._oauth_cls(
|
|
48
|
+
client_id=self._client_id,
|
|
49
|
+
client_secret=self._client_secret,
|
|
50
|
+
session=self._session,
|
|
51
|
+
)
|
|
52
|
+
return self._oauth
|
|
53
|
+
|
|
54
|
+
def _get_service(self, name: str, base_url: str) -> Base:
|
|
55
|
+
if name not in self._services:
|
|
56
|
+
service_cls = self._service_classes[name]
|
|
57
|
+
if self._session is None:
|
|
58
|
+
raise RuntimeError(
|
|
59
|
+
"Client session not initialized. Use as an async context manager."
|
|
60
|
+
)
|
|
61
|
+
self._services[name] = service_cls(self._session, self.oauth, base_url)
|
|
62
|
+
return self._services[name]
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def cms(self) -> CMS:
|
|
66
|
+
return cast("CMS", self._get_service("cms", self._cms_base_url))
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def syndication(self) -> Syndication:
|
|
70
|
+
return cast(
|
|
71
|
+
"Syndication", self._get_service("syndication", self._syndication_base_url)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def analytics(self) -> Analytics:
|
|
76
|
+
return cast(
|
|
77
|
+
"Analytics", self._get_service("analytics", self._analytics_base_url)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
async def __aenter__(self) -> Self:
|
|
81
|
+
if self._session is None:
|
|
82
|
+
self._session = aiohttp.ClientSession(
|
|
83
|
+
connector=aiohttp.TCPConnector(limit=100)
|
|
84
|
+
)
|
|
85
|
+
return self
|
|
86
|
+
|
|
87
|
+
async def __aexit__(self, exc_type, exc, tb) -> None:
|
|
88
|
+
if self._session and not self._external_session:
|
|
89
|
+
await self._session.close()
|
|
90
|
+
self._session = None
|
|
91
|
+
self._services.clear()
|
|
92
|
+
self._oauth = None
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from brightcove_async.client import BrightcoveClient
|
|
2
|
+
from brightcove_async.oauth.oauth import OAuthClient
|
|
3
|
+
from brightcove_async.settings import BrightcoveBaseAPIConfig, BrightcoveOAuthCreds
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def initialise_brightcove_client(
|
|
7
|
+
oauth_creds: BrightcoveOAuthCreds | None = None,
|
|
8
|
+
client_config: BrightcoveBaseAPIConfig | None = None,
|
|
9
|
+
) -> BrightcoveClient:
|
|
10
|
+
"""Initialise the Brightcove client with OAuth credentials.
|
|
11
|
+
Returns the configured OAuthClient.
|
|
12
|
+
"""
|
|
13
|
+
client_credentials = BrightcoveOAuthCreds() if oauth_creds is None else oauth_creds # type: ignore[ReportCallIssueType]
|
|
14
|
+
|
|
15
|
+
client_config = (
|
|
16
|
+
BrightcoveBaseAPIConfig() if client_config is None else client_config
|
|
17
|
+
) # type: ignore[ReportCallIssueType]
|
|
18
|
+
|
|
19
|
+
return BrightcoveClient(
|
|
20
|
+
client_id=client_credentials.client_id,
|
|
21
|
+
client_secret=client_credentials.client_secret.get_secret_value(),
|
|
22
|
+
oauth_cls=OAuthClient,
|
|
23
|
+
cms_base_url=client_config.cms_base_url,
|
|
24
|
+
syndication_base_url=client_config.syndication_base_url,
|
|
25
|
+
analytics_base_url=client_config.analytics_base_url,
|
|
26
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
from aiohttp import BasicAuth
|
|
5
|
+
from tenacity import (
|
|
6
|
+
retry,
|
|
7
|
+
retry_if_exception_type,
|
|
8
|
+
stop_after_attempt,
|
|
9
|
+
wait_exponential,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OAuthClient:
|
|
14
|
+
base_url = "https://oauth.brightcove.com/v4/access_token"
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self, client_id: str, client_secret: str, session: aiohttp.ClientSession
|
|
18
|
+
) -> None:
|
|
19
|
+
self.client_id = client_id
|
|
20
|
+
self.client_secret = client_secret
|
|
21
|
+
self._access_token: str | None = None
|
|
22
|
+
self._request_time = 0.0
|
|
23
|
+
self._token_life = 240.0 # Token expires after 4 minutes
|
|
24
|
+
self._session: aiohttp.ClientSession = session
|
|
25
|
+
|
|
26
|
+
@retry(
|
|
27
|
+
retry=retry_if_exception_type(
|
|
28
|
+
(aiohttp.ClientConnectionError),
|
|
29
|
+
),
|
|
30
|
+
wait=wait_exponential(multiplier=1, min=1, max=3), # exponential backoff
|
|
31
|
+
stop=stop_after_attempt(3), # up to 5 retries
|
|
32
|
+
)
|
|
33
|
+
async def _get_access_token(self) -> None:
|
|
34
|
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
35
|
+
data = {"grant_type": "client_credentials"}
|
|
36
|
+
|
|
37
|
+
async with (
|
|
38
|
+
self._session.post(
|
|
39
|
+
url=self.base_url,
|
|
40
|
+
headers=headers,
|
|
41
|
+
data=data,
|
|
42
|
+
auth=BasicAuth(self.client_id, self.client_secret),
|
|
43
|
+
timeout=aiohttp.ClientTimeout(total=10),
|
|
44
|
+
) as response,
|
|
45
|
+
):
|
|
46
|
+
response.raise_for_status()
|
|
47
|
+
json_data = await response.json()
|
|
48
|
+
self._access_token = json_data.get("access_token")
|
|
49
|
+
self._request_time = time.time()
|
|
50
|
+
|
|
51
|
+
async def get_access_token(self) -> str:
|
|
52
|
+
if (
|
|
53
|
+
not self._access_token
|
|
54
|
+
or time.time() - self._request_time > self._token_life
|
|
55
|
+
):
|
|
56
|
+
await self._get_access_token()
|
|
57
|
+
|
|
58
|
+
if not self._access_token:
|
|
59
|
+
raise ValueError("Failed to fetch access token.")
|
|
60
|
+
|
|
61
|
+
return self._access_token
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
async def headers(self) -> dict[str, str]:
|
|
65
|
+
access_token = await self.get_access_token()
|
|
66
|
+
return {
|
|
67
|
+
"Authorization": f"Bearer {access_token}",
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import Protocol, runtime_checkable
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@runtime_checkable
|
|
7
|
+
class OAuthClientProtocol(Protocol):
|
|
8
|
+
def __init__(
|
|
9
|
+
self, client_id: str, client_secret: str, session: aiohttp.ClientSession
|
|
10
|
+
) -> None: ...
|
|
11
|
+
|
|
12
|
+
async def get_access_token(self) -> str: ...
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
async def headers(self) -> dict[str, str]: ...
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# generated by datamodel-codegen:
|
|
2
|
+
# filename: cms.yaml
|
|
3
|
+
# timestamp: 2025-07-18T07:27:42+00:00
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Sources(BaseModel):
|
|
11
|
+
src: str = Field(..., description="URL for a image source image")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# generated by datamodel-codegen:
|
|
2
|
+
# filename: cms.yaml
|
|
3
|
+
# timestamp: 2025-07-18T07:27:42+00:00
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CustomField(BaseModel):
|
|
13
|
+
description: Optional[str] = Field(
|
|
14
|
+
None, description="description (instruction for user)"
|
|
15
|
+
)
|
|
16
|
+
display_name: Optional[str] = Field(None, description="display name")
|
|
17
|
+
enum_values: Optional[List[str]] = Field(
|
|
18
|
+
None, description="array of string values for select type fields"
|
|
19
|
+
)
|
|
20
|
+
id: Optional[str] = Field(
|
|
21
|
+
None,
|
|
22
|
+
description="data name for the field (used to access it in searches, etc.)",
|
|
23
|
+
)
|
|
24
|
+
required: Optional[bool] = Field(
|
|
25
|
+
False, description="whether field must have a value before video can be active"
|
|
26
|
+
)
|
|
27
|
+
type: Optional[str] = Field(None, description="custom field type (enum or string)")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class StandardField(BaseModel):
|
|
31
|
+
description: Optional[str] = Field(
|
|
32
|
+
None, description="description (instruction for user)"
|
|
33
|
+
)
|
|
34
|
+
id: Optional[str] = Field(
|
|
35
|
+
None,
|
|
36
|
+
description="data name for the field (used to access it in searches, etc.)",
|
|
37
|
+
)
|
|
38
|
+
required: Optional[bool] = Field(
|
|
39
|
+
None, description="whether field must have a value before video can be active"
|
|
40
|
+
)
|