|
| 1 | +# Client API Reference |
| 2 | + |
| 3 | +## Creating a Client |
| 4 | + |
| 5 | +### `login_do(email, token_path=None)` |
| 6 | + |
| 7 | +Create a Data Owner client. |
| 8 | + |
| 9 | +```python |
| 10 | +# Google Colab |
| 11 | +do_client = login_do(email="owner@example.com") |
| 12 | + |
| 13 | +# Jupyter Lab (local) |
| 14 | +do_client = login_do(email="owner@example.com", token_path="path/to/token.json") |
| 15 | +``` |
| 16 | + |
| 17 | +### `login_ds(email, token_path=None)` |
| 18 | + |
| 19 | +Create a Data Scientist client. |
| 20 | + |
| 21 | +```python |
| 22 | +# Google Colab |
| 23 | +ds_client = login_ds(email="scientist@example.com") |
| 24 | + |
| 25 | +# Jupyter Lab (local) |
| 26 | +ds_client = login_ds(email="scientist@example.com", token_path="path/to/token.json") |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Properties |
| 32 | + |
| 33 | +### `client.email` |
| 34 | + |
| 35 | +The email address of the client. |
| 36 | + |
| 37 | +### `client.peers` |
| 38 | + |
| 39 | +Get the list of peers. Auto-syncs before returning. |
| 40 | + |
| 41 | +- **DO**: Returns approved peers followed by pending peer requests. |
| 42 | +- **DS**: Returns all connected peers. |
| 43 | + |
| 44 | +Returns a `PeerList`. |
| 45 | + |
| 46 | +### `client.jobs` |
| 47 | + |
| 48 | +Get the list of jobs. Auto-syncs before returning. |
| 49 | + |
| 50 | +Returns a `JobsList`. |
| 51 | + |
| 52 | +### `client.datasets` |
| 53 | + |
| 54 | +Get the dataset manager. Auto-syncs before returning. |
| 55 | + |
| 56 | +Returns a `SyftDatasetManager`. Use `.get_all()` or `.get(name, datasite)` to query datasets. |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## Peer Management |
| 61 | + |
| 62 | +### `client.add_peer(peer_email)` |
| 63 | + |
| 64 | +Request a peer connection. |
| 65 | + |
| 66 | +- **DS** calls this to request access to a DO. |
| 67 | +- The DO must approve the request before syncing is enabled. |
| 68 | + |
| 69 | +```python |
| 70 | +ds_client.add_peer("owner@example.com") |
| 71 | +``` |
| 72 | + |
| 73 | +### `client.load_peers()` |
| 74 | + |
| 75 | +Reload the peer list from the transport layer. |
| 76 | + |
| 77 | +### `client.approve_peer_request(email_or_peer)` |
| 78 | + |
| 79 | +Approve a pending peer request. **DO only.** |
| 80 | + |
| 81 | +```python |
| 82 | +do_client.approve_peer_request("scientist@example.com") |
| 83 | +``` |
| 84 | + |
| 85 | +### `client.reject_peer_request(email_or_peer)` |
| 86 | + |
| 87 | +Reject a pending peer request. **DO only.** |
| 88 | + |
| 89 | +```python |
| 90 | +do_client.reject_peer_request("scientist@example.com") |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Syncing |
| 96 | + |
| 97 | +### `client.sync(auto_checkpoint=True, checkpoint_threshold=50)` |
| 98 | + |
| 99 | +Sync local state with Google Drive. |
| 100 | + |
| 101 | +- **DO**: Pulls incoming messages from approved peers and optionally creates a checkpoint. |
| 102 | +- **DS**: Pushes pending changes and pulls results from peers. |
| 103 | + |
| 104 | +```python |
| 105 | +client.sync() |
| 106 | +``` |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Datasets |
| 111 | + |
| 112 | +### `client.create_dataset(name, mock_path, private_path=None, summary=None, users=None, upload_private=False)` |
| 113 | + |
| 114 | +Create and upload a dataset. **DO only.** |
| 115 | + |
| 116 | +- `mock_path`: Path to public mock data (shared with approved peers). |
| 117 | +- `private_path`: Path to private data (never leaves the DO). |
| 118 | +- `users`: List of emails to share with, or `"any"` for all approved peers. |
| 119 | + |
| 120 | +```python |
| 121 | +do_client.create_dataset( |
| 122 | + name="my dataset", |
| 123 | + mock_path="/path/to/mock.csv", |
| 124 | + private_path="/path/to/private.csv", |
| 125 | + summary="Example dataset", |
| 126 | + users=["scientist@example.com"], |
| 127 | +) |
| 128 | +``` |
| 129 | + |
| 130 | +### `client.delete_dataset(name, datasite)` |
| 131 | + |
| 132 | +Delete a dataset. **DO only.** |
| 133 | + |
| 134 | +```python |
| 135 | +do_client.delete_dataset(name="my dataset", datasite="owner@example.com") |
| 136 | +``` |
| 137 | + |
| 138 | +### `client.share_dataset(tag, users)` |
| 139 | + |
| 140 | +Share an existing dataset with additional users. **DO only.** |
| 141 | + |
| 142 | +- `tag`: Dataset name. |
| 143 | +- `users`: List of email addresses or `"any"`. |
| 144 | + |
| 145 | +```python |
| 146 | +do_client.share_dataset("my dataset", users=["new_user@example.com"]) |
| 147 | +``` |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Jobs |
| 152 | + |
| 153 | +### `client.submit_python_job(user, code_path, job_name=None, entrypoint=None)` |
| 154 | + |
| 155 | +Submit a Python job to a Data Owner. **DS only.** |
| 156 | + |
| 157 | +- `user`: DO email to submit the job to. |
| 158 | +- `code_path`: Path to a Python script or folder. |
| 159 | +- `entrypoint`: Entry script (auto-detected if `main.py` exists in folder). |
| 160 | + |
| 161 | +```python |
| 162 | +ds_client.submit_python_job( |
| 163 | + user="owner@example.com", |
| 164 | + code_path="/path/to/script.py", |
| 165 | +) |
| 166 | +``` |
| 167 | + |
| 168 | +### `client.submit_bash_job(user, code_path, job_name=None)` |
| 169 | + |
| 170 | +Submit a bash job to a Data Owner. **DS only.** |
| 171 | + |
| 172 | +```python |
| 173 | +ds_client.submit_bash_job( |
| 174 | + user="owner@example.com", |
| 175 | + code_path="/path/to/script.sh", |
| 176 | +) |
| 177 | +``` |
| 178 | + |
| 179 | +### `client.process_approved_jobs(stream_output=True, timeout=None, force_execution=False)` |
| 180 | + |
| 181 | +Run all approved jobs. **DO only.** |
| 182 | + |
| 183 | +- `stream_output`: Stream stdout/stderr in real-time. |
| 184 | +- `timeout`: Timeout in seconds per job (default: 300). |
| 185 | +- `force_execution`: Skip version compatibility checks. |
| 186 | + |
| 187 | +```python |
| 188 | +do_client.process_approved_jobs() |
| 189 | +``` |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +## Cleanup |
| 194 | + |
| 195 | +### `client.delete_syftbox(verbose=True, broadcast_delete_events=True)` |
| 196 | + |
| 197 | +Delete all SyftBox state: Google Drive files, local caches, and local folder. |
| 198 | + |
| 199 | +- `broadcast_delete_events`: Notify approved peers about deleted files before cleanup. |
0 commit comments