nexttoken 0.3.2__tar.gz → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nexttoken
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: NextToken SDK - Simple client for the NextToken APIs and Gateway
5
5
  Project-URL: Homepage, https://nexttoken.co
6
6
  Project-URL: Documentation, https://docs.nexttoken.co
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nexttoken"
7
- version = "0.3.2"
7
+ version = "0.4.0"
8
8
  description = "NextToken SDK - Simple client for the NextToken APIs and Gateway"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,8 +1,9 @@
1
1
  """NextToken SDK - Simple client for the NextToken Gateway."""
2
2
 
3
3
  from .client import NextToken
4
+ from .email import Email
4
5
  from .integrations import Integrations
5
6
  from .search import Search
6
7
 
7
- __version__ = "0.3.0"
8
- __all__ = ["NextToken", "Integrations", "Search", "__version__"]
8
+ __version__ = "0.4.0"
9
+ __all__ = ["NextToken", "Email", "Integrations", "Search", "__version__"]
@@ -6,6 +6,7 @@ import os
6
6
 
7
7
  from openai import OpenAI
8
8
 
9
+ from .email import Email
9
10
  from .integrations import Integrations
10
11
  from .search import Search
11
12
 
@@ -55,6 +56,7 @@ class NextToken:
55
56
  base_url=gateway_url,
56
57
  )
57
58
  api_url = api_base_url or os.environ.get("NEXTTOKEN_API_BASE_URL")
59
+ self._email = Email(api_key=resolved_key, base_url=api_url)
58
60
  self._integrations = Integrations(api_key=resolved_key, base_url=api_url)
59
61
  self._search = Search(api_key=resolved_key, base_url=api_url)
60
62
 
@@ -73,6 +75,11 @@ class NextToken:
73
75
  """Access models list."""
74
76
  return self._client.models
75
77
 
78
+ @property
79
+ def email(self) -> Email:
80
+ """Access email API for sending transactional emails."""
81
+ return self._email
82
+
76
83
  @property
77
84
  def integrations(self) -> Integrations:
78
85
  """Access integrations API for connected third-party services."""
@@ -0,0 +1,82 @@
1
+ """NextToken Email client for sending transactional emails."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Dict, Optional
6
+
7
+ import requests
8
+
9
+
10
+ class Email:
11
+ """Client for NextToken Email API.
12
+
13
+ Sends emails on behalf of the authenticated user via the
14
+ NextToken transactional email service.
15
+
16
+ Example:
17
+ >>> from nexttoken import NextToken
18
+ >>> client = NextToken(api_key="your-api-key")
19
+ >>> result = client.email.send(
20
+ ... subject="Daily Report",
21
+ ... body="Here is your daily report...",
22
+ ... )
23
+ >>> print(result) # {"success": True, "message_id": "..."}
24
+ """
25
+
26
+ DEFAULT_BASE_URL = "https://api.nexttoken.co"
27
+
28
+ def __init__(self, api_key: str, base_url: Optional[str] = None):
29
+ self._api_key = api_key
30
+ self._base_url = (base_url or self.DEFAULT_BASE_URL).rstrip("/")
31
+
32
+ def _headers(self) -> Dict[str, str]:
33
+ return {
34
+ "Authorization": f"Bearer {self._api_key}",
35
+ "Content-Type": "application/json",
36
+ }
37
+
38
+ def _request(self, method: str, path: str, **kwargs) -> Dict[str, Any]:
39
+ url = f"{self._base_url}{path}"
40
+ response = requests.request(
41
+ method, url, headers=self._headers(), **kwargs
42
+ )
43
+ response.raise_for_status()
44
+ return response.json()
45
+
46
+ def send(
47
+ self,
48
+ subject: str,
49
+ body: str,
50
+ to: Optional[str] = None,
51
+ body_html: Optional[str] = None,
52
+ ) -> Dict[str, Any]:
53
+ """Send an email.
54
+
55
+ The email is sent from a personalized NextToken address
56
+ (e.g., ``John Doe <john-doe@nexttoken.dev>``) with reply-to
57
+ set to the user's real email address.
58
+
59
+ Args:
60
+ subject: Email subject line.
61
+ body: Plain text email body.
62
+ to: Recipient address. Defaults to the user's own email.
63
+ body_html: Optional HTML body for rich formatting.
64
+
65
+ Returns:
66
+ Dict with ``success`` and ``message_id`` keys.
67
+ """
68
+ payload: Dict[str, Any] = {"subject": subject, "body": body}
69
+ if to is not None:
70
+ payload["to"] = to
71
+ if body_html is not None:
72
+ payload["body_html"] = body_html
73
+
74
+ return self._request("POST", "/email/send", json=payload)
75
+
76
+ def usage(self) -> Dict[str, Any]:
77
+ """Get email usage stats for the authenticated user.
78
+
79
+ Returns:
80
+ Dict with ``sent_today``, ``daily_limit``, and ``tier`` keys.
81
+ """
82
+ return self._request("GET", "/api/public/email/usage")
File without changes
File without changes