oridio 0.1.0__py3-none-any.whl

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.
oridio/__init__.py ADDED
@@ -0,0 +1,99 @@
1
+ """
2
+ Oridio Python SDK — AI Control Plane
3
+
4
+ Drop-in OpenAI-compatible proxy with policy enforcement,
5
+ semantic caching, cost controls, and observability.
6
+ """
7
+
8
+ __version__ = "0.1.0"
9
+
10
+ from .client import OridioClient, AsyncOridioClient
11
+ from .decorators import oridio_protected
12
+ from .context import (
13
+ set_agent_id, get_agent_id,
14
+ set_session_id, get_session_id,
15
+ set_run_id, get_run_id
16
+ )
17
+ from .bootstrap import init
18
+ from .tools.bridge import wrap_tool, register_autogen_tool
19
+ from .tools.schema import extract_mcp_schema
20
+ from .interceptors import (
21
+ create_openai_client,
22
+ create_async_openai_client,
23
+ create_anthropic_client,
24
+ create_async_anthropic_client,
25
+ spawn_child,
26
+ )
27
+ from .exceptions import (
28
+ OridioError,
29
+ OridioAPIError,
30
+ OridioAuthError,
31
+ OridioRateLimitError,
32
+ OridioPolicyBlockedError,
33
+ OridioTimeoutError,
34
+ OridioHITLPendingError,
35
+ OridioHITLTimeoutError,
36
+ OridioHITLDeniedError,
37
+ )
38
+ from .models import (
39
+ ChatMessage,
40
+ ChatCompletionRequest,
41
+ ChatCompletionResponse,
42
+ McpGrant,
43
+ McpServer,
44
+ McpTool,
45
+ Policy,
46
+ PolicyRule,
47
+ ApiKey,
48
+ UsageRecord,
49
+ AgentStatus,
50
+ AgentIdentity,
51
+ MCPMeta,
52
+ MCPParams,
53
+ MCPPayload,
54
+ FirewallVerdict,
55
+ OridioResponse,
56
+ )
57
+
58
+ __all__ = [
59
+ "__version__",
60
+ # Client
61
+ "OridioClient",
62
+ "AsyncOridioClient",
63
+ "oridio_protected",
64
+ "create_openai_client",
65
+ "create_async_openai_client",
66
+ "create_anthropic_client",
67
+ "create_async_anthropic_client",
68
+ "spawn_child",
69
+ # Exceptions
70
+ "OridioError",
71
+ "OridioAPIError",
72
+ "OridioAuthError",
73
+ "OridioRateLimitError",
74
+ "OridioPolicyBlockedError",
75
+ "OridioTimeoutError",
76
+ "OridioHITLPendingError",
77
+ "OridioHITLTimeoutError",
78
+ "OridioHITLDeniedError",
79
+ "extract_mcp_schema",
80
+ # Models
81
+ "ChatMessage",
82
+ "ChatCompletionRequest",
83
+ "ChatCompletionResponse",
84
+ "McpGrant",
85
+ "McpServer",
86
+ "McpTool",
87
+ "Policy",
88
+ "PolicyRule",
89
+ "ApiKey",
90
+ "UsageRecord",
91
+ "AgentStatus",
92
+ "AgentIdentity",
93
+ "MCPMeta",
94
+ "MCPParams",
95
+ "MCPPayload",
96
+ "FirewallVerdict",
97
+ "OridioResponse",
98
+ ]
99
+
oridio/bootstrap.py ADDED
@@ -0,0 +1,45 @@
1
+ import os
2
+ import logging
3
+ from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
4
+ from opentelemetry.instrumentation.requests import RequestsInstrumentor
5
+ from .context import get_agent_id
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ def _request_hook(span, request):
10
+ """Inject Oridio headers into outbound HTTP requests."""
11
+ agent_id = get_agent_id()
12
+ if agent_id:
13
+ request.headers["X-Oridio-Agent-Id"] = agent_id
14
+
15
+ # The JWT is typically already in the environment or set by the user,
16
+ # but if we wanted to auto-inject a known key here we could.
17
+ oridio_api_key = os.environ.get("ORIDIO_API_KEY")
18
+ if oridio_api_key and "Authorization" not in request.headers:
19
+ request.headers["Authorization"] = f"Bearer {oridio_api_key}"
20
+
21
+ def init():
22
+ """
23
+ Initialize global Oridio interception for Python.
24
+
25
+ 1. Sets OPENAI_BASE_URL and ANTHROPIC_BASE_URL to point to the proxy.
26
+ 2. Hooks httpx and requests via OpenTelemetry to inject identity headers.
27
+ """
28
+ proxy_url = os.environ.get("ORIDIO_PROXY_URL", "http://localhost:8080")
29
+
30
+ # Force OpenAI and Anthropic SDKs to use the Oridio proxy
31
+ os.environ.setdefault("OPENAI_BASE_URL", f"{proxy_url}/v1")
32
+ os.environ.setdefault("ANTHROPIC_BASE_URL", f"{proxy_url}/v1")
33
+
34
+ try:
35
+ HTTPXClientInstrumentor().instrument(request_hook=_request_hook)
36
+ logger.info("Successfully instrumented httpx.")
37
+ except Exception as e:
38
+ logger.warning(f"Failed to instrument httpx: {e}")
39
+
40
+ try:
41
+ RequestsInstrumentor().instrument(request_hook=_request_hook)
42
+ logger.info("Successfully instrumented requests.")
43
+ except Exception as e:
44
+ logger.warning(f"Failed to instrument requests: {e}")
45
+