promptrails 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.
- promptrails-0.1.0/LICENSE +21 -0
- promptrails-0.1.0/PKG-INFO +144 -0
- promptrails-0.1.0/README.md +114 -0
- promptrails-0.1.0/promptrails/__init__.py +90 -0
- promptrails-0.1.0/promptrails/_async_http.py +66 -0
- promptrails-0.1.0/promptrails/_http.py +66 -0
- promptrails-0.1.0/promptrails/async_client.py +77 -0
- promptrails-0.1.0/promptrails/client.py +77 -0
- promptrails-0.1.0/promptrails/config.py +20 -0
- promptrails-0.1.0/promptrails/exceptions.py +86 -0
- promptrails-0.1.0/promptrails/pagination.py +33 -0
- promptrails-0.1.0/promptrails/resources/__init__.py +63 -0
- promptrails-0.1.0/promptrails/resources/a2a.py +164 -0
- promptrails-0.1.0/promptrails/resources/agents.py +361 -0
- promptrails-0.1.0/promptrails/resources/approvals.py +71 -0
- promptrails-0.1.0/promptrails/resources/base.py +26 -0
- promptrails-0.1.0/promptrails/resources/chat.py +85 -0
- promptrails-0.1.0/promptrails/resources/costs.py +54 -0
- promptrails-0.1.0/promptrails/resources/credentials.py +105 -0
- promptrails-0.1.0/promptrails/resources/dashboard.py +24 -0
- promptrails-0.1.0/promptrails/resources/data_sources.py +183 -0
- promptrails-0.1.0/promptrails/resources/executions.py +57 -0
- promptrails-0.1.0/promptrails/resources/guardrails.py +22 -0
- promptrails-0.1.0/promptrails/resources/llm_models.py +39 -0
- promptrails-0.1.0/promptrails/resources/mcp_templates.py +109 -0
- promptrails-0.1.0/promptrails/resources/mcp_tools.py +129 -0
- promptrails-0.1.0/promptrails/resources/memories.py +22 -0
- promptrails-0.1.0/promptrails/resources/prompts.py +195 -0
- promptrails-0.1.0/promptrails/resources/scores.py +256 -0
- promptrails-0.1.0/promptrails/resources/sessions.py +29 -0
- promptrails-0.1.0/promptrails/resources/templates.py +59 -0
- promptrails-0.1.0/promptrails/resources/traces.py +57 -0
- promptrails-0.1.0/promptrails/resources/webhook_triggers.py +81 -0
- promptrails-0.1.0/promptrails/types.py +845 -0
- promptrails-0.1.0/promptrails.egg-info/PKG-INFO +144 -0
- promptrails-0.1.0/promptrails.egg-info/SOURCES.txt +43 -0
- promptrails-0.1.0/promptrails.egg-info/dependency_links.txt +1 -0
- promptrails-0.1.0/promptrails.egg-info/requires.txt +7 -0
- promptrails-0.1.0/promptrails.egg-info/top_level.txt +1 -0
- promptrails-0.1.0/pyproject.toml +72 -0
- promptrails-0.1.0/setup.cfg +4 -0
- promptrails-0.1.0/tests/test_agents.py +163 -0
- promptrails-0.1.0/tests/test_client.py +83 -0
- promptrails-0.1.0/tests/test_executions.py +61 -0
- promptrails-0.1.0/tests/test_prompts.py +115 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PromptRails
|
|
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,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: promptrails
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the PromptRails API
|
|
5
|
+
Author-email: PromptRails <support@promptrails.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/promptrails/promptrails
|
|
8
|
+
Project-URL: Documentation, https://promptrails.ai/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/promptrails/promptrails
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
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: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: httpx>=0.25.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
27
|
+
Requires-Dist: respx>=0.20; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff>=0.8.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# PromptRails Python SDK
|
|
32
|
+
|
|
33
|
+
[](https://pypi.org/project/promptrails/)
|
|
34
|
+
[](https://pypi.org/project/promptrails/)
|
|
35
|
+
[](https://opensource.org/licenses/MIT)
|
|
36
|
+
|
|
37
|
+
Official Python SDK for [PromptRails](https://promptrails.ai) — the AI agent orchestration platform.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install promptrails
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Synchronous
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from promptrails import PromptRails
|
|
51
|
+
|
|
52
|
+
client = PromptRails(api_key="pr_key_...")
|
|
53
|
+
|
|
54
|
+
# Execute an agent
|
|
55
|
+
result = client.agents.execute("agent-id", input={"query": "Summarise this week's sales"})
|
|
56
|
+
print(result.output)
|
|
57
|
+
|
|
58
|
+
client.close()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Async
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
from promptrails import AsyncPromptRails
|
|
66
|
+
|
|
67
|
+
async def main():
|
|
68
|
+
async with AsyncPromptRails(api_key="pr_key_...") as client:
|
|
69
|
+
result = await client.agents.execute("agent-id", input={"query": "hello"})
|
|
70
|
+
print(result.output)
|
|
71
|
+
|
|
72
|
+
asyncio.run(main())
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Context Manager
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
with PromptRails(api_key="pr_key_...") as client:
|
|
79
|
+
agents = client.agents.list()
|
|
80
|
+
for agent in agents.data:
|
|
81
|
+
print(agent.name)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Error Handling
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from promptrails import NotFoundError, ValidationError, RateLimitError, QuotaExceededError
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
result = client.agents.execute("agent-id", input={})
|
|
91
|
+
except QuotaExceededError:
|
|
92
|
+
print("Execution limit reached — upgrade your plan")
|
|
93
|
+
except RateLimitError:
|
|
94
|
+
print("Too many requests, back off and retry")
|
|
95
|
+
except NotFoundError as e:
|
|
96
|
+
print(f"Agent not found: {e.message}")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Available Resources
|
|
100
|
+
|
|
101
|
+
| Resource | Methods |
|
|
102
|
+
| ------------------------- | ------------------------------------------------------------------------ |
|
|
103
|
+
| `client.agents` | `list`, `get`, `create`, `update`, `delete`, `execute`, `list_versions`, `create_version`, `list_guardrails`, `create_guardrail`, `list_memories`, `create_memory`, `search_memories`, `delete_all_memories` |
|
|
104
|
+
| `client.prompts` | `list`, `get`, `create`, `update`, `delete`, `list_versions`, `create_version` |
|
|
105
|
+
| `client.executions` | `list`, `get` |
|
|
106
|
+
| `client.credentials` | `list`, `get`, `create`, `update`, `delete`, `set_default`, `check_connection` |
|
|
107
|
+
| `client.data_sources` | `list`, `get`, `create`, `update`, `delete`, `list_versions`, `create_version`, `test_connection`, `query` |
|
|
108
|
+
| `client.chat` | `list_sessions`, `get_session`, `create_session`, `delete_session`, `list_messages`, `send_message` |
|
|
109
|
+
| `client.traces` | `list`, `get_by_trace_id` |
|
|
110
|
+
| `client.costs` | `get_summary`, `get_agent_summary` |
|
|
111
|
+
| `client.scores` | `list`, `get`, `create`, `update`, `delete`, `list_configs`, `get_config`, `create_config`, `update_config`, `delete_config`, `aggregates` |
|
|
112
|
+
| `client.mcp_tools` | `list`, `get`, `create`, `update`, `delete` |
|
|
113
|
+
| `client.approvals` | `list`, `get`, `decide` |
|
|
114
|
+
| `client.webhook_triggers` | `list`, `get`, `create`, `update`, `delete` |
|
|
115
|
+
| `client.a2a` | `get_agent_card`, `send_message`, `get_task`, `list_tasks`, `cancel_task` |
|
|
116
|
+
|
|
117
|
+
## Configuration
|
|
118
|
+
|
|
119
|
+
| Option | Default | Description |
|
|
120
|
+
| ------------- | ---------------------------- | --------------------------------- |
|
|
121
|
+
| `api_key` | required | API key |
|
|
122
|
+
| `base_url` | `https://api.promptrails.ai` | API base URL |
|
|
123
|
+
| `timeout` | `30.0` | Request timeout (seconds) |
|
|
124
|
+
| `max_retries` | `3` | Max retries on network/5xx errors |
|
|
125
|
+
|
|
126
|
+
## Contributing
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Install development dependencies
|
|
130
|
+
pip install -e ".[dev]"
|
|
131
|
+
|
|
132
|
+
# Run linter
|
|
133
|
+
ruff check .
|
|
134
|
+
|
|
135
|
+
# Run formatter
|
|
136
|
+
ruff format .
|
|
137
|
+
|
|
138
|
+
# Run tests
|
|
139
|
+
pytest tests/ -v
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# PromptRails Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/promptrails/)
|
|
4
|
+
[](https://pypi.org/project/promptrails/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
Official Python SDK for [PromptRails](https://promptrails.ai) — the AI agent orchestration platform.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install promptrails
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### Synchronous
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from promptrails import PromptRails
|
|
21
|
+
|
|
22
|
+
client = PromptRails(api_key="pr_key_...")
|
|
23
|
+
|
|
24
|
+
# Execute an agent
|
|
25
|
+
result = client.agents.execute("agent-id", input={"query": "Summarise this week's sales"})
|
|
26
|
+
print(result.output)
|
|
27
|
+
|
|
28
|
+
client.close()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Async
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import asyncio
|
|
35
|
+
from promptrails import AsyncPromptRails
|
|
36
|
+
|
|
37
|
+
async def main():
|
|
38
|
+
async with AsyncPromptRails(api_key="pr_key_...") as client:
|
|
39
|
+
result = await client.agents.execute("agent-id", input={"query": "hello"})
|
|
40
|
+
print(result.output)
|
|
41
|
+
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Context Manager
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
with PromptRails(api_key="pr_key_...") as client:
|
|
49
|
+
agents = client.agents.list()
|
|
50
|
+
for agent in agents.data:
|
|
51
|
+
print(agent.name)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Error Handling
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from promptrails import NotFoundError, ValidationError, RateLimitError, QuotaExceededError
|
|
58
|
+
|
|
59
|
+
try:
|
|
60
|
+
result = client.agents.execute("agent-id", input={})
|
|
61
|
+
except QuotaExceededError:
|
|
62
|
+
print("Execution limit reached — upgrade your plan")
|
|
63
|
+
except RateLimitError:
|
|
64
|
+
print("Too many requests, back off and retry")
|
|
65
|
+
except NotFoundError as e:
|
|
66
|
+
print(f"Agent not found: {e.message}")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Available Resources
|
|
70
|
+
|
|
71
|
+
| Resource | Methods |
|
|
72
|
+
| ------------------------- | ------------------------------------------------------------------------ |
|
|
73
|
+
| `client.agents` | `list`, `get`, `create`, `update`, `delete`, `execute`, `list_versions`, `create_version`, `list_guardrails`, `create_guardrail`, `list_memories`, `create_memory`, `search_memories`, `delete_all_memories` |
|
|
74
|
+
| `client.prompts` | `list`, `get`, `create`, `update`, `delete`, `list_versions`, `create_version` |
|
|
75
|
+
| `client.executions` | `list`, `get` |
|
|
76
|
+
| `client.credentials` | `list`, `get`, `create`, `update`, `delete`, `set_default`, `check_connection` |
|
|
77
|
+
| `client.data_sources` | `list`, `get`, `create`, `update`, `delete`, `list_versions`, `create_version`, `test_connection`, `query` |
|
|
78
|
+
| `client.chat` | `list_sessions`, `get_session`, `create_session`, `delete_session`, `list_messages`, `send_message` |
|
|
79
|
+
| `client.traces` | `list`, `get_by_trace_id` |
|
|
80
|
+
| `client.costs` | `get_summary`, `get_agent_summary` |
|
|
81
|
+
| `client.scores` | `list`, `get`, `create`, `update`, `delete`, `list_configs`, `get_config`, `create_config`, `update_config`, `delete_config`, `aggregates` |
|
|
82
|
+
| `client.mcp_tools` | `list`, `get`, `create`, `update`, `delete` |
|
|
83
|
+
| `client.approvals` | `list`, `get`, `decide` |
|
|
84
|
+
| `client.webhook_triggers` | `list`, `get`, `create`, `update`, `delete` |
|
|
85
|
+
| `client.a2a` | `get_agent_card`, `send_message`, `get_task`, `list_tasks`, `cancel_task` |
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
| Option | Default | Description |
|
|
90
|
+
| ------------- | ---------------------------- | --------------------------------- |
|
|
91
|
+
| `api_key` | required | API key |
|
|
92
|
+
| `base_url` | `https://api.promptrails.ai` | API base URL |
|
|
93
|
+
| `timeout` | `30.0` | Request timeout (seconds) |
|
|
94
|
+
| `max_retries` | `3` | Max retries on network/5xx errors |
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Install development dependencies
|
|
100
|
+
pip install -e ".[dev]"
|
|
101
|
+
|
|
102
|
+
# Run linter
|
|
103
|
+
ruff check .
|
|
104
|
+
|
|
105
|
+
# Run formatter
|
|
106
|
+
ruff format .
|
|
107
|
+
|
|
108
|
+
# Run tests
|
|
109
|
+
pytest tests/ -v
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""PromptRails Python SDK."""
|
|
2
|
+
|
|
3
|
+
from .async_client import AsyncPromptRails
|
|
4
|
+
from .client import PromptRails
|
|
5
|
+
from .exceptions import (
|
|
6
|
+
ForbiddenError,
|
|
7
|
+
NotFoundError,
|
|
8
|
+
PromptRailsError,
|
|
9
|
+
RateLimitError,
|
|
10
|
+
ServerError,
|
|
11
|
+
UnauthorizedError,
|
|
12
|
+
ValidationError,
|
|
13
|
+
)
|
|
14
|
+
from .pagination import PaginatedResponse, PaginationMeta
|
|
15
|
+
from .types import (
|
|
16
|
+
Agent,
|
|
17
|
+
AgentExecution,
|
|
18
|
+
AgentMemory,
|
|
19
|
+
AgentVersion,
|
|
20
|
+
ApprovalRequest,
|
|
21
|
+
AvailableModelEntry,
|
|
22
|
+
AvailableModelGroup,
|
|
23
|
+
ChatMessage,
|
|
24
|
+
ChatSession,
|
|
25
|
+
CostSummary,
|
|
26
|
+
Credential,
|
|
27
|
+
DataSource,
|
|
28
|
+
DataSourceVersion,
|
|
29
|
+
ExecutionResult,
|
|
30
|
+
FlowTemplate,
|
|
31
|
+
Guardrail,
|
|
32
|
+
InstallMCPTemplateRequest,
|
|
33
|
+
LLMModel,
|
|
34
|
+
MCPCallToolResult,
|
|
35
|
+
MCPDiscoveredTool,
|
|
36
|
+
MCPDiscoverResult,
|
|
37
|
+
MCPTemplate,
|
|
38
|
+
MCPTemplateParameterSpec,
|
|
39
|
+
MCPTool,
|
|
40
|
+
MCPToolCallContent,
|
|
41
|
+
Prompt,
|
|
42
|
+
PromptVersion,
|
|
43
|
+
RunPromptResponse,
|
|
44
|
+
Trace,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
__version__ = "0.1.0"
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"Agent",
|
|
51
|
+
"AgentExecution",
|
|
52
|
+
"AgentMemory",
|
|
53
|
+
"AgentVersion",
|
|
54
|
+
"ApprovalRequest",
|
|
55
|
+
"AsyncPromptRails",
|
|
56
|
+
"AvailableModelEntry",
|
|
57
|
+
"AvailableModelGroup",
|
|
58
|
+
"ChatMessage",
|
|
59
|
+
"ChatSession",
|
|
60
|
+
"CostSummary",
|
|
61
|
+
"Credential",
|
|
62
|
+
"DataSource",
|
|
63
|
+
"DataSourceVersion",
|
|
64
|
+
"ExecutionResult",
|
|
65
|
+
"FlowTemplate",
|
|
66
|
+
"ForbiddenError",
|
|
67
|
+
"Guardrail",
|
|
68
|
+
"InstallMCPTemplateRequest",
|
|
69
|
+
"LLMModel",
|
|
70
|
+
"MCPCallToolResult",
|
|
71
|
+
"MCPDiscoverResult",
|
|
72
|
+
"MCPDiscoveredTool",
|
|
73
|
+
"MCPTemplate",
|
|
74
|
+
"MCPTemplateParameterSpec",
|
|
75
|
+
"MCPTool",
|
|
76
|
+
"MCPToolCallContent",
|
|
77
|
+
"NotFoundError",
|
|
78
|
+
"PaginatedResponse",
|
|
79
|
+
"PaginationMeta",
|
|
80
|
+
"Prompt",
|
|
81
|
+
"PromptRails",
|
|
82
|
+
"PromptRailsError",
|
|
83
|
+
"PromptVersion",
|
|
84
|
+
"RateLimitError",
|
|
85
|
+
"RunPromptResponse",
|
|
86
|
+
"ServerError",
|
|
87
|
+
"Trace",
|
|
88
|
+
"UnauthorizedError",
|
|
89
|
+
"ValidationError",
|
|
90
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from .config import Config
|
|
9
|
+
from .exceptions import RateLimitError, ServerError, raise_for_status
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AsyncHTTPClient:
|
|
13
|
+
"""Async HTTP wrapper around httpx."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, config: Config):
|
|
16
|
+
self._config = config
|
|
17
|
+
self._client = httpx.AsyncClient(
|
|
18
|
+
base_url=config.base_url,
|
|
19
|
+
headers=config.headers,
|
|
20
|
+
timeout=config.timeout,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
async def close(self):
|
|
24
|
+
await self._client.aclose()
|
|
25
|
+
|
|
26
|
+
async def request(
|
|
27
|
+
self,
|
|
28
|
+
method: str,
|
|
29
|
+
path: str,
|
|
30
|
+
*,
|
|
31
|
+
json: Optional[Dict[str, Any]] = None,
|
|
32
|
+
params: Optional[Dict[str, Any]] = None,
|
|
33
|
+
) -> Dict[str, Any]:
|
|
34
|
+
for attempt in range(self._config.max_retries + 1):
|
|
35
|
+
try:
|
|
36
|
+
response = await self._client.request(method, path, json=json, params=params)
|
|
37
|
+
body = response.json() if response.content else {}
|
|
38
|
+
if response.status_code >= 500:
|
|
39
|
+
raise ServerError(
|
|
40
|
+
message=body.get("error", "Server error"),
|
|
41
|
+
status_code=response.status_code,
|
|
42
|
+
)
|
|
43
|
+
raise_for_status(response.status_code, body)
|
|
44
|
+
return body
|
|
45
|
+
except (httpx.ConnectError, httpx.TimeoutException, ServerError):
|
|
46
|
+
if attempt < self._config.max_retries:
|
|
47
|
+
await asyncio.sleep(min(2**attempt, 8))
|
|
48
|
+
continue
|
|
49
|
+
raise
|
|
50
|
+
except RateLimitError:
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
async def get(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
54
|
+
return await self.request("GET", path, **kwargs)
|
|
55
|
+
|
|
56
|
+
async def post(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
57
|
+
return await self.request("POST", path, **kwargs)
|
|
58
|
+
|
|
59
|
+
async def patch(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
60
|
+
return await self.request("PATCH", path, **kwargs)
|
|
61
|
+
|
|
62
|
+
async def put(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
63
|
+
return await self.request("PUT", path, **kwargs)
|
|
64
|
+
|
|
65
|
+
async def delete(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
66
|
+
return await self.request("DELETE", path, **kwargs)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from .config import Config
|
|
9
|
+
from .exceptions import RateLimitError, ServerError, raise_for_status
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HTTPClient:
|
|
13
|
+
"""Synchronous HTTP wrapper around httpx."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, config: Config):
|
|
16
|
+
self._config = config
|
|
17
|
+
self._client = httpx.Client(
|
|
18
|
+
base_url=config.base_url,
|
|
19
|
+
headers=config.headers,
|
|
20
|
+
timeout=config.timeout,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def close(self):
|
|
24
|
+
self._client.close()
|
|
25
|
+
|
|
26
|
+
def request(
|
|
27
|
+
self,
|
|
28
|
+
method: str,
|
|
29
|
+
path: str,
|
|
30
|
+
*,
|
|
31
|
+
json: Optional[Dict[str, Any]] = None,
|
|
32
|
+
params: Optional[Dict[str, Any]] = None,
|
|
33
|
+
) -> Dict[str, Any]:
|
|
34
|
+
for attempt in range(self._config.max_retries + 1):
|
|
35
|
+
try:
|
|
36
|
+
response = self._client.request(method, path, json=json, params=params)
|
|
37
|
+
body = response.json() if response.content else {}
|
|
38
|
+
if response.status_code >= 500:
|
|
39
|
+
raise ServerError(
|
|
40
|
+
message=body.get("error", "Server error"),
|
|
41
|
+
status_code=response.status_code,
|
|
42
|
+
)
|
|
43
|
+
raise_for_status(response.status_code, body)
|
|
44
|
+
return body
|
|
45
|
+
except (httpx.ConnectError, httpx.TimeoutException, ServerError):
|
|
46
|
+
if attempt < self._config.max_retries:
|
|
47
|
+
time.sleep(min(2**attempt, 8))
|
|
48
|
+
continue
|
|
49
|
+
raise
|
|
50
|
+
except RateLimitError:
|
|
51
|
+
raise
|
|
52
|
+
|
|
53
|
+
def get(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
54
|
+
return self.request("GET", path, **kwargs)
|
|
55
|
+
|
|
56
|
+
def post(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
57
|
+
return self.request("POST", path, **kwargs)
|
|
58
|
+
|
|
59
|
+
def patch(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
60
|
+
return self.request("PATCH", path, **kwargs)
|
|
61
|
+
|
|
62
|
+
def put(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
63
|
+
return self.request("PUT", path, **kwargs)
|
|
64
|
+
|
|
65
|
+
def delete(self, path: str, **kwargs) -> Dict[str, Any]:
|
|
66
|
+
return self.request("DELETE", path, **kwargs)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ._async_http import AsyncHTTPClient
|
|
4
|
+
from .config import Config
|
|
5
|
+
from .resources import (
|
|
6
|
+
AsyncA2AResource,
|
|
7
|
+
AsyncAgentsResource,
|
|
8
|
+
AsyncApprovalsResource,
|
|
9
|
+
AsyncChatResource,
|
|
10
|
+
AsyncCostsResource,
|
|
11
|
+
AsyncCredentialsResource,
|
|
12
|
+
AsyncDashboardResource,
|
|
13
|
+
AsyncDataSourcesResource,
|
|
14
|
+
AsyncExecutionsResource,
|
|
15
|
+
AsyncGuardrailsResource,
|
|
16
|
+
AsyncLLMModelsResource,
|
|
17
|
+
AsyncMCPTemplatesResource,
|
|
18
|
+
AsyncMCPToolsResource,
|
|
19
|
+
AsyncMemoriesResource,
|
|
20
|
+
AsyncPromptsResource,
|
|
21
|
+
AsyncScoresResource,
|
|
22
|
+
AsyncSessionsResource,
|
|
23
|
+
AsyncTemplatesResource,
|
|
24
|
+
AsyncTracesResource,
|
|
25
|
+
AsyncWebhookTriggersResource,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AsyncPromptRails:
|
|
30
|
+
"""Async PromptRails API client."""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
api_key: str,
|
|
35
|
+
*,
|
|
36
|
+
base_url: str = "https://api.promptrails.ai",
|
|
37
|
+
timeout: float = 30.0,
|
|
38
|
+
max_retries: int = 3,
|
|
39
|
+
):
|
|
40
|
+
self._config = Config(
|
|
41
|
+
api_key=api_key,
|
|
42
|
+
base_url=base_url,
|
|
43
|
+
timeout=timeout,
|
|
44
|
+
max_retries=max_retries,
|
|
45
|
+
)
|
|
46
|
+
self._http = AsyncHTTPClient(self._config)
|
|
47
|
+
|
|
48
|
+
self.agents = AsyncAgentsResource(self._http)
|
|
49
|
+
self.prompts = AsyncPromptsResource(self._http)
|
|
50
|
+
self.executions = AsyncExecutionsResource(self._http)
|
|
51
|
+
self.credentials = AsyncCredentialsResource(self._http)
|
|
52
|
+
self.data_sources = AsyncDataSourcesResource(self._http)
|
|
53
|
+
self.chat = AsyncChatResource(self._http)
|
|
54
|
+
self.memories = AsyncMemoriesResource(self._http)
|
|
55
|
+
self.traces = AsyncTracesResource(self._http)
|
|
56
|
+
self.costs = AsyncCostsResource(self._http)
|
|
57
|
+
self.mcp_tools = AsyncMCPToolsResource(self._http)
|
|
58
|
+
self.mcp_templates = AsyncMCPTemplatesResource(self._http)
|
|
59
|
+
self.guardrails = AsyncGuardrailsResource(self._http)
|
|
60
|
+
self.llm_models = AsyncLLMModelsResource(self._http)
|
|
61
|
+
self.approvals = AsyncApprovalsResource(self._http)
|
|
62
|
+
self.templates = AsyncTemplatesResource(self._http)
|
|
63
|
+
self.scores = AsyncScoresResource(self._http)
|
|
64
|
+
self.dashboard = AsyncDashboardResource(self._http)
|
|
65
|
+
self.sessions = AsyncSessionsResource(self._http)
|
|
66
|
+
self.a2a = AsyncA2AResource(self._http)
|
|
67
|
+
self.webhook_triggers = AsyncWebhookTriggersResource(self._http)
|
|
68
|
+
|
|
69
|
+
async def close(self):
|
|
70
|
+
"""Close the underlying HTTP client."""
|
|
71
|
+
await self._http.close()
|
|
72
|
+
|
|
73
|
+
async def __aenter__(self):
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
async def __aexit__(self, *args):
|
|
77
|
+
await self.close()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ._http import HTTPClient
|
|
4
|
+
from .config import Config
|
|
5
|
+
from .resources import (
|
|
6
|
+
A2AResource,
|
|
7
|
+
AgentsResource,
|
|
8
|
+
ApprovalsResource,
|
|
9
|
+
ChatResource,
|
|
10
|
+
CostsResource,
|
|
11
|
+
CredentialsResource,
|
|
12
|
+
DashboardResource,
|
|
13
|
+
DataSourcesResource,
|
|
14
|
+
ExecutionsResource,
|
|
15
|
+
GuardrailsResource,
|
|
16
|
+
LLMModelsResource,
|
|
17
|
+
MCPTemplatesResource,
|
|
18
|
+
MCPToolsResource,
|
|
19
|
+
MemoriesResource,
|
|
20
|
+
PromptsResource,
|
|
21
|
+
ScoresResource,
|
|
22
|
+
SessionsResource,
|
|
23
|
+
TemplatesResource,
|
|
24
|
+
TracesResource,
|
|
25
|
+
WebhookTriggersResource,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class PromptRails:
|
|
30
|
+
"""Synchronous PromptRails API client."""
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
api_key: str,
|
|
35
|
+
*,
|
|
36
|
+
base_url: str = "https://api.promptrails.ai",
|
|
37
|
+
timeout: float = 30.0,
|
|
38
|
+
max_retries: int = 3,
|
|
39
|
+
):
|
|
40
|
+
self._config = Config(
|
|
41
|
+
api_key=api_key,
|
|
42
|
+
base_url=base_url,
|
|
43
|
+
timeout=timeout,
|
|
44
|
+
max_retries=max_retries,
|
|
45
|
+
)
|
|
46
|
+
self._http = HTTPClient(self._config)
|
|
47
|
+
|
|
48
|
+
self.agents = AgentsResource(self._http)
|
|
49
|
+
self.prompts = PromptsResource(self._http)
|
|
50
|
+
self.executions = ExecutionsResource(self._http)
|
|
51
|
+
self.credentials = CredentialsResource(self._http)
|
|
52
|
+
self.data_sources = DataSourcesResource(self._http)
|
|
53
|
+
self.chat = ChatResource(self._http)
|
|
54
|
+
self.memories = MemoriesResource(self._http)
|
|
55
|
+
self.traces = TracesResource(self._http)
|
|
56
|
+
self.costs = CostsResource(self._http)
|
|
57
|
+
self.mcp_tools = MCPToolsResource(self._http)
|
|
58
|
+
self.mcp_templates = MCPTemplatesResource(self._http)
|
|
59
|
+
self.guardrails = GuardrailsResource(self._http)
|
|
60
|
+
self.llm_models = LLMModelsResource(self._http)
|
|
61
|
+
self.approvals = ApprovalsResource(self._http)
|
|
62
|
+
self.templates = TemplatesResource(self._http)
|
|
63
|
+
self.scores = ScoresResource(self._http)
|
|
64
|
+
self.dashboard = DashboardResource(self._http)
|
|
65
|
+
self.sessions = SessionsResource(self._http)
|
|
66
|
+
self.a2a = A2AResource(self._http)
|
|
67
|
+
self.webhook_triggers = WebhookTriggersResource(self._http)
|
|
68
|
+
|
|
69
|
+
def close(self):
|
|
70
|
+
"""Close the underlying HTTP client."""
|
|
71
|
+
self._http.close()
|
|
72
|
+
|
|
73
|
+
def __enter__(self):
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def __exit__(self, *args):
|
|
77
|
+
self.close()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Config:
|
|
6
|
+
api_key: str
|
|
7
|
+
base_url: str = "https://api.promptrails.ai"
|
|
8
|
+
timeout: float = 30.0
|
|
9
|
+
max_retries: int = 3
|
|
10
|
+
|
|
11
|
+
def __post_init__(self):
|
|
12
|
+
self.base_url = self.base_url.rstrip("/")
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def headers(self) -> dict:
|
|
16
|
+
return {
|
|
17
|
+
"X-API-Key": self.api_key,
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
"Accept": "application/json",
|
|
20
|
+
}
|