Python API Reference
Here is the complete API reference for controlling FViewer from Python.
fviewer.api.FViewer
Bases: ImageControlMixin, RegionsMixin, DataCubeMixin
A Python client to control the FViewer browser-based application.
This class allows users to programmatically load files, adjust UI settings (colormaps, stretches), and manage regions via a REST API to the FViewer backend.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
The base URL of the FastAPI backend. |
headers |
dict
|
HTTP headers for authentication (e.g., Jupyter token). |
client_id |
str
|
The specific browser client ID to control. If None, it will auto-connect to the first available client. |
Source code in fviewer/api.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
__init__(host=None, port=None, base_url=None, client_id=None)
Initializes the FViewer client connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The hostname for the FViewer server. |
None
|
port
|
int
|
The port for the FViewer server. |
None
|
base_url
|
str
|
A direct URL to the API (useful for remote JupyterLab environments). |
None
|
client_id
|
str
|
Target a specific connected browser tab. |
None
|
Source code in fviewer/api.py
get_clients()
Retrieves a list of all currently connected frontend browser client IDs.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: A list of active client IDs. |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the backend request fails. |
Source code in fviewer/api.py
load_file(path)
wait_for_ready(timeout=15, poll_interval=0.5)
Blocks execution until the FViewer FastAPI server is running and a browser client has connected via WebSocket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Maximum time to wait in seconds. Defaults to 15. |
15
|
poll_interval
|
float
|
Time between checks. Defaults to 0.5. |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the server and client are ready. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If no browser client connects within the timeout. |