pangea-sdk 5.2.0b1__tar.gz → 5.2.0b2__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.
Files changed (63) hide show
  1. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/PKG-INFO +6 -5
  2. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/README.md +4 -3
  3. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/__init__.py +1 -1
  4. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/__init__.py +2 -0
  5. pangea_sdk-5.2.0b2/pangea/asyncio/services/ai_guard.py +75 -0
  6. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/base.py +6 -1
  7. pangea_sdk-5.2.0b2/pangea/asyncio/services/prompt_guard.py +73 -0
  8. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/__init__.py +1 -1
  9. pangea_sdk-5.2.0b1/pangea/services/data_guard.py → pangea_sdk-5.2.0b2/pangea/services/ai_guard.py +42 -32
  10. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/base.py +2 -1
  11. pangea_sdk-5.2.0b2/pangea/services/prompt_guard.py +83 -0
  12. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/utils.py +8 -9
  13. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pyproject.toml +4 -4
  14. pangea_sdk-5.2.0b1/pangea/asyncio/services/data_guard.py +0 -65
  15. pangea_sdk-5.2.0b1/pangea/asyncio/services/prompt_guard.py +0 -39
  16. pangea_sdk-5.2.0b1/pangea/services/prompt_guard.py +0 -48
  17. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/__init__.py +0 -0
  18. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/file_uploader.py +0 -0
  19. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/request.py +0 -0
  20. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/audit.py +0 -0
  21. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/authn.py +0 -0
  22. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/authz.py +0 -0
  23. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/embargo.py +0 -0
  24. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/file_scan.py +0 -0
  25. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/intel.py +0 -0
  26. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/redact.py +0 -0
  27. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/sanitize.py +0 -0
  28. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/share.py +0 -0
  29. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/asyncio/services/vault.py +0 -0
  30. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/audit_logger.py +0 -0
  31. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/config.py +0 -0
  32. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/crypto/rsa.py +0 -0
  33. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/deep_verify.py +0 -0
  34. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/deprecated.py +0 -0
  35. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/dump_audit.py +0 -0
  36. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/exceptions.py +0 -0
  37. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/file_uploader.py +0 -0
  38. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/py.typed +0 -0
  39. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/request.py +0 -0
  40. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/response.py +0 -0
  41. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/audit/audit.py +0 -0
  42. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/audit/exceptions.py +0 -0
  43. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/audit/models.py +0 -0
  44. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/audit/signing.py +0 -0
  45. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/audit/util.py +0 -0
  46. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/authn/authn.py +0 -0
  47. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/authn/models.py +0 -0
  48. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/authz.py +0 -0
  49. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/embargo.py +0 -0
  50. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/file_scan.py +0 -0
  51. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/intel.py +0 -0
  52. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/redact.py +0 -0
  53. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/sanitize.py +0 -0
  54. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/share/file_format.py +0 -0
  55. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/share/share.py +0 -0
  56. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/models/asymmetric.py +0 -0
  57. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/models/common.py +0 -0
  58. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/models/keys.py +0 -0
  59. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/models/secret.py +0 -0
  60. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/models/symmetric.py +0 -0
  61. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/services/vault/vault.py +0 -0
  62. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/tools.py +0 -0
  63. {pangea_sdk-5.2.0b1 → pangea_sdk-5.2.0b2}/pangea/verify_audit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pangea-sdk
3
- Version: 5.2.0b1
3
+ Version: 5.2.0b2
4
4
  Summary: Pangea API SDK
5
5
  Home-page: https://pangea.cloud/docs/sdk/python/
6
6
  License: MIT
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Topic :: Software Development
19
19
  Classifier: Topic :: Software Development :: Libraries
20
20
  Requires-Dist: aiohttp (>=3.10.10,<4.0.0)
21
- Requires-Dist: cryptography (>=43.0.1,<44.0.0)
21
+ Requires-Dist: cryptography (>=43.0.3,<44.0.0)
22
22
  Requires-Dist: deprecated (>=1.2.14,<2.0.0)
23
23
  Requires-Dist: google-crc32c (>=1.5.0,<2.0.0)
24
24
  Requires-Dist: pydantic (>=2.9.2,<3.0.0)
@@ -64,9 +64,10 @@ $ poetry add pangea-sdk
64
64
  #### Beta releases
65
65
 
66
66
  Pre-release versions may be available with the `b` (beta) denotation in the
67
- version number. These releases serve to preview beta services and APIs. Per
68
- Semantic Versioning, they are considered unstable and do not carry the same
69
- compatibility guarantees as stable releases. [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
67
+ version number. These releases serve to preview Beta and Early Access services
68
+ and APIs. Per Semantic Versioning, they are considered unstable and do not carry
69
+ the same compatibility guarantees as stable releases.
70
+ [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
70
71
 
71
72
  Via pip:
72
73
 
@@ -33,9 +33,10 @@ $ poetry add pangea-sdk
33
33
  #### Beta releases
34
34
 
35
35
  Pre-release versions may be available with the `b` (beta) denotation in the
36
- version number. These releases serve to preview beta services and APIs. Per
37
- Semantic Versioning, they are considered unstable and do not carry the same
38
- compatibility guarantees as stable releases. [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
36
+ version number. These releases serve to preview Beta and Early Access services
37
+ and APIs. Per Semantic Versioning, they are considered unstable and do not carry
38
+ the same compatibility guarantees as stable releases.
39
+ [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
39
40
 
40
41
  Via pip:
41
42
 
@@ -1,4 +1,4 @@
1
- __version__ = "5.2.0beta1"
1
+ __version__ = "5.2.0beta2"
2
2
 
3
3
  from pangea.asyncio.request import PangeaRequestAsync
4
4
  from pangea.config import PangeaConfig
@@ -1,9 +1,11 @@
1
+ from .ai_guard import AIGuardAsync
1
2
  from .audit import AuditAsync
2
3
  from .authn import AuthNAsync
3
4
  from .authz import AuthZAsync
4
5
  from .embargo import EmbargoAsync
5
6
  from .file_scan import FileScanAsync
6
7
  from .intel import DomainIntelAsync, FileIntelAsync, IpIntelAsync, UrlIntelAsync, UserIntelAsync
8
+ from .prompt_guard import PromptGuardAsync
7
9
  from .redact import RedactAsync
8
10
  from .sanitize import SanitizeAsync
9
11
  from .share import ShareAsync
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ from pangea.asyncio.services.base import ServiceBaseAsync
4
+ from pangea.config import PangeaConfig
5
+ from pangea.response import PangeaResponse
6
+ from pangea.services.ai_guard import TextGuardResult
7
+
8
+
9
+ class AIGuardAsync(ServiceBaseAsync):
10
+ """AI Guard service client.
11
+
12
+ Provides methods to interact with Pangea's AI Guard service.
13
+
14
+ Examples:
15
+ from pangea import PangeaConfig
16
+ from pangea.asyncio.services import AIGuardAsync
17
+
18
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
19
+ ai_guard = AIGuardAsync(token="pangea_token", config=config)
20
+ """
21
+
22
+ service_name = "ai-guard"
23
+
24
+ def __init__(
25
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
26
+ ) -> None:
27
+ """
28
+ AI Guard service client.
29
+
30
+ Initializes a new AI Guard client.
31
+
32
+ Args:
33
+ token: Pangea API token.
34
+ config: Pangea service configuration.
35
+ logger_name: Logger name.
36
+ config_id: Configuration ID.
37
+
38
+ Examples:
39
+ from pangea import PangeaConfig
40
+ from pangea.asyncio.services import AIGuardAsync
41
+
42
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
43
+ ai_guard = AIGuardAsync(token="pangea_token", config=config)
44
+ """
45
+
46
+ super().__init__(token, config, logger_name, config_id)
47
+
48
+ async def guard_text(
49
+ self,
50
+ text: str,
51
+ *,
52
+ recipe: str = "pangea_prompt_guard",
53
+ debug: bool = False,
54
+ ) -> PangeaResponse[TextGuardResult]:
55
+ """
56
+ Text guard (Beta)
57
+
58
+ Guard text.
59
+
60
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
61
+
62
+ OperationId: ai_guard_post_v1beta_text_guard
63
+
64
+ Args:
65
+ text: Text.
66
+ recipe: Recipe.
67
+ debug: Debug.
68
+
69
+ Examples:
70
+ response = await ai_guard.guard_text("text")
71
+ """
72
+
73
+ return await self.request.post(
74
+ "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
75
+ )
@@ -1,8 +1,11 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+ from __future__ import annotations
3
4
 
4
5
  from typing import Dict, Optional, Type, Union
5
6
 
7
+ from typing_extensions import override
8
+
6
9
  from pangea.asyncio.request import PangeaRequestAsync
7
10
  from pangea.exceptions import AcceptedRequestException
8
11
  from pangea.response import AttachedFile, PangeaResponse, PangeaResponseResult
@@ -23,6 +26,7 @@ class ServiceBaseAsync(ServiceBase):
23
26
 
24
27
  return self._request
25
28
 
29
+ @override
26
30
  async def poll_result( # type: ignore[override]
27
31
  self,
28
32
  exception: Optional[AcceptedRequestException] = None,
@@ -36,7 +40,8 @@ class ServiceBaseAsync(ServiceBase):
36
40
  Returns request's result that has been accepted by the server
37
41
 
38
42
  Args:
39
- exception (AcceptedRequestException): Exception raise by SDK on the call that is been processed.
43
+ exception: Exception that was previously raised by the SDK on a call
44
+ that is being processed.
40
45
 
41
46
  Returns:
42
47
  PangeaResponse
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from pangea.asyncio.services.base import ServiceBaseAsync
6
+ from pangea.config import PangeaConfig
7
+ from pangea.services.prompt_guard import GuardResult, Message
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterable
11
+
12
+ from pangea.response import PangeaResponse
13
+
14
+
15
+ class PromptGuardAsync(ServiceBaseAsync):
16
+ """Prompt Guard service client.
17
+
18
+ Provides methods to interact with Pangea's Prompt Guard service.
19
+
20
+ Examples:
21
+ from pangea import PangeaConfig
22
+ from pangea.asyncio.services import PromptGuardAsync
23
+
24
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
25
+ prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
26
+ """
27
+
28
+ service_name = "prompt-guard"
29
+
30
+ def __init__(
31
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
32
+ ) -> None:
33
+ """
34
+ Prompt Guard service client.
35
+
36
+ Initializes a new Prompt Guard client.
37
+
38
+ Args:
39
+ token: Pangea API token.
40
+ config: Pangea service configuration.
41
+ logger_name: Logger name.
42
+ config_id: Configuration ID.
43
+
44
+ Examples:
45
+ from pangea import PangeaConfig
46
+ from pangea.asyncio.services import PromptGuardAsync
47
+
48
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
49
+ prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
50
+ """
51
+
52
+ super().__init__(token, config, logger_name, config_id)
53
+
54
+ async def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
55
+ """
56
+ Guard (Beta)
57
+
58
+ Guard messages.
59
+
60
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
61
+
62
+ OperationId: prompt_guard_post_v1beta_guard
63
+
64
+ Args:
65
+ messages: Messages.
66
+
67
+ Examples:
68
+ from pangea.asyncio.services.prompt_guard import Message
69
+
70
+ response = await prompt_guard.guard([Message(role="user", content="hello world")])
71
+ """
72
+
73
+ return await self.request.post("v1beta/guard", GuardResult, data={"messages": messages})
@@ -1,7 +1,7 @@
1
+ from .ai_guard import AIGuard
1
2
  from .audit.audit import Audit
2
3
  from .authn.authn import AuthN
3
4
  from .authz import AuthZ
4
- from .data_guard import DataGuard
5
5
  from .embargo import Embargo
6
6
  from .file_scan import FileScan
7
7
  from .intel import DomainIntel, FileIntel, IpIntel, UrlIntel, UserIntel
@@ -4,6 +4,7 @@ from typing import List, Optional
4
4
 
5
5
  from typing_extensions import Literal
6
6
 
7
+ from pangea.config import PangeaConfig
7
8
  from pangea.response import PangeaResponse, PangeaResponseResult
8
9
  from pangea.services.base import ServiceBase
9
10
  from pangea.services.intel import UserBreachedData
@@ -14,12 +15,12 @@ class TextGuardSecurityIssues(PangeaResponseResult):
14
15
  malicious_domain_count: int
15
16
  malicious_ip_count: int
16
17
  malicious_url_count: int
17
- redacted_item_count: int
18
+ redact_rule_match_count: int
18
19
 
19
20
 
20
21
  class TextGuardFindings(PangeaResponseResult):
21
- artifact_count: int
22
- malicious_count: int
22
+ artifact_count: Optional[int] = None
23
+ malicious_count: Optional[int] = None
23
24
  security_issues: TextGuardSecurityIssues
24
25
 
25
26
 
@@ -87,13 +88,44 @@ class TextGuardResult(PangeaResponseResult):
87
88
  report: Optional[TextGuardReport] = None
88
89
 
89
90
 
90
- class DataGuard(ServiceBase):
91
- """Data Guard service client.
91
+ class AIGuard(ServiceBase):
92
+ """AI Guard service client.
92
93
 
93
- Provides methods to interact with Pangea's Data Guard service.
94
+ Provides methods to interact with Pangea's AI Guard service.
95
+
96
+ Examples:
97
+ from pangea import PangeaConfig
98
+ from pangea.services import AIGuard
99
+
100
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
101
+ ai_guard = AIGuard(token="pangea_token", config=config)
94
102
  """
95
103
 
96
- service_name = "data-guard"
104
+ service_name = "ai-guard"
105
+
106
+ def __init__(
107
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
108
+ ) -> None:
109
+ """
110
+ AI Guard service client.
111
+
112
+ Initializes a new AI Guard client.
113
+
114
+ Args:
115
+ token: Pangea API token.
116
+ config: Pangea service configuration.
117
+ logger_name: Logger name.
118
+ config_id: Configuration ID.
119
+
120
+ Examples:
121
+ from pangea import PangeaConfig
122
+ from pangea.services import AIGuard
123
+
124
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
125
+ ai_guard = AIGuard(token="pangea_token", config=config)
126
+ """
127
+
128
+ super().__init__(token, config, logger_name, config_id)
97
129
 
98
130
  def guard_text(
99
131
  self,
@@ -109,7 +141,7 @@ class DataGuard(ServiceBase):
109
141
 
110
142
  How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
111
143
 
112
- OperationId: data_guard_post_v1_text_guard
144
+ OperationId: ai_guard_post_v1beta_text_guard
113
145
 
114
146
  Args:
115
147
  text: Text.
@@ -117,31 +149,9 @@ class DataGuard(ServiceBase):
117
149
  debug: Debug.
118
150
 
119
151
  Examples:
120
- response = data_guard.guard_text("text")
152
+ response = ai_guard.guard_text("text")
121
153
  """
122
154
 
123
155
  return self.request.post(
124
- "v1/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
156
+ "v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
125
157
  )
126
-
127
- def guard_file(
128
- self,
129
- file_url: str,
130
- ) -> PangeaResponse[PangeaResponseResult]:
131
- """
132
- File guard (Beta)
133
-
134
- Guard a file URL.
135
-
136
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
137
-
138
- OperationId: data_guard_post_v1_file_guard
139
-
140
- Args:
141
- file_url: File URL.
142
-
143
- Examples:
144
- response = data_guard.guard_file("https://example.org/file.txt")
145
- """
146
-
147
- return self.request.post("v1/file/guard", PangeaResponseResult, data={"file_url": file_url})
@@ -80,7 +80,8 @@ class ServiceBase(object):
80
80
  Returns request's result that has been accepted by the server
81
81
 
82
82
  Args:
83
- exception (AcceptedRequestException): Exception raise by SDK on the call that is been processed.
83
+ exception: Exception that was previously raised by the SDK on a call
84
+ that is being processed.
84
85
 
85
86
  Returns:
86
87
  PangeaResponse
@@ -0,0 +1,83 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Optional
4
+
5
+ from pangea.config import PangeaConfig
6
+ from pangea.response import APIRequestModel, PangeaResponse, PangeaResponseResult
7
+ from pangea.services.base import ServiceBase
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Iterable
11
+
12
+
13
+ class Message(APIRequestModel):
14
+ role: str
15
+ content: str
16
+
17
+
18
+ class GuardResult(PangeaResponseResult):
19
+ detected: bool
20
+ type: Optional[str] = None
21
+ detector: Optional[str] = None
22
+ confidence: int
23
+
24
+
25
+ class PromptGuard(ServiceBase):
26
+ """Prompt Guard service client.
27
+
28
+ Provides methods to interact with Pangea's Prompt Guard service.
29
+
30
+ Examples:
31
+ from pangea import PangeaConfig
32
+ from pangea.services import PromptGuard
33
+
34
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
35
+ prompt_guard = PromptGuard(token="pangea_token", config=config)
36
+ """
37
+
38
+ service_name = "prompt-guard"
39
+
40
+ def __init__(
41
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
42
+ ) -> None:
43
+ """
44
+ Prompt Guard service client.
45
+
46
+ Initializes a new Prompt Guard client.
47
+
48
+ Args:
49
+ token: Pangea API token.
50
+ config: Pangea service configuration.
51
+ logger_name: Logger name.
52
+ config_id: Configuration ID.
53
+
54
+ Examples:
55
+ from pangea import PangeaConfig
56
+ from pangea.services import PromptGuard
57
+
58
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
59
+ prompt_guard = PromptGuard(token="pangea_token", config=config)
60
+ """
61
+
62
+ super().__init__(token, config, logger_name, config_id)
63
+
64
+ def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
65
+ """
66
+ Guard (Beta)
67
+
68
+ Guard messages.
69
+
70
+ How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
71
+
72
+ OperationId: prompt_guard_post_v1beta_guard
73
+
74
+ Args:
75
+ messages: Messages.
76
+
77
+ Examples:
78
+ from pangea.services.prompt_guard import Message
79
+
80
+ response = prompt_guard.guard([Message(role="user", content="hello world")])
81
+ """
82
+
83
+ return self.request.post("v1beta/guard", GuardResult, data={"messages": messages})
@@ -6,7 +6,6 @@ import datetime
6
6
  import io
7
7
  import json
8
8
  from hashlib import md5, new, sha1, sha256, sha512
9
- from typing import Union
10
9
 
11
10
  from google_crc32c import Checksum as CRC32C
12
11
  from pydantic import BaseModel
@@ -67,7 +66,7 @@ def canonicalize(data: dict) -> str:
67
66
  return str(data)
68
67
 
69
68
 
70
- def hash_sha256(input: Union[str, io.BufferedReader]) -> str:
69
+ def hash_sha256(input: str | io.BufferedReader) -> str:
71
70
  # Return SHA256 hash in hex format
72
71
  hash = sha256()
73
72
  if isinstance(input, io.BufferedReader):
@@ -80,12 +79,12 @@ def hash_sha256(input: Union[str, io.BufferedReader]) -> str:
80
79
 
81
80
  input.seek(0) # restart reading
82
81
  else:
83
- hash.update(input) # type: ignore
82
+ hash.update(input.encode("utf-8"))
84
83
 
85
84
  return hash.hexdigest()
86
85
 
87
86
 
88
- def hash_sha1(input: Union[str, io.BufferedReader]) -> str:
87
+ def hash_sha1(input: str | io.BufferedReader) -> str:
89
88
  # Return SHA1 hash in hex format
90
89
  hash = sha1()
91
90
  if isinstance(input, io.BufferedReader):
@@ -98,12 +97,12 @@ def hash_sha1(input: Union[str, io.BufferedReader]) -> str:
98
97
 
99
98
  input.seek(0) # restart reading
100
99
  else:
101
- hash.update(input) # type: ignore
100
+ hash.update(input.encode("utf-8"))
102
101
 
103
102
  return hash.hexdigest()
104
103
 
105
104
 
106
- def hash_sha512(input: Union[str, io.BufferedReader]) -> str:
105
+ def hash_sha512(input: str | io.BufferedReader) -> str:
107
106
  # Return SHA512 hash in hex format
108
107
  hash = sha512()
109
108
  if isinstance(input, io.BufferedReader):
@@ -116,7 +115,7 @@ def hash_sha512(input: Union[str, io.BufferedReader]) -> str:
116
115
 
117
116
  input.seek(0) # restart reading
118
117
  else:
119
- hash.update(input) # type: ignore
118
+ hash.update(input.encode("utf-8"))
120
119
 
121
120
  return hash.hexdigest()
122
121
 
@@ -126,7 +125,7 @@ def hash_ntlm(data: str) -> str:
126
125
  return new("md4", data.encode("utf-16le")).hexdigest()
127
126
 
128
127
 
129
- def hash_md5(input: Union[str, io.BufferedReader]) -> str:
128
+ def hash_md5(input: str | io.BufferedReader) -> str:
130
129
  # Return MD5 hash in hex format
131
130
  hash = md5()
132
131
  if isinstance(input, io.BufferedReader):
@@ -140,7 +139,7 @@ def hash_md5(input: Union[str, io.BufferedReader]) -> str:
140
139
 
141
140
  input.seek(0) # restart reading
142
141
  else:
143
- hash.update(input) # type: ignore
142
+ hash.update(input.encode("utf-8"))
144
143
 
145
144
  return hash.hexdigest()
146
145
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pangea-sdk"
3
- version = "5.2.0beta1"
3
+ version = "5.2.0beta2"
4
4
  description = "Pangea API SDK"
5
5
  authors = ["Glenn Gallien <glenn.gallien@pangea.cloud>"]
6
6
  license = "MIT"
@@ -19,7 +19,7 @@ packages = [
19
19
  [tool.poetry.dependencies]
20
20
  python = "^3.9.0"
21
21
  requests = "^2.31.0"
22
- cryptography = "^43.0.1"
22
+ cryptography = "^43.0.3"
23
23
  python-dateutil = "^2.9.0"
24
24
  pydantic = "^2.9.2"
25
25
  deprecated = "^1.2.14"
@@ -29,10 +29,10 @@ requests-toolbelt = "^1.0.0"
29
29
  typing-extensions = "^4.12.2"
30
30
 
31
31
  [tool.poetry.group.dev.dependencies]
32
- black = "^24.8.0"
32
+ black = "^24.10.0"
33
33
  docstring-parser = "^0.15"
34
34
  isort = "^5.13.2"
35
- mypy = "1.11.2"
35
+ mypy = "1.13.0"
36
36
  types-Deprecated = "^1.2.9.3"
37
37
  types-python-dateutil = "^2.8.19.14"
38
38
  types-requests = "^2.31.0.10"
@@ -1,65 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from pangea.asyncio.services.base import ServiceBaseAsync
4
- from pangea.response import PangeaResponse, PangeaResponseResult
5
- from pangea.services.data_guard import TextGuardResult
6
-
7
-
8
- class DataGuard(ServiceBaseAsync):
9
- """Data Guard service client.
10
-
11
- Provides methods to interact with Pangea's Data Guard service.
12
- """
13
-
14
- service_name = "data-guard"
15
-
16
- async def guard_text(
17
- self,
18
- text: str,
19
- *,
20
- recipe: str = "pangea_prompt_guard",
21
- debug: bool = False,
22
- ) -> PangeaResponse[TextGuardResult]:
23
- """
24
- Text guard (Beta)
25
-
26
- Guard text.
27
-
28
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
29
-
30
- OperationId: data_guard_post_v1_text_guard
31
-
32
- Args:
33
- text: Text.
34
- recipe: Recipe.
35
- debug: Debug.
36
-
37
- Examples:
38
- response = await data_guard.guard_text("text")
39
- """
40
-
41
- return await self.request.post(
42
- "v1/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
43
- )
44
-
45
- async def guard_file(
46
- self,
47
- file_url: str,
48
- ) -> PangeaResponse[PangeaResponseResult]:
49
- """
50
- File guard (Beta)
51
-
52
- Guard a file URL.
53
-
54
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
55
-
56
- OperationId: data_guard_post_v1_file_guard
57
-
58
- Args:
59
- file_url: File URL.
60
-
61
- Examples:
62
- response = await data_guard.guard_file("https://example.org/file.txt")
63
- """
64
-
65
- return await self.request.post("v1/file/guard", PangeaResponseResult, data={"file_url": file_url})
@@ -1,39 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING
4
-
5
- from pangea.asyncio.services.base import ServiceBaseAsync
6
- from pangea.services.prompt_guard import GuardResult, Message
7
-
8
- if TYPE_CHECKING:
9
- from collections.abc import Iterable
10
-
11
- from pangea.response import PangeaResponse
12
-
13
-
14
- class PromptGuard(ServiceBaseAsync):
15
- """Prompt Guard service client.
16
-
17
- Provides methods to interact with Pangea's Prompt Guard service.
18
- """
19
-
20
- service_name = "prompt-guard"
21
-
22
- async def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
23
- """
24
- Guard (Beta)
25
-
26
- Guard messages.
27
-
28
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
29
-
30
- OperationId: prompt_guard_post_v1_guard
31
-
32
- Args:
33
- messages: Messages..
34
-
35
- Examples:
36
- response = await prompt_guard.guard([Message(role="user", content="hello world")])
37
- """
38
-
39
- return await self.request.post("v1/guard", GuardResult, data={"messages": messages})
@@ -1,48 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Optional
4
-
5
- from pangea.response import APIRequestModel, PangeaResponse, PangeaResponseResult
6
- from pangea.services.base import ServiceBase
7
-
8
- if TYPE_CHECKING:
9
- from collections.abc import Iterable
10
-
11
-
12
- class Message(APIRequestModel):
13
- role: str
14
- content: str
15
-
16
-
17
- class GuardResult(PangeaResponseResult):
18
- prompt_injection_detected: bool
19
- prompt_injection_type: Optional[str] = None
20
- prompt_injection_detector: Optional[str] = None
21
-
22
-
23
- class PromptGuard(ServiceBase):
24
- """Prompt Guard service client.
25
-
26
- Provides methods to interact with Pangea's Prompt Guard service.
27
- """
28
-
29
- service_name = "prompt-guard"
30
-
31
- def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
32
- """
33
- Guard (Beta)
34
-
35
- Guard messages.
36
-
37
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
38
-
39
- OperationId: prompt_guard_post_v1_guard
40
-
41
- Args:
42
- messages: Messages.
43
-
44
- Examples:
45
- response = prompt_guard.guard([Message(role="user", content="hello world")])
46
- """
47
-
48
- return self.request.post("v1/guard", GuardResult, data={"messages": messages})