flimkit-bridge 0.6.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.
Files changed (48) hide show
  1. flimkit_bridge-0.6.0/LICENSE.md +11 -0
  2. flimkit_bridge-0.6.0/PKG-INFO +60 -0
  3. flimkit_bridge-0.6.0/README.md +44 -0
  4. flimkit_bridge-0.6.0/flimkit_bridge/__init__.py +142 -0
  5. flimkit_bridge-0.6.0/flimkit_bridge/dataset_routes.py +594 -0
  6. flimkit_bridge-0.6.0/flimkit_bridge/datasets.py +356 -0
  7. flimkit_bridge-0.6.0/flimkit_bridge/discovery.py +118 -0
  8. flimkit_bridge-0.6.0/flimkit_bridge/fitting.py +388 -0
  9. flimkit_bridge-0.6.0/flimkit_bridge/formats.py +75 -0
  10. flimkit_bridge-0.6.0/flimkit_bridge/headless.py +90 -0
  11. flimkit_bridge-0.6.0/flimkit_bridge/irf.py +125 -0
  12. flimkit_bridge-0.6.0/flimkit_bridge/jobs.py +170 -0
  13. flimkit_bridge-0.6.0/flimkit_bridge/phasor.py +307 -0
  14. flimkit_bridge-0.6.0/flimkit_bridge/pipeline.py +275 -0
  15. flimkit_bridge-0.6.0/flimkit_bridge/server.py +413 -0
  16. flimkit_bridge-0.6.0/flimkit_bridge/state.py +10 -0
  17. flimkit_bridge-0.6.0/flimkit_bridge/version.py +23 -0
  18. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/PKG-INFO +60 -0
  19. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/SOURCES.txt +46 -0
  20. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/dependency_links.txt +1 -0
  21. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/entry_points.txt +5 -0
  22. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/requires.txt +6 -0
  23. flimkit_bridge-0.6.0/flimkit_bridge.egg-info/top_level.txt +1 -0
  24. flimkit_bridge-0.6.0/pyproject.toml +29 -0
  25. flimkit_bridge-0.6.0/setup.cfg +4 -0
  26. flimkit_bridge-0.6.0/tests/test_dataset_endpoints.py +347 -0
  27. flimkit_bridge-0.6.0/tests/test_datasets.py +321 -0
  28. flimkit_bridge-0.6.0/tests/test_discovery.py +187 -0
  29. flimkit_bridge-0.6.0/tests/test_encoding.py +66 -0
  30. flimkit_bridge-0.6.0/tests/test_fit_endpoints.py +128 -0
  31. flimkit_bridge-0.6.0/tests/test_fitting.py +355 -0
  32. flimkit_bridge-0.6.0/tests/test_formats.py +118 -0
  33. flimkit_bridge-0.6.0/tests/test_headless.py +124 -0
  34. flimkit_bridge-0.6.0/tests/test_image_server.py +88 -0
  35. flimkit_bridge-0.6.0/tests/test_irf.py +109 -0
  36. flimkit_bridge-0.6.0/tests/test_jobs.py +124 -0
  37. flimkit_bridge-0.6.0/tests/test_live_mode.py +107 -0
  38. flimkit_bridge-0.6.0/tests/test_per_pixel.py +93 -0
  39. flimkit_bridge-0.6.0/tests/test_phasor.py +497 -0
  40. flimkit_bridge-0.6.0/tests/test_phasor_annotations.py +90 -0
  41. flimkit_bridge-0.6.0/tests/test_phasor_endpoints.py +244 -0
  42. flimkit_bridge-0.6.0/tests/test_pipeline.py +165 -0
  43. flimkit_bridge-0.6.0/tests/test_pixel_endpoints.py +123 -0
  44. flimkit_bridge-0.6.0/tests/test_plugin.py +25 -0
  45. flimkit_bridge-0.6.0/tests/test_project_import.py +55 -0
  46. flimkit_bridge-0.6.0/tests/test_real_data.py +118 -0
  47. flimkit_bridge-0.6.0/tests/test_server.py +162 -0
  48. flimkit_bridge-0.6.0/tests/test_stitched_datasets.py +132 -0
@@ -0,0 +1,11 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2026 FLIMKit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ **If you use FLIMKit in academic work, a citation or acknowledgment is appreciated.** There is no formal publication yet but it is planned — for now, please reference the GitHub repository and the author's name.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: flimkit-bridge
3
+ Version: 0.6.0
4
+ Summary: The local HTTP server FLIMKit image analysis clients talk to
5
+ Author-email: Alex Hunt <alexander.hunt@ed.ac.uk>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE.md
10
+ Requires-Dist: flimkit>=0.13.2
11
+ Requires-Dist: numpy
12
+ Requires-Dist: tifffile
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest; extra == "test"
15
+ Dynamic: license-file
16
+
17
+ # flimkit-bridge
18
+
19
+ The local HTTP server that [FLIMKit](https://github.com/FLIMKit/FLIMKit) image analysis clients talk to.
20
+
21
+ Two add-ons use it. The [QuPath extension](https://github.com/FLIMKit/flimkit-qupath-bridge) and the [Fiji add-on](https://github.com/FLIMKit/flimkit-fiji-bridge) are both clients of this one server, so a fix here reaches both and neither carries its own copy of the API.
22
+
23
+ It started inside the QuPath add-on and moved out once there were two clients. The wire protocol it speaks was designed and first implemented in [flimkit-fiji-bridge](https://github.com/FLIMKit/flimkit-fiji-bridge) by Zhen Yuan Yeo (https://doi.org/10.5281/zenodo.21951612).
24
+
25
+ ## Running it
26
+
27
+ The server starts with FLIMKit. `Tools > FLIMKit Bridge...` shows its address and whether anything has connected.
28
+
29
+ It also runs without the desktop app, which is what you want on a headless machine or when QuPath or Fiji is the only front end:
30
+
31
+ ```bash
32
+ pip install flimkit-bridge
33
+ flimkit-bridge
34
+ ```
35
+
36
+ `--port` and `--token` are there if you need them, `--force` takes over from a bridge that has been left running, and `--no-announce` serves alongside one instead.
37
+
38
+ ## Pairing
39
+
40
+ The server writes its address and a generated token to `~/.flimkit/bridge.json`, and clients read that file, so there is nothing to type in. Each start mints a new token, so a client re-reads the file before every call.
41
+
42
+ It writes `~/.flimkit/qupath-bridge.json` alongside it, carrying the same address under the older protocol name. QuPath extensions built before the server moved out check for that name and stop pairing without it. The second file goes when those versions are retired.
43
+
44
+ ## Versions
45
+
46
+ `GET /v1/status` reports `protocol_version`, `bridge_version` and `flimkit_version`. A client checks `protocol_version`, which is what governs whether the two can talk. `bridge_version` is for display: the server and each client version independently now, so a difference between them is ordinary rather than a problem.
47
+
48
+ ## Security
49
+
50
+ The server listens on `127.0.0.1` only, and refuses any request whose `Host` header is not localhost, which stops a web page reaching it by resolving its own hostname to your machine. Every endpoint except the status check requires the token.
51
+
52
+ Both programs therefore have to be on the same machine. If they are not, forward the port over SSH rather than exposing it:
53
+
54
+ ```bash
55
+ ssh -L 8765:127.0.0.1:8765 you@the-flimkit-machine
56
+ ```
57
+
58
+ ## Licence
59
+
60
+ MIT. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,44 @@
1
+ # flimkit-bridge
2
+
3
+ The local HTTP server that [FLIMKit](https://github.com/FLIMKit/FLIMKit) image analysis clients talk to.
4
+
5
+ Two add-ons use it. The [QuPath extension](https://github.com/FLIMKit/flimkit-qupath-bridge) and the [Fiji add-on](https://github.com/FLIMKit/flimkit-fiji-bridge) are both clients of this one server, so a fix here reaches both and neither carries its own copy of the API.
6
+
7
+ It started inside the QuPath add-on and moved out once there were two clients. The wire protocol it speaks was designed and first implemented in [flimkit-fiji-bridge](https://github.com/FLIMKit/flimkit-fiji-bridge) by Zhen Yuan Yeo (https://doi.org/10.5281/zenodo.21951612).
8
+
9
+ ## Running it
10
+
11
+ The server starts with FLIMKit. `Tools > FLIMKit Bridge...` shows its address and whether anything has connected.
12
+
13
+ It also runs without the desktop app, which is what you want on a headless machine or when QuPath or Fiji is the only front end:
14
+
15
+ ```bash
16
+ pip install flimkit-bridge
17
+ flimkit-bridge
18
+ ```
19
+
20
+ `--port` and `--token` are there if you need them, `--force` takes over from a bridge that has been left running, and `--no-announce` serves alongside one instead.
21
+
22
+ ## Pairing
23
+
24
+ The server writes its address and a generated token to `~/.flimkit/bridge.json`, and clients read that file, so there is nothing to type in. Each start mints a new token, so a client re-reads the file before every call.
25
+
26
+ It writes `~/.flimkit/qupath-bridge.json` alongside it, carrying the same address under the older protocol name. QuPath extensions built before the server moved out check for that name and stop pairing without it. The second file goes when those versions are retired.
27
+
28
+ ## Versions
29
+
30
+ `GET /v1/status` reports `protocol_version`, `bridge_version` and `flimkit_version`. A client checks `protocol_version`, which is what governs whether the two can talk. `bridge_version` is for display: the server and each client version independently now, so a difference between them is ordinary rather than a problem.
31
+
32
+ ## Security
33
+
34
+ The server listens on `127.0.0.1` only, and refuses any request whose `Host` header is not localhost, which stops a web page reaching it by resolving its own hostname to your machine. Every endpoint except the status check requires the token.
35
+
36
+ Both programs therefore have to be on the same machine. If they are not, forward the port over SSH rather than exposing it:
37
+
38
+ ```bash
39
+ ssh -L 8765:127.0.0.1:8765 you@the-flimkit-machine
40
+ ```
41
+
42
+ ## Licence
43
+
44
+ MIT. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,142 @@
1
+ import atexit
2
+ import secrets
3
+ import threading
4
+
5
+ from flimkit.plugins import (
6
+ export_rois_geojson,
7
+ get_current_images,
8
+ import_rois_geojson,
9
+ panel_button,
10
+ plugin_config,
11
+ startup,
12
+ tool,
13
+ )
14
+
15
+ from flimkit_bridge import discovery
16
+ from flimkit_bridge.state import build_state
17
+ from flimkit_bridge.server import bind
18
+
19
+ FLIMKIT_PLUGIN_API = 1
20
+
21
+ PLUGIN_NAME = 'flimkit_bridge'
22
+
23
+ DEFAULT_PORT = 8765
24
+
25
+ _state = {
26
+ 'server': None,
27
+ 'thread': None,
28
+ 'token': '',
29
+ 'url': '',
30
+ 'error': '',
31
+ }
32
+
33
+
34
+ def bridge_status():
35
+ return dict(_state)
36
+
37
+
38
+ def _live_state(app):
39
+ state = build_state()
40
+ state.app = app
41
+ return state
42
+
43
+
44
+ def _start_server(app, port=DEFAULT_PORT):
45
+ token = secrets.token_urlsafe(24)
46
+ state = _live_state(app)
47
+ server = bind('127.0.0.1', port, token, state, live=True)
48
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
49
+ thread.start()
50
+ host, bound = server.server_address
51
+ _state.update({
52
+ 'server': server,
53
+ 'thread': thread,
54
+ 'token': token,
55
+ 'url': f'http://{host}:{bound}',
56
+ 'error': '',
57
+ })
58
+ discovery.write(_state['url'], token)
59
+ atexit.register(discovery.remove)
60
+ return _state
61
+
62
+
63
+ @startup('flimkit_bridge_server', order=200)
64
+ def start_bridge(app):
65
+ if _state['server'] is not None:
66
+ return
67
+ cfg = plugin_config(PLUGIN_NAME)
68
+ port = int(cfg.get('port', DEFAULT_PORT) or DEFAULT_PORT)
69
+ try:
70
+ _start_server(app, port)
71
+ except OSError as exc:
72
+ _state['error'] = str(exc)
73
+ print(f'[FLIMKit bridge] could not bind a port: {exc}')
74
+ return
75
+ if _state['url'] != f'http://127.0.0.1:{port}':
76
+ print(f'[FLIMKit bridge] port {port} was busy, using {_state["url"]}')
77
+ print(f'[FLIMKit bridge] listening on {_state["url"]}')
78
+ print(f'[FLIMKit bridge] details written to {discovery.discovery_path()}')
79
+
80
+
81
+ @panel_button('flimkit_bridge_send', 'Send to a viewer', panel='roi', order=200)
82
+ def send_to_clients(app):
83
+ from tkinter import messagebox
84
+ server = _state['server']
85
+ if server is None:
86
+ messagebox.showerror(
87
+ 'FLIMKit bridge',
88
+ 'The bridge is not running.\n\n'
89
+ + (_state['error'] or 'It failed to start with FLIMKit.'),
90
+ parent=getattr(app, 'root', None),
91
+ )
92
+ return
93
+ if not server.state.connected:
94
+ messagebox.showerror(
95
+ 'No viewer is connected',
96
+ 'Nothing has connected to FLIMKit yet.\n\n'
97
+ 'Start QuPath, then choose\n'
98
+ 'Extensions > FLIMKit bridge > Connect...\n\n'
99
+ 'It finds the address and token itself, from\n'
100
+ f'{discovery.discovery_path()}',
101
+ parent=getattr(app, 'root', None),
102
+ )
103
+ return
104
+ images = get_current_images(app)
105
+ names = sorted(images.get('images', {}))
106
+ if not names:
107
+ messagebox.showerror(
108
+ 'FLIMKit bridge',
109
+ 'There is nothing to send yet. Fit a dataset first.',
110
+ parent=getattr(app, 'root', None),
111
+ )
112
+ return
113
+ messagebox.showinfo(
114
+ 'FLIMKit bridge',
115
+ 'FLIMKit is serving ' + ', '.join(names) + '.\n\n'
116
+ 'In QuPath choose\n'
117
+ 'Extensions > FLIMKit bridge > Add FLIMKit images to project',
118
+ parent=getattr(app, 'root', None),
119
+ )
120
+
121
+
122
+ @tool(id='flimkit_bridge_open', label='FLIMKit Bridge...', menu='Tools', order=510)
123
+ def open_bridge(app):
124
+ from tkinter import messagebox
125
+ if _state['server'] is None:
126
+ messagebox.showerror(
127
+ 'FLIMKit bridge',
128
+ 'The bridge is not running.\n\n'
129
+ + (_state['error'] or 'It failed to start with FLIMKit.'),
130
+ parent=getattr(app, 'root', None),
131
+ )
132
+ return
133
+ connected = 'yes' if _state['server'].state.connected else 'no'
134
+ messagebox.showinfo(
135
+ 'FLIMKit bridge',
136
+ f'Address: {_state["url"]}\n'
137
+ f'A viewer is connected: {connected}\n\n'
138
+ f'Pairing details: {discovery.discovery_path()}\n\n'
139
+ 'In QuPath choose\n'
140
+ 'Extensions > FLIMKit bridge > Connect...',
141
+ parent=getattr(app, 'root', None),
142
+ )