typecast-python 0.3.2__tar.gz → 0.3.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: typecast-python
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Official Typecast Python SDK - Convert text to lifelike speech using AI-powered voices
5
5
  Project-URL: Homepage, https://typecast.ai
6
6
  Project-URL: Documentation, https://typecast.ai/docs/overview
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "typecast-python"
7
- version = "0.3.2"
7
+ version = "0.3.3"
8
8
  description = "Official Typecast Python SDK - Convert text to lifelike speech using AI-powered voices"
9
9
  authors = [
10
10
  {name = "Neosapience", email = "help@typecast.ai"}
@@ -68,6 +68,8 @@ class AsyncTypecast:
68
68
  """
69
69
  self.host = conf.get_host(host)
70
70
  self.api_key = conf.get_api_key(api_key)
71
+ if not self.api_key and conf.is_default_host(self.host):
72
+ raise ValueError("API key is required for the default Typecast API host")
71
73
  self.session: Optional[aiohttp.ClientSession] = None
72
74
 
73
75
  async def __aenter__(self):
@@ -77,10 +77,13 @@ class Typecast:
77
77
  """
78
78
  self.host = conf.get_host(host)
79
79
  self.api_key = conf.get_api_key(api_key)
80
+ if not self.api_key and conf.is_default_host(self.host):
81
+ raise ValueError("API key is required for the default Typecast API host")
80
82
  self.session = requests.Session()
81
- self.session.headers.update(
82
- {"X-API-KEY": self.api_key, "Content-Type": "application/json"}
83
- )
83
+ headers = {"Content-Type": "application/json"}
84
+ if self.api_key:
85
+ headers["X-API-KEY"] = self.api_key
86
+ self.session.headers.update(headers)
84
87
 
85
88
  def _handle_error(self, status_code: int, response_text: str):
86
89
  """Handle HTTP error responses with specific exception types."""
@@ -0,0 +1,25 @@
1
+ import os
2
+
3
+ TYPECAST_API_HOST = "https://api.typecast.ai"
4
+
5
+
6
+ def get_host(host=None):
7
+ if host: # Parameter takes priority
8
+ return normalize_host(host)
9
+ env_host = os.getenv("TYPECAST_API_HOST") # Check environment variable
10
+ return normalize_host(env_host) if env_host else TYPECAST_API_HOST # Use default if not set
11
+
12
+
13
+ def get_api_key(api_key=None):
14
+ if api_key: # Parameter takes priority
15
+ return api_key.strip()
16
+ env_key = os.getenv("TYPECAST_API_KEY") # Return from environment variable
17
+ return env_key.strip() if env_key else None
18
+
19
+
20
+ def normalize_host(host):
21
+ return host.strip().rstrip("/")
22
+
23
+
24
+ def is_default_host(host):
25
+ return normalize_host(host).lower() == TYPECAST_API_HOST
@@ -1,16 +0,0 @@
1
- import os
2
-
3
- TYPECAST_API_HOST = "https://api.typecast.ai"
4
-
5
-
6
- def get_host(host=None):
7
- if host: # Parameter takes priority
8
- return host
9
- env_host = os.getenv("TYPECAST_API_HOST") # Check environment variable
10
- return env_host if env_host else TYPECAST_API_HOST # Use default if not set
11
-
12
-
13
- def get_api_key(api_key=None):
14
- if api_key: # Parameter takes priority
15
- return api_key
16
- return os.getenv("TYPECAST_API_KEY") # Return from environment variable
File without changes