rapha-ai 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.
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.4
2
+ Name: rapha-ai
3
+ Version: 0.1.0
4
+ Summary: The official SDK for Rapha Protocol: Compute-to-Data AI Training
5
+ Home-page: https://rapha.ltd
6
+ Author: Rapha Protocol Team
7
+ Author-email: hello@rapha.ltd
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Classifier: Topic :: Security :: Cryptography
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests>=2.25.0
16
+ Requires-Dist: torch>=1.9.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Rapha AI SDK
28
+
29
+ The official Python SDK for the **Rapha Protocol**—a decentralized "Compute-to-Data" network for AI model training over sensitive health data.
30
+
31
+ Instead of bringing data to the model, Rapha brings your model to the data using TEEs (Trusted Execution Environments) and ZK-TLS cryptography.
32
+
33
+ ## Installation
34
+
35
+ Install the package directly from PyPI:
36
+
37
+ ```bash
38
+ pip install rapha-ai
39
+ ```
40
+
41
+ ## Quickstart
42
+
43
+ Initialize the `RaphaClient`, fund the escrow contract (for compute nodes), and execute remote training over HIPAA-compliant medical datasets securely.
44
+
45
+ ```python
46
+ import torch
47
+ import torch.nn as nn
48
+ from rapha import RaphaClient
49
+
50
+ # 1. Define your PyTorch Model Architecture
51
+ class MedicalNet(nn.Module):
52
+ def __init__(self):
53
+ super().__init__()
54
+ self.fc1 = nn.Linear(3, 10)
55
+ self.fc2 = nn.Linear(10, 1)
56
+
57
+ def forward(self, x):
58
+ x = torch.relu(self.fc1(x))
59
+ return self.fc2(x)
60
+
61
+ model = MedicalNet()
62
+
63
+ # 2. Initialize the Rapha Client
64
+ # node_url defaults to production: https://api.rapha.ltd
65
+ # For local testing, pass: node_url="http://127.0.0.1:8000"
66
+ client = RaphaClient(escrow_contract_address="0xYourContractAddress")
67
+
68
+ # 3. Fund your job with USDC
69
+ job_id = client.fund_job(amount=100.0)
70
+ print(f"Funded Job: {job_id}")
71
+
72
+ # 4. Trigger remote training
73
+ # The model weights are packaged, sent to the node, computed against the dataset,
74
+ # and returned with a valid Zero-Knowledge proof.
75
+ zk_proof = client.train(model, target_dataset_id="hospital_dataset_1")
76
+
77
+ # 5. Model state is updated in-place automatically
78
+ print("Training Complete. Model weights updated securely.")
79
+
80
+ # 6. Push proof to on-chain settlement
81
+ client.settle(zk_proof)
82
+ print("Node provider paid. Transaction complete.")
83
+ ```
84
+
85
+ ## Learn More
86
+
87
+ Visit [rapha.ltd](https://rapha.ltd) for protocol documentation and enterprise features.
@@ -0,0 +1,61 @@
1
+ # Rapha AI SDK
2
+
3
+ The official Python SDK for the **Rapha Protocol**—a decentralized "Compute-to-Data" network for AI model training over sensitive health data.
4
+
5
+ Instead of bringing data to the model, Rapha brings your model to the data using TEEs (Trusted Execution Environments) and ZK-TLS cryptography.
6
+
7
+ ## Installation
8
+
9
+ Install the package directly from PyPI:
10
+
11
+ ```bash
12
+ pip install rapha-ai
13
+ ```
14
+
15
+ ## Quickstart
16
+
17
+ Initialize the `RaphaClient`, fund the escrow contract (for compute nodes), and execute remote training over HIPAA-compliant medical datasets securely.
18
+
19
+ ```python
20
+ import torch
21
+ import torch.nn as nn
22
+ from rapha import RaphaClient
23
+
24
+ # 1. Define your PyTorch Model Architecture
25
+ class MedicalNet(nn.Module):
26
+ def __init__(self):
27
+ super().__init__()
28
+ self.fc1 = nn.Linear(3, 10)
29
+ self.fc2 = nn.Linear(10, 1)
30
+
31
+ def forward(self, x):
32
+ x = torch.relu(self.fc1(x))
33
+ return self.fc2(x)
34
+
35
+ model = MedicalNet()
36
+
37
+ # 2. Initialize the Rapha Client
38
+ # node_url defaults to production: https://api.rapha.ltd
39
+ # For local testing, pass: node_url="http://127.0.0.1:8000"
40
+ client = RaphaClient(escrow_contract_address="0xYourContractAddress")
41
+
42
+ # 3. Fund your job with USDC
43
+ job_id = client.fund_job(amount=100.0)
44
+ print(f"Funded Job: {job_id}")
45
+
46
+ # 4. Trigger remote training
47
+ # The model weights are packaged, sent to the node, computed against the dataset,
48
+ # and returned with a valid Zero-Knowledge proof.
49
+ zk_proof = client.train(model, target_dataset_id="hospital_dataset_1")
50
+
51
+ # 5. Model state is updated in-place automatically
52
+ print("Training Complete. Model weights updated securely.")
53
+
54
+ # 6. Push proof to on-chain settlement
55
+ client.settle(zk_proof)
56
+ print("Node provider paid. Transaction complete.")
57
+ ```
58
+
59
+ ## Learn More
60
+
61
+ Visit [rapha.ltd](https://rapha.ltd) for protocol documentation and enterprise features.
@@ -0,0 +1 @@
1
+ from .client import RaphaClient
@@ -0,0 +1,43 @@
1
+ import requests
2
+ import torch
3
+ from .packaging import create_payload, deserialize_model_state
4
+
5
+ class RaphaClient:
6
+ def __init__(self, escrow_contract_address: str, node_url: str = "https://api.rapha.ltd"):
7
+ self.escrow_contract_address = escrow_contract_address
8
+ self.node_url = node_url
9
+ self.job_id = None
10
+
11
+ def fund_job(self, amount: float):
12
+ """Mocks locking USDC to fund a job on the smart contract."""
13
+ print(f"[SDK] Funding job with {amount} USDC at {self.escrow_contract_address}")
14
+ # In a real scenario, this would interact with a Web3 provider to lock funds
15
+ self.job_id = "job_mock_" + str(hash(amount))
16
+ return self.job_id
17
+
18
+ def train(self, model: torch.nn.Module, target_dataset_id: str):
19
+ """Packages the model and sends it to the Enterprise Node for training."""
20
+ if not self.job_id:
21
+ raise ValueError("Must fund_job() before training.")
22
+
23
+ print(f"[SDK] Packaging model for dataset {target_dataset_id}...")
24
+ payload = create_payload(model, target_dataset_id)
25
+ payload["job_id"] = self.job_id
26
+
27
+ print(f"[SDK] Dispatching payload to {self.node_url}/train...")
28
+ response = requests.post(f"{self.node_url}/train", json=payload)
29
+
30
+ if response.status_code != 200:
31
+ raise RuntimeError(f"Node returned error: {response.text}")
32
+
33
+ result = response.json()
34
+ print(f"[SDK] Received updated weights and ZK proof from node.")
35
+
36
+ # Update our local model with the trained weights
37
+ deserialize_model_state(model, result["updated_weights"])
38
+ return result.get("zk_proof", "mock_proof_true")
39
+
40
+ def settle(self, zk_proof: str):
41
+ """Mocks triggering the smart contract settlement with the ZK proof."""
42
+ print(f"[SDK] Submitting proof {zk_proof} to escrow contract for settlement of {self.job_id}")
43
+ return True
@@ -0,0 +1,24 @@
1
+ import base64
2
+ import io
3
+ import torch
4
+
5
+ def serialize_model_state(model: torch.nn.Module) -> str:
6
+ """Serializes a PyTorch model state_dict to a base64 string."""
7
+ buffer = io.BytesIO()
8
+ # Use standard load/save instead of weights_only to allow full structure payload representation in mock
9
+ torch.save(model.state_dict(), buffer)
10
+ return base64.b64encode(buffer.getvalue()).decode('utf-8')
11
+
12
+ def deserialize_model_state(model: torch.nn.Module, b64_state: str):
13
+ """Deserializes a base64 string back into a PyTorch model state_dict."""
14
+ buffer = io.BytesIO(base64.b64decode(b64_state))
15
+ # Safe loading is good practice, but for mock standard is fine
16
+ state_dict = torch.load(buffer, map_location='cpu', weights_only=False)
17
+ model.load_state_dict(state_dict)
18
+
19
+ def create_payload(model: torch.nn.Module, dataset_id: str) -> dict:
20
+ """Creates a secure JSON payload containing model weights."""
21
+ return {
22
+ "dataset_id": dataset_id,
23
+ "weights": serialize_model_state(model)
24
+ }
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.4
2
+ Name: rapha-ai
3
+ Version: 0.1.0
4
+ Summary: The official SDK for Rapha Protocol: Compute-to-Data AI Training
5
+ Home-page: https://rapha.ltd
6
+ Author: Rapha Protocol Team
7
+ Author-email: hello@rapha.ltd
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
12
+ Classifier: Topic :: Security :: Cryptography
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests>=2.25.0
16
+ Requires-Dist: torch>=1.9.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # Rapha AI SDK
28
+
29
+ The official Python SDK for the **Rapha Protocol**—a decentralized "Compute-to-Data" network for AI model training over sensitive health data.
30
+
31
+ Instead of bringing data to the model, Rapha brings your model to the data using TEEs (Trusted Execution Environments) and ZK-TLS cryptography.
32
+
33
+ ## Installation
34
+
35
+ Install the package directly from PyPI:
36
+
37
+ ```bash
38
+ pip install rapha-ai
39
+ ```
40
+
41
+ ## Quickstart
42
+
43
+ Initialize the `RaphaClient`, fund the escrow contract (for compute nodes), and execute remote training over HIPAA-compliant medical datasets securely.
44
+
45
+ ```python
46
+ import torch
47
+ import torch.nn as nn
48
+ from rapha import RaphaClient
49
+
50
+ # 1. Define your PyTorch Model Architecture
51
+ class MedicalNet(nn.Module):
52
+ def __init__(self):
53
+ super().__init__()
54
+ self.fc1 = nn.Linear(3, 10)
55
+ self.fc2 = nn.Linear(10, 1)
56
+
57
+ def forward(self, x):
58
+ x = torch.relu(self.fc1(x))
59
+ return self.fc2(x)
60
+
61
+ model = MedicalNet()
62
+
63
+ # 2. Initialize the Rapha Client
64
+ # node_url defaults to production: https://api.rapha.ltd
65
+ # For local testing, pass: node_url="http://127.0.0.1:8000"
66
+ client = RaphaClient(escrow_contract_address="0xYourContractAddress")
67
+
68
+ # 3. Fund your job with USDC
69
+ job_id = client.fund_job(amount=100.0)
70
+ print(f"Funded Job: {job_id}")
71
+
72
+ # 4. Trigger remote training
73
+ # The model weights are packaged, sent to the node, computed against the dataset,
74
+ # and returned with a valid Zero-Knowledge proof.
75
+ zk_proof = client.train(model, target_dataset_id="hospital_dataset_1")
76
+
77
+ # 5. Model state is updated in-place automatically
78
+ print("Training Complete. Model weights updated securely.")
79
+
80
+ # 6. Push proof to on-chain settlement
81
+ client.settle(zk_proof)
82
+ print("Node provider paid. Transaction complete.")
83
+ ```
84
+
85
+ ## Learn More
86
+
87
+ Visit [rapha.ltd](https://rapha.ltd) for protocol documentation and enterprise features.
@@ -0,0 +1,10 @@
1
+ README.md
2
+ setup.py
3
+ rapha/__init__.py
4
+ rapha/client.py
5
+ rapha/packaging.py
6
+ rapha_ai.egg-info/PKG-INFO
7
+ rapha_ai.egg-info/SOURCES.txt
8
+ rapha_ai.egg-info/dependency_links.txt
9
+ rapha_ai.egg-info/requires.txt
10
+ rapha_ai.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ requests>=2.25.0
2
+ torch>=1.9.0
@@ -0,0 +1 @@
1
+ rapha
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="rapha-ai",
8
+ version="0.1.0",
9
+ author="Rapha Protocol Team",
10
+ author_email="hello@rapha.ltd",
11
+ description="The official SDK for Rapha Protocol: Compute-to-Data AI Training",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://rapha.ltd",
15
+ packages=find_packages(),
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
21
+ "Topic :: Security :: Cryptography"
22
+ ],
23
+ python_requires='>=3.8',
24
+ install_requires=[
25
+ "requests>=2.25.0",
26
+ "torch>=1.9.0"
27
+ ],
28
+ )