Official Shield SDK for Python
Project description
Shield Python SDK
Official Python SDK for Shield — tamper-evident session recording for online business transactions.
Installation
pip install shield-python
Quick Start
import shield
client = shield.Client(api_key="sk_live_your_api_key")
# Create a session
session = client.sessions.create(title="123 Main St Closing")
session_id = session["id"]
# Record events
client.events.create(
session_id=session_id,
event_type="shield.party.joined",
actor="agent@example.com",
data={"role": "listing_agent", "name": "Jane Smith"},
)
client.events.create(
session_id=session_id,
event_type="shield.content.uploaded",
actor="agent@example.com",
data={"filename": "purchase_agreement.pdf", "hash": "sha256:abc123..."},
)
client.events.create(
session_id=session_id,
event_type="shield.agreement.signed",
actor="buyer@example.com",
data={"document": "purchase_agreement.pdf"},
)
# Verify session integrity
result = client.verify.session(session_id)
print(result["intact"]) # True
# Export session
pdf_bytes = client.sessions.export(session_id, format="pdf")
with open("audit_trail.pdf", "wb") as f:
f.write(pdf_bytes)
HMAC Authentication
For enhanced security, provide an HMAC secret to sign every request:
client = shield.Client(
api_key="sk_live_your_api_key",
hmac_secret="your_hmac_secret",
)
When an HMAC secret is configured, the SDK computes a signature for each request:
X-Shield-Timestamp— Unix timestamp of the requestX-Shield-Signature— HMAC-SHA256 of{timestamp}.{METHOD}.{path}.{SHA256(body)}
The server validates these headers to ensure requests have not been tampered with or replayed.
Flask Integration
from flask import Flask, request, jsonify
import shield
app = Flask(__name__)
client = shield.Client(api_key="sk_live_your_api_key")
@app.route("/sessions", methods=["POST"])
def create_session():
data = request.get_json()
session = client.sessions.create(title=data["title"])
# Record who created the session
client.events.create(
session_id=session["id"],
event_type="shield.session.created",
actor=data["user_email"],
)
return jsonify(session), 201
@app.route("/sessions/<session_id>/upload", methods=["POST"])
def upload_document(session_id):
file = request.files["file"]
# ... save file logic ...
client.events.create(
session_id=session_id,
event_type="shield.content.uploaded",
actor=request.headers.get("X-User-Email"),
data={"filename": file.filename},
)
return jsonify({"status": "uploaded"}), 200
@app.route("/sessions/<session_id>/sign", methods=["POST"])
def sign_agreement(session_id):
data = request.get_json()
client.events.create(
session_id=session_id,
event_type="shield.agreement.signed",
actor=data["signer_email"],
data={"document": data["document_name"], "ip": request.remote_addr},
)
return jsonify({"status": "signed"}), 200
FastAPI Integration
from fastapi import FastAPI, UploadFile, Header
from pydantic import BaseModel
import shield
app = FastAPI()
client = shield.Client(
api_key="sk_live_your_api_key",
hmac_secret="your_hmac_secret",
)
class CreateSessionRequest(BaseModel):
title: str
user_email: str
class SignRequest(BaseModel):
signer_email: str
document_name: str
@app.post("/sessions")
async def create_session(body: CreateSessionRequest):
session = client.sessions.create(title=body.title)
client.events.create(
session_id=session["id"],
event_type="shield.session.created",
actor=body.user_email,
)
return session
@app.post("/sessions/{session_id}/upload")
async def upload_document(
session_id: str,
file: UploadFile,
x_user_email: str = Header(...),
):
# ... save file logic ...
client.events.create(
session_id=session_id,
event_type="shield.content.uploaded",
actor=x_user_email,
data={"filename": file.filename},
)
return {"status": "uploaded"}
@app.post("/sessions/{session_id}/sign")
async def sign_agreement(session_id: str, body: SignRequest):
client.events.create(
session_id=session_id,
event_type="shield.agreement.signed",
actor=body.signer_email,
data={"document": body.document_name},
)
return {"status": "signed"}
@app.get("/sessions/{session_id}/verify")
async def verify_session(session_id: str):
return client.verify.session(session_id)
Event Types Reference
Shield Standard Event Taxonomy v1.0 — 37 event types across 7 categories:
Party Events
| Event Type | Description |
|---|---|
shield.party.joined |
A party joined the session |
shield.party.left |
A party left the session |
shield.party.identity.verified |
Party identity was verified |
shield.party.identity.failed |
Party identity verification failed |
shield.party.role.assigned |
A role was assigned to a party |
Session Events
| Event Type | Description |
|---|---|
shield.session.created |
Session was created |
shield.session.opened |
Session was opened |
shield.session.closed |
Session was closed |
shield.session.expired |
Session expired |
shield.session.archived |
Session was archived |
Content Events
| Event Type | Description |
|---|---|
shield.content.uploaded |
Content was uploaded |
shield.content.viewed |
Content was viewed |
shield.content.downloaded |
Content was downloaded |
shield.content.deleted |
Content was deleted |
shield.content.hash.verified |
Content hash was verified |
Negotiation Events
| Event Type | Description |
|---|---|
shield.negotiation.terms.proposed |
Terms were proposed |
shield.negotiation.terms.accepted |
Terms were accepted |
shield.negotiation.terms.rejected |
Terms were rejected |
shield.negotiation.terms.modified |
Terms were modified |
shield.negotiation.terms.expired |
Terms expired |
shield.negotiation.message.sent |
Negotiation message sent |
shield.negotiation.message.read |
Negotiation message read |
Agreement Events
| Event Type | Description |
|---|---|
shield.agreement.drafted |
Agreement was drafted |
shield.agreement.reviewed |
Agreement was reviewed |
shield.agreement.approved |
Agreement was approved |
shield.agreement.signed |
Agreement was signed |
shield.agreement.countersigned |
Agreement was countersigned |
shield.agreement.voided |
Agreement was voided |
shield.agreement.reached |
Agreement was reached |
Access Events
| Event Type | Description |
|---|---|
shield.access.granted |
Access was granted |
shield.access.revoked |
Access was revoked |
shield.access.attempted |
Access was attempted |
shield.access.denied |
Access was denied |
Disclosure Events
| Event Type | Description |
|---|---|
shield.disclosure.presented |
Disclosure was presented |
shield.disclosure.acknowledged |
Disclosure was acknowledged |
shield.disclosure.declined |
Disclosure was declined |
Evidence Events
| Event Type | Description |
|---|---|
shield.evidence.exported |
Evidence was exported |
shield.evidence.verified |
Evidence was verified |
shield.evidence.tampered_detected |
Evidence tampering was detected |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shield_python-0.1.1.tar.gz.
File metadata
- Download URL: shield_python-0.1.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb5d1a7e7c5d00ba60646fb0d9e0f22aec44d50477d93fc78169ace36edfb1c
|
|
| MD5 |
e28d4ab9c95f3a5255f497c58130f5c1
|
|
| BLAKE2b-256 |
2816bef240bd9c31f5669bd03382c354a9a422383ff4d8b297bdcceae2d20a05
|
File details
Details for the file shield_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: shield_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5851e4bad0f6143a84ba19edff4b8e88e8c1f152a9e36b92feabd639ee9f01f0
|
|
| MD5 |
43a4b00a0857c3a5c68b374f8e93a500
|
|
| BLAKE2b-256 |
4742a24f5b46c96d18a56157784cb21649cb325982e1ba522630098bf2e04037
|