swiftapi-python 1.0.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.
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: swiftapi-python
3
+ Version: 1.0.0
4
+ Summary: SwiftAPI Python SDK - AI Action Verification Gateway
5
+ Author-email: Rayan Pal <rayan@swiftapi.ai>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://swiftapi.ai
8
+ Project-URL: Documentation, https://docs.swiftapi.ai
9
+ Project-URL: Repository, https://github.com/swiftapi/swiftapi-python
10
+ Project-URL: Issues, https://github.com/swiftapi/swiftapi-python/issues
11
+ Keywords: swiftapi,ai,verification,attestation,security,governance,enforcement
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Security
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: requests>=2.31.0
25
+ Requires-Dist: pynacl>=1.5.0
26
+ Requires-Dist: colorama>=0.4.6
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+ Requires-Dist: black>=23.0.0; extra == "dev"
31
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
32
+ Requires-Dist: types-requests>=2.31.0; extra == "dev"
33
+
34
+ # SwiftAPI Python SDK
35
+
36
+ **No AI action executes without verification.**
37
+
38
+ SwiftAPI is the ignition key for AI agents. This SDK provides Python bindings for the SwiftAPI execution governance protocol.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install swiftapi
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```python
49
+ from swiftapi import SwiftAPI, Enforcement
50
+
51
+ # Initialize client with your API key
52
+ api = SwiftAPI(key="swiftapi_live_...")
53
+
54
+ # Create an enforcement point
55
+ guard = Enforcement(api)
56
+
57
+ # THE LINE THAT SAVES THE COMPANY
58
+ guard.run(
59
+ lambda: os.system("rm -rf /tmp/data"),
60
+ action="file_delete",
61
+ intent="Cleanup temporary files"
62
+ )
63
+ ```
64
+
65
+ If the action is denied by policy, a `PolicyViolation` exception is raised and **nothing executes**.
66
+
67
+ ## Features
68
+
69
+ - **Cryptographic Enforcement**: Ed25519 signed attestations prove authorization
70
+ - **Offline Verification**: Verify attestation signatures without network calls
71
+ - **Policy Enforcement**: Actions blocked if they violate configured policies
72
+ - **Rate Limiting**: Built-in handling for API rate limits
73
+ - **Beautiful Output**: Color-coded terminal output for approvals/denials
74
+
75
+ ## Usage Patterns
76
+
77
+ ### 1. Direct Execution
78
+
79
+ ```python
80
+ from swiftapi import SwiftAPI, Enforcement
81
+
82
+ api = SwiftAPI(key="swiftapi_live_...")
83
+ guard = Enforcement(api)
84
+
85
+ # Execute with verification
86
+ result = guard.run(
87
+ lambda: dangerous_operation(),
88
+ action="database_write",
89
+ intent="Update user preferences"
90
+ )
91
+ ```
92
+
93
+ ### 2. Decorator
94
+
95
+ ```python
96
+ @guard.protect(action="api_call", intent="Send notification")
97
+ def send_notification(user_id: str, message: str):
98
+ # This only runs if SwiftAPI approves
99
+ notification_service.send(user_id, message)
100
+
101
+ # Usage - automatically enforced
102
+ send_notification("user123", "Hello!")
103
+ ```
104
+
105
+ ### 3. Context Manager
106
+
107
+ ```python
108
+ with guard.guard(action="file_write", intent="Save configuration"):
109
+ # This block only executes if approved
110
+ with open("/etc/myapp/config.json", "w") as f:
111
+ json.dump(config, f)
112
+ ```
113
+
114
+ ### 4. One-off Enforcement
115
+
116
+ ```python
117
+ from swiftapi import SwiftAPI, enforce
118
+
119
+ api = SwiftAPI(key="swiftapi_live_...")
120
+ enforce(api, lambda: risky_operation(), action="admin", intent="Reset system")
121
+ ```
122
+
123
+ ## Paranoid Mode
124
+
125
+ For maximum security, enable paranoid mode to check revocation status online:
126
+
127
+ ```python
128
+ guard = Enforcement(api, paranoid=True)
129
+ ```
130
+
131
+ This adds an extra network call but ensures revoked attestations are caught in real-time.
132
+
133
+ ## Offline Verification
134
+
135
+ You can verify attestation signatures without any network calls:
136
+
137
+ ```python
138
+ from swiftapi import verify_signature, is_valid
139
+
140
+ # Verify signature (raises exception if invalid)
141
+ verify_signature(attestation)
142
+
143
+ # Check validity without exceptions
144
+ if is_valid(attestation):
145
+ print("Attestation is valid")
146
+ ```
147
+
148
+ ## Error Handling
149
+
150
+ ```python
151
+ from swiftapi import (
152
+ SwiftAPI,
153
+ Enforcement,
154
+ PolicyViolation,
155
+ SignatureVerificationError,
156
+ AttestationRevokedError,
157
+ )
158
+
159
+ api = SwiftAPI(key="swiftapi_live_...")
160
+ guard = Enforcement(api)
161
+
162
+ try:
163
+ guard.run(lambda: delete_everything(), action="nuke", intent="YOLO")
164
+ except PolicyViolation as e:
165
+ print(f"Action denied: {e.denial_reason}")
166
+ except SignatureVerificationError:
167
+ print("CRITICAL: Attestation signature is invalid!")
168
+ except AttestationRevokedError as e:
169
+ print(f"Attestation {e.jti} was revoked")
170
+ ```
171
+
172
+ ## API Client
173
+
174
+ The SDK also provides direct API access:
175
+
176
+ ```python
177
+ from swiftapi import SwiftAPI
178
+
179
+ api = SwiftAPI(key="swiftapi_live_...")
180
+
181
+ # Get API info
182
+ info = api.get_info()
183
+
184
+ # Verify an action
185
+ result = api.verify(
186
+ action_type="file_write",
187
+ intent="Save user data",
188
+ params={"path": "/data/users.json"}
189
+ )
190
+
191
+ # Check attestation revocation
192
+ is_revoked = api.check_revocation(jti="attestation-id")
193
+
194
+ # List authority keys (admin only)
195
+ keys = api.list_keys()
196
+
197
+ # Create new key (admin only)
198
+ new_key = api.create_key(name="agent-1", scopes=["verify"])
199
+ ```
200
+
201
+ ## Configuration
202
+
203
+ ```python
204
+ api = SwiftAPI(
205
+ key="swiftapi_live_...",
206
+ base_url="https://swiftapi.ai", # Default
207
+ timeout=30, # Request timeout in seconds
208
+ )
209
+
210
+ guard = Enforcement(
211
+ client=api,
212
+ paranoid=False, # Enable online revocation checks
213
+ verbose=True, # Print status messages
214
+ )
215
+ ```
216
+
217
+ ## The Golden Loop
218
+
219
+ Every protected action goes through this verification chain:
220
+
221
+ ```
222
+ ┌─────────────────────────────────────────────────────────┐
223
+ │ THE GOLDEN LOOP │
224
+ ├─────────────────────────────────────────────────────────┤
225
+ │ │
226
+ │ 1. API CALL │
227
+ │ client.verify() ──────────────────────────────┐ │
228
+ │ │ │
229
+ │ 2. CRYPTO CHECK (Offline Truth) │ │
230
+ │ verifier.verify_signature() ◄─────────────────┤ │
231
+ │ │ │
232
+ │ 3. ONLINE CHECK (Optional/Paranoid) │ │
233
+ │ client.check_revocation() ◄───────────────────┤ │
234
+ │ │ │
235
+ │ 4. EXECUTE │ │
236
+ │ func() ◄──────────────────────────────────────┘ │
237
+ │ │
238
+ │ If ANY step fails → PolicyViolation raised │
239
+ │ The action NEVER executes without full verification │
240
+ │ │
241
+ └─────────────────────────────────────────────────────────┘
242
+ ```
243
+
244
+ ## License
245
+
246
+ MIT License - See LICENSE file for details.
247
+
248
+ ## Links
249
+
250
+ - **API**: https://swiftapi.ai
251
+ - **Documentation**: https://docs.swiftapi.ai
252
+ - **GitHub**: https://github.com/swiftapi/swiftapi-python
253
+
254
+ ---
255
+
256
+ *Built by Rayan Pal. No AI action executes without verification.*
@@ -0,0 +1,223 @@
1
+ # SwiftAPI Python SDK
2
+
3
+ **No AI action executes without verification.**
4
+
5
+ SwiftAPI is the ignition key for AI agents. This SDK provides Python bindings for the SwiftAPI execution governance protocol.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install swiftapi
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ from swiftapi import SwiftAPI, Enforcement
17
+
18
+ # Initialize client with your API key
19
+ api = SwiftAPI(key="swiftapi_live_...")
20
+
21
+ # Create an enforcement point
22
+ guard = Enforcement(api)
23
+
24
+ # THE LINE THAT SAVES THE COMPANY
25
+ guard.run(
26
+ lambda: os.system("rm -rf /tmp/data"),
27
+ action="file_delete",
28
+ intent="Cleanup temporary files"
29
+ )
30
+ ```
31
+
32
+ If the action is denied by policy, a `PolicyViolation` exception is raised and **nothing executes**.
33
+
34
+ ## Features
35
+
36
+ - **Cryptographic Enforcement**: Ed25519 signed attestations prove authorization
37
+ - **Offline Verification**: Verify attestation signatures without network calls
38
+ - **Policy Enforcement**: Actions blocked if they violate configured policies
39
+ - **Rate Limiting**: Built-in handling for API rate limits
40
+ - **Beautiful Output**: Color-coded terminal output for approvals/denials
41
+
42
+ ## Usage Patterns
43
+
44
+ ### 1. Direct Execution
45
+
46
+ ```python
47
+ from swiftapi import SwiftAPI, Enforcement
48
+
49
+ api = SwiftAPI(key="swiftapi_live_...")
50
+ guard = Enforcement(api)
51
+
52
+ # Execute with verification
53
+ result = guard.run(
54
+ lambda: dangerous_operation(),
55
+ action="database_write",
56
+ intent="Update user preferences"
57
+ )
58
+ ```
59
+
60
+ ### 2. Decorator
61
+
62
+ ```python
63
+ @guard.protect(action="api_call", intent="Send notification")
64
+ def send_notification(user_id: str, message: str):
65
+ # This only runs if SwiftAPI approves
66
+ notification_service.send(user_id, message)
67
+
68
+ # Usage - automatically enforced
69
+ send_notification("user123", "Hello!")
70
+ ```
71
+
72
+ ### 3. Context Manager
73
+
74
+ ```python
75
+ with guard.guard(action="file_write", intent="Save configuration"):
76
+ # This block only executes if approved
77
+ with open("/etc/myapp/config.json", "w") as f:
78
+ json.dump(config, f)
79
+ ```
80
+
81
+ ### 4. One-off Enforcement
82
+
83
+ ```python
84
+ from swiftapi import SwiftAPI, enforce
85
+
86
+ api = SwiftAPI(key="swiftapi_live_...")
87
+ enforce(api, lambda: risky_operation(), action="admin", intent="Reset system")
88
+ ```
89
+
90
+ ## Paranoid Mode
91
+
92
+ For maximum security, enable paranoid mode to check revocation status online:
93
+
94
+ ```python
95
+ guard = Enforcement(api, paranoid=True)
96
+ ```
97
+
98
+ This adds an extra network call but ensures revoked attestations are caught in real-time.
99
+
100
+ ## Offline Verification
101
+
102
+ You can verify attestation signatures without any network calls:
103
+
104
+ ```python
105
+ from swiftapi import verify_signature, is_valid
106
+
107
+ # Verify signature (raises exception if invalid)
108
+ verify_signature(attestation)
109
+
110
+ # Check validity without exceptions
111
+ if is_valid(attestation):
112
+ print("Attestation is valid")
113
+ ```
114
+
115
+ ## Error Handling
116
+
117
+ ```python
118
+ from swiftapi import (
119
+ SwiftAPI,
120
+ Enforcement,
121
+ PolicyViolation,
122
+ SignatureVerificationError,
123
+ AttestationRevokedError,
124
+ )
125
+
126
+ api = SwiftAPI(key="swiftapi_live_...")
127
+ guard = Enforcement(api)
128
+
129
+ try:
130
+ guard.run(lambda: delete_everything(), action="nuke", intent="YOLO")
131
+ except PolicyViolation as e:
132
+ print(f"Action denied: {e.denial_reason}")
133
+ except SignatureVerificationError:
134
+ print("CRITICAL: Attestation signature is invalid!")
135
+ except AttestationRevokedError as e:
136
+ print(f"Attestation {e.jti} was revoked")
137
+ ```
138
+
139
+ ## API Client
140
+
141
+ The SDK also provides direct API access:
142
+
143
+ ```python
144
+ from swiftapi import SwiftAPI
145
+
146
+ api = SwiftAPI(key="swiftapi_live_...")
147
+
148
+ # Get API info
149
+ info = api.get_info()
150
+
151
+ # Verify an action
152
+ result = api.verify(
153
+ action_type="file_write",
154
+ intent="Save user data",
155
+ params={"path": "/data/users.json"}
156
+ )
157
+
158
+ # Check attestation revocation
159
+ is_revoked = api.check_revocation(jti="attestation-id")
160
+
161
+ # List authority keys (admin only)
162
+ keys = api.list_keys()
163
+
164
+ # Create new key (admin only)
165
+ new_key = api.create_key(name="agent-1", scopes=["verify"])
166
+ ```
167
+
168
+ ## Configuration
169
+
170
+ ```python
171
+ api = SwiftAPI(
172
+ key="swiftapi_live_...",
173
+ base_url="https://swiftapi.ai", # Default
174
+ timeout=30, # Request timeout in seconds
175
+ )
176
+
177
+ guard = Enforcement(
178
+ client=api,
179
+ paranoid=False, # Enable online revocation checks
180
+ verbose=True, # Print status messages
181
+ )
182
+ ```
183
+
184
+ ## The Golden Loop
185
+
186
+ Every protected action goes through this verification chain:
187
+
188
+ ```
189
+ ┌─────────────────────────────────────────────────────────┐
190
+ │ THE GOLDEN LOOP │
191
+ ├─────────────────────────────────────────────────────────┤
192
+ │ │
193
+ │ 1. API CALL │
194
+ │ client.verify() ──────────────────────────────┐ │
195
+ │ │ │
196
+ │ 2. CRYPTO CHECK (Offline Truth) │ │
197
+ │ verifier.verify_signature() ◄─────────────────┤ │
198
+ │ │ │
199
+ │ 3. ONLINE CHECK (Optional/Paranoid) │ │
200
+ │ client.check_revocation() ◄───────────────────┤ │
201
+ │ │ │
202
+ │ 4. EXECUTE │ │
203
+ │ func() ◄──────────────────────────────────────┘ │
204
+ │ │
205
+ │ If ANY step fails → PolicyViolation raised │
206
+ │ The action NEVER executes without full verification │
207
+ │ │
208
+ └─────────────────────────────────────────────────────────┘
209
+ ```
210
+
211
+ ## License
212
+
213
+ MIT License - See LICENSE file for details.
214
+
215
+ ## Links
216
+
217
+ - **API**: https://swiftapi.ai
218
+ - **Documentation**: https://docs.swiftapi.ai
219
+ - **GitHub**: https://github.com/swiftapi/swiftapi-python
220
+
221
+ ---
222
+
223
+ *Built by Rayan Pal. No AI action executes without verification.*
@@ -0,0 +1,73 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "swiftapi-python"
7
+ version = "1.0.0"
8
+ description = "SwiftAPI Python SDK - AI Action Verification Gateway"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ authors = [
12
+ {name = "Rayan Pal", email = "rayan@swiftapi.ai"}
13
+ ]
14
+ keywords = [
15
+ "swiftapi",
16
+ "ai",
17
+ "verification",
18
+ "attestation",
19
+ "security",
20
+ "governance",
21
+ "enforcement",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 4 - Beta",
25
+ "Intended Audience :: Developers",
26
+ "Operating System :: OS Independent",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Topic :: Security",
33
+ "Topic :: Software Development :: Libraries :: Python Modules",
34
+ ]
35
+ requires-python = ">=3.9"
36
+ dependencies = [
37
+ "requests>=2.31.0",
38
+ "pynacl>=1.5.0",
39
+ "colorama>=0.4.6",
40
+ ]
41
+
42
+ [project.optional-dependencies]
43
+ dev = [
44
+ "pytest>=7.0.0",
45
+ "pytest-cov>=4.0.0",
46
+ "black>=23.0.0",
47
+ "mypy>=1.0.0",
48
+ "types-requests>=2.31.0",
49
+ ]
50
+
51
+ [project.urls]
52
+ Homepage = "https://swiftapi.ai"
53
+ Documentation = "https://docs.swiftapi.ai"
54
+ Repository = "https://github.com/swiftapi/swiftapi-python"
55
+ Issues = "https://github.com/swiftapi/swiftapi-python/issues"
56
+
57
+ [tool.setuptools.packages.find]
58
+ where = ["."]
59
+ include = ["swiftapi*"]
60
+
61
+ [tool.black]
62
+ line-length = 100
63
+ target-version = ["py39", "py310", "py311", "py312"]
64
+
65
+ [tool.mypy]
66
+ python_version = "3.9"
67
+ warn_return_any = true
68
+ warn_unused_configs = true
69
+ ignore_missing_imports = true
70
+
71
+ [tool.pytest.ini_options]
72
+ testpaths = ["tests"]
73
+ python_files = ["test_*.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,91 @@
1
+ """
2
+ SwiftAPI Python SDK
3
+
4
+ No AI action executes without verification.
5
+
6
+ Usage:
7
+ from swiftapi import SwiftAPI, Enforcement
8
+
9
+ # Initialize client
10
+ api = SwiftAPI(key="swiftapi_live_...")
11
+
12
+ # Create enforcement point
13
+ guard = Enforcement(api)
14
+
15
+ # Protect dangerous operations
16
+ guard.run(
17
+ lambda: os.system("rm -rf /tmp/data"),
18
+ action="file_delete",
19
+ intent="Cleanup temporary data"
20
+ )
21
+
22
+ # Or use decorator
23
+ @guard.protect(action="api_call", intent="Send email")
24
+ def send_email(to, subject, body):
25
+ ...
26
+
27
+ # Or use context manager
28
+ with guard.guard(action="database_write", intent="Update user"):
29
+ db.update(user_id, data)
30
+ """
31
+
32
+ __version__ = "1.0.0"
33
+ __author__ = "Rayan Pal"
34
+
35
+ # Core exports
36
+ from .client import SwiftAPI
37
+ from .enforcement import Enforcement, enforce
38
+ from .verifier import verify_signature, is_valid, get_public_key
39
+
40
+ # Exceptions
41
+ from .exceptions import (
42
+ SwiftAPIError,
43
+ AuthenticationError,
44
+ PolicyViolation,
45
+ SignatureVerificationError,
46
+ AttestationExpiredError,
47
+ AttestationRevokedError,
48
+ RateLimitError,
49
+ NetworkError,
50
+ )
51
+
52
+ # UX utilities
53
+ from .utils import (
54
+ Colors,
55
+ Symbols,
56
+ print_approved,
57
+ print_denied,
58
+ print_verified,
59
+ print_error,
60
+ print_info,
61
+ )
62
+
63
+ __all__ = [
64
+ # Version
65
+ "__version__",
66
+ # Core
67
+ "SwiftAPI",
68
+ "Enforcement",
69
+ "enforce",
70
+ # Verification
71
+ "verify_signature",
72
+ "is_valid",
73
+ "get_public_key",
74
+ # Exceptions
75
+ "SwiftAPIError",
76
+ "AuthenticationError",
77
+ "PolicyViolation",
78
+ "SignatureVerificationError",
79
+ "AttestationExpiredError",
80
+ "AttestationRevokedError",
81
+ "RateLimitError",
82
+ "NetworkError",
83
+ # UX
84
+ "Colors",
85
+ "Symbols",
86
+ "print_approved",
87
+ "print_denied",
88
+ "print_verified",
89
+ "print_error",
90
+ "print_info",
91
+ ]