gofish-graphics 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,300 @@
1
+ Metadata-Version: 2.4
2
+ Name: gofish-graphics
3
+ Version: 0.1.0
4
+ Summary: Python wrapper for GoFish Graphics - JavaScript is the source of truth for rendering
5
+ Author: GoFish Team
6
+ License: MIT
7
+ Keywords: visualization,charts,graphics,gofish
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Visualization
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+ Provides-Extra: pythonmonkey
21
+ Requires-Dist: pythonmonkey; extra == "pythonmonkey"
22
+ Provides-Extra: jspybridge
23
+ Requires-Dist: jsbridge; extra == "jspybridge"
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
27
+ Requires-Dist: black>=23.0; extra == "dev"
28
+ Requires-Dist: mypy>=1.0; extra == "dev"
29
+ Provides-Extra: jupyter
30
+ Requires-Dist: ipython>=8.0; extra == "jupyter"
31
+ Requires-Dist: jupyter>=1.0; extra == "jupyter"
32
+ Provides-Extra: data
33
+ Requires-Dist: numpy>=1.20; extra == "data"
34
+ Requires-Dist: pandas>=1.3; extra == "data"
35
+ Dynamic: requires-python
36
+
37
+ # GoFish Python
38
+
39
+ Python wrapper for [GoFish Graphics](https://gofish.graphics/), a declarative charting library.
40
+
41
+ **Important:** JavaScript is the source of truth for all rendering, layout, and reactivity. This Python package provides a syntax-similar API that translates Python calls to JavaScript execution. All interactive and animated graphics are handled by SolidJS in JavaScript.
42
+
43
+ ## Installation
44
+
45
+ ### Using pip
46
+
47
+ ```bash
48
+ # Install the package
49
+ pip install gofish-graphics
50
+
51
+ # Install a JavaScript bridge (choose one):
52
+ pip install pythonmonkey # Recommended
53
+ # OR
54
+ pip install jsbridge
55
+ ```
56
+
57
+ ### Using uv (Recommended)
58
+
59
+ ```bash
60
+ # Install uv: https://github.com/astral-sh/uv
61
+ curl -LsSf https://astral.sh/uv/install.sh | sh
62
+
63
+ # Install the package
64
+ uv pip install gofish-graphics
65
+
66
+ # Install a JavaScript bridge (choose one):
67
+ uv pip install pythonmonkey # Recommended
68
+ # OR
69
+ uv pip install jsbridge
70
+ ```
71
+
72
+ You also need the GoFish JavaScript bundle. Either:
73
+
74
+ 1. Install it as a sibling package in your monorepo
75
+ 2. Set `GOFISH_JS_PATH` environment variable to the `dist` directory
76
+ 3. The package will try to auto-detect it in common locations
77
+
78
+ ## Quick Start
79
+
80
+ ```python
81
+ from gofish import chart, spread, rect
82
+
83
+ # Data
84
+ alphabet = [
85
+ {"letter": "A", "frequency": 28},
86
+ {"letter": "B", "frequency": 55},
87
+ {"letter": "C", "frequency": 43},
88
+ ]
89
+
90
+ # Create chart (JavaScript executes all rendering)
91
+ chart(alphabet).flow(spread("letter", dir="x")).mark(rect(h="frequency")).render(w=500, h=300, axes=True)
92
+ ```
93
+
94
+ ## Architecture
95
+
96
+ ### JavaScript as Source of Truth
97
+
98
+ This wrapper follows the same pattern as Plotly and Bokeh:
99
+
100
+ - **Python**: Provides the API, data, and configuration
101
+ - **JavaScript**: Handles all rendering, layout computation, and reactivity
102
+
103
+ All GoFish features work through JavaScript:
104
+
105
+ - SolidJS reactivity for animations
106
+ - Interactive graphics via DOM events
107
+ - Complex layouts and coordinate transforms
108
+ - SVG rendering
109
+
110
+ ### How It Works
111
+
112
+ 1. **Python API**: You write Python code with syntax similar to JS GoFish
113
+ 2. **Translation**: Python calls are converted to JavaScript function calls
114
+ 3. **Execution**: JavaScript (via bridge) executes GoFish code
115
+ 4. **Rendering**: SolidJS renders interactive SVG to DOM or HTML
116
+
117
+ ## Usage
118
+
119
+ ### Basic Chart
120
+
121
+ ```python
122
+ from gofish import chart, spread, rect
123
+
124
+ data = [{"x": 1, "y": 10}, {"x": 2, "y": 20}]
125
+
126
+ chart(data).flow(spread("x", dir="x")).mark(rect(h="y")).render(w=500, h=300)
127
+ ```
128
+
129
+ ### Stacked Bar Chart
130
+
131
+ ```python
132
+ from gofish import chart, spread, stack, rect
133
+
134
+ chart(data).flow(
135
+ spread("category", dir="x"),
136
+ stack("series", dir="y")
137
+ ).mark(rect(h="value", fill="series")).render(w=500, h=300, axes=True)
138
+ ```
139
+
140
+ ### With Pandas
141
+
142
+ ```python
143
+ import pandas as pd
144
+ from gofish import chart, spread, rect
145
+
146
+ df = pd.DataFrame({
147
+ "category": ["A", "B", "C"],
148
+ "value": [10, 20, 30]
149
+ })
150
+
151
+ chart(df).flow(spread("category", dir="x")).mark(rect(h="value")).render()
152
+ ```
153
+
154
+ ### Jupyter Notebooks
155
+
156
+ ```python
157
+ from gofish import chart, spread, rect, display_jupyter
158
+
159
+ node = chart(data).flow(spread("x", dir="x")).mark(rect(h="y"))
160
+ display_jupyter(node, w=500, h=300, axes=True)
161
+ ```
162
+
163
+ ## API Reference
164
+
165
+ ### Core Functions
166
+
167
+ - `chart(data, **options)` - Create a new chart
168
+ - `ChartBuilder.flow(*operators)` - Add operators
169
+ - `ChartBuilder.mark(mark)` - Apply a mark
170
+ - `GoFishNode.render(**options)` - Render the chart
171
+
172
+ ### Operators
173
+
174
+ - `spread(field, dir="x", ...)` - Spread groups
175
+ - `stack(field, dir="y", ...)` - Stack groups
176
+ - `scatter(field, x, y, ...)` - Scatter plot positioning
177
+ - `group(field)` - Group by field
178
+ - `derive(fn)` - Transform data
179
+ - `normalize(field)` - Normalize values
180
+ - `repeat(field)` - Repeat items
181
+ - `log(label)` - Debug logging
182
+
183
+ ### Marks
184
+
185
+ - `rect(w, h, fill, ...)` - Rectangles
186
+ - `circle(r, fill, ...)` - Circles
187
+ - `line(stroke, ...)` - Lines
188
+ - `area(stroke, opacity, ...)` - Areas
189
+ - `scaffold(w, h, ...)` - Invisible guides
190
+ - `select(layer_name)` - Select from layer
191
+
192
+ ## Development
193
+
194
+ ### Setup with uv (Recommended)
195
+
196
+ ```bash
197
+ # Clone repository
198
+ git clone <repo-url>
199
+ cd packages/gofish-python
200
+
201
+ # Install uv: https://github.com/astral-sh/uv
202
+ curl -LsSf https://astral.sh/uv/install.sh | sh
203
+
204
+ # Install in development mode with all dependencies
205
+ uv sync
206
+
207
+ # This installs:
208
+ # - Package in editable mode
209
+ # - Dev dependencies (pytest, black, mypy)
210
+ # - Optional dependencies available via extras
211
+ ```
212
+
213
+ ### Setup with pip (Alternative)
214
+
215
+ ```bash
216
+ # Clone repository
217
+ git clone <repo-url>
218
+ cd packages/gofish-python
219
+
220
+ # Install in development mode
221
+ pip install -e ".[dev]"
222
+
223
+ # Install JavaScript bridge
224
+ pip install pythonmonkey
225
+ ```
226
+
227
+ ### Building GoFish JS Bundle
228
+
229
+ The Python wrapper needs the compiled GoFish JavaScript bundle:
230
+
231
+ ```bash
232
+ # In packages/gofish-graphics
233
+ pnpm install
234
+ pnpm build
235
+ ```
236
+
237
+ ### Development Commands
238
+
239
+ ```bash
240
+ # Run tests
241
+ uv run pytest
242
+ # or
243
+ make test
244
+
245
+ # Format code
246
+ uv run black gofish_python/
247
+
248
+ # Type checking
249
+ uv run mypy gofish_python/
250
+
251
+ # Build distribution
252
+ uv build
253
+ # or
254
+ make build
255
+
256
+ # Clean build artifacts
257
+ make clean
258
+ ```
259
+
260
+ ### Publishing
261
+
262
+ See [PUBLISHING.md](PUBLISHING.md) for detailed publishing instructions.
263
+
264
+ Quick version:
265
+
266
+ ```bash
267
+ # 1. Update version in pyproject.toml
268
+ # 2. Build
269
+ uv build
270
+ # or
271
+ make build
272
+
273
+ # 3. Publish to PyPI
274
+ uv publish
275
+ # or
276
+ make publish
277
+
278
+ # Or test on TestPyPI first
279
+ make testpypi
280
+ ```
281
+
282
+ ## Limitations
283
+
284
+ 1. **JavaScript Bridge Required**: You must install either `pythonmonkey` or `jsbridge`
285
+ 2. **JS Bundle Required**: The GoFish JavaScript bundle must be available
286
+ 3. **DOM Environment**: For interactive rendering, a DOM (browser/Jupyter) is needed
287
+ 4. **Performance**: Python↔JavaScript interop has overhead; complex animations may be slower
288
+
289
+ ## Future Work
290
+
291
+ - [ ] Better DOM-less rendering (static SVG export)
292
+ - [ ] Improved error messages
293
+ - [ ] Type hints and type checking
294
+ - [ ] More comprehensive examples
295
+ - [ ] Event handling from Python
296
+ - [ ] Animation control from Python
297
+
298
+ ## License
299
+
300
+ MIT
@@ -0,0 +1,264 @@
1
+ # GoFish Python
2
+
3
+ Python wrapper for [GoFish Graphics](https://gofish.graphics/), a declarative charting library.
4
+
5
+ **Important:** JavaScript is the source of truth for all rendering, layout, and reactivity. This Python package provides a syntax-similar API that translates Python calls to JavaScript execution. All interactive and animated graphics are handled by SolidJS in JavaScript.
6
+
7
+ ## Installation
8
+
9
+ ### Using pip
10
+
11
+ ```bash
12
+ # Install the package
13
+ pip install gofish-graphics
14
+
15
+ # Install a JavaScript bridge (choose one):
16
+ pip install pythonmonkey # Recommended
17
+ # OR
18
+ pip install jsbridge
19
+ ```
20
+
21
+ ### Using uv (Recommended)
22
+
23
+ ```bash
24
+ # Install uv: https://github.com/astral-sh/uv
25
+ curl -LsSf https://astral.sh/uv/install.sh | sh
26
+
27
+ # Install the package
28
+ uv pip install gofish-graphics
29
+
30
+ # Install a JavaScript bridge (choose one):
31
+ uv pip install pythonmonkey # Recommended
32
+ # OR
33
+ uv pip install jsbridge
34
+ ```
35
+
36
+ You also need the GoFish JavaScript bundle. Either:
37
+
38
+ 1. Install it as a sibling package in your monorepo
39
+ 2. Set `GOFISH_JS_PATH` environment variable to the `dist` directory
40
+ 3. The package will try to auto-detect it in common locations
41
+
42
+ ## Quick Start
43
+
44
+ ```python
45
+ from gofish import chart, spread, rect
46
+
47
+ # Data
48
+ alphabet = [
49
+ {"letter": "A", "frequency": 28},
50
+ {"letter": "B", "frequency": 55},
51
+ {"letter": "C", "frequency": 43},
52
+ ]
53
+
54
+ # Create chart (JavaScript executes all rendering)
55
+ chart(alphabet).flow(spread("letter", dir="x")).mark(rect(h="frequency")).render(w=500, h=300, axes=True)
56
+ ```
57
+
58
+ ## Architecture
59
+
60
+ ### JavaScript as Source of Truth
61
+
62
+ This wrapper follows the same pattern as Plotly and Bokeh:
63
+
64
+ - **Python**: Provides the API, data, and configuration
65
+ - **JavaScript**: Handles all rendering, layout computation, and reactivity
66
+
67
+ All GoFish features work through JavaScript:
68
+
69
+ - SolidJS reactivity for animations
70
+ - Interactive graphics via DOM events
71
+ - Complex layouts and coordinate transforms
72
+ - SVG rendering
73
+
74
+ ### How It Works
75
+
76
+ 1. **Python API**: You write Python code with syntax similar to JS GoFish
77
+ 2. **Translation**: Python calls are converted to JavaScript function calls
78
+ 3. **Execution**: JavaScript (via bridge) executes GoFish code
79
+ 4. **Rendering**: SolidJS renders interactive SVG to DOM or HTML
80
+
81
+ ## Usage
82
+
83
+ ### Basic Chart
84
+
85
+ ```python
86
+ from gofish import chart, spread, rect
87
+
88
+ data = [{"x": 1, "y": 10}, {"x": 2, "y": 20}]
89
+
90
+ chart(data).flow(spread("x", dir="x")).mark(rect(h="y")).render(w=500, h=300)
91
+ ```
92
+
93
+ ### Stacked Bar Chart
94
+
95
+ ```python
96
+ from gofish import chart, spread, stack, rect
97
+
98
+ chart(data).flow(
99
+ spread("category", dir="x"),
100
+ stack("series", dir="y")
101
+ ).mark(rect(h="value", fill="series")).render(w=500, h=300, axes=True)
102
+ ```
103
+
104
+ ### With Pandas
105
+
106
+ ```python
107
+ import pandas as pd
108
+ from gofish import chart, spread, rect
109
+
110
+ df = pd.DataFrame({
111
+ "category": ["A", "B", "C"],
112
+ "value": [10, 20, 30]
113
+ })
114
+
115
+ chart(df).flow(spread("category", dir="x")).mark(rect(h="value")).render()
116
+ ```
117
+
118
+ ### Jupyter Notebooks
119
+
120
+ ```python
121
+ from gofish import chart, spread, rect, display_jupyter
122
+
123
+ node = chart(data).flow(spread("x", dir="x")).mark(rect(h="y"))
124
+ display_jupyter(node, w=500, h=300, axes=True)
125
+ ```
126
+
127
+ ## API Reference
128
+
129
+ ### Core Functions
130
+
131
+ - `chart(data, **options)` - Create a new chart
132
+ - `ChartBuilder.flow(*operators)` - Add operators
133
+ - `ChartBuilder.mark(mark)` - Apply a mark
134
+ - `GoFishNode.render(**options)` - Render the chart
135
+
136
+ ### Operators
137
+
138
+ - `spread(field, dir="x", ...)` - Spread groups
139
+ - `stack(field, dir="y", ...)` - Stack groups
140
+ - `scatter(field, x, y, ...)` - Scatter plot positioning
141
+ - `group(field)` - Group by field
142
+ - `derive(fn)` - Transform data
143
+ - `normalize(field)` - Normalize values
144
+ - `repeat(field)` - Repeat items
145
+ - `log(label)` - Debug logging
146
+
147
+ ### Marks
148
+
149
+ - `rect(w, h, fill, ...)` - Rectangles
150
+ - `circle(r, fill, ...)` - Circles
151
+ - `line(stroke, ...)` - Lines
152
+ - `area(stroke, opacity, ...)` - Areas
153
+ - `scaffold(w, h, ...)` - Invisible guides
154
+ - `select(layer_name)` - Select from layer
155
+
156
+ ## Development
157
+
158
+ ### Setup with uv (Recommended)
159
+
160
+ ```bash
161
+ # Clone repository
162
+ git clone <repo-url>
163
+ cd packages/gofish-python
164
+
165
+ # Install uv: https://github.com/astral-sh/uv
166
+ curl -LsSf https://astral.sh/uv/install.sh | sh
167
+
168
+ # Install in development mode with all dependencies
169
+ uv sync
170
+
171
+ # This installs:
172
+ # - Package in editable mode
173
+ # - Dev dependencies (pytest, black, mypy)
174
+ # - Optional dependencies available via extras
175
+ ```
176
+
177
+ ### Setup with pip (Alternative)
178
+
179
+ ```bash
180
+ # Clone repository
181
+ git clone <repo-url>
182
+ cd packages/gofish-python
183
+
184
+ # Install in development mode
185
+ pip install -e ".[dev]"
186
+
187
+ # Install JavaScript bridge
188
+ pip install pythonmonkey
189
+ ```
190
+
191
+ ### Building GoFish JS Bundle
192
+
193
+ The Python wrapper needs the compiled GoFish JavaScript bundle:
194
+
195
+ ```bash
196
+ # In packages/gofish-graphics
197
+ pnpm install
198
+ pnpm build
199
+ ```
200
+
201
+ ### Development Commands
202
+
203
+ ```bash
204
+ # Run tests
205
+ uv run pytest
206
+ # or
207
+ make test
208
+
209
+ # Format code
210
+ uv run black gofish_python/
211
+
212
+ # Type checking
213
+ uv run mypy gofish_python/
214
+
215
+ # Build distribution
216
+ uv build
217
+ # or
218
+ make build
219
+
220
+ # Clean build artifacts
221
+ make clean
222
+ ```
223
+
224
+ ### Publishing
225
+
226
+ See [PUBLISHING.md](PUBLISHING.md) for detailed publishing instructions.
227
+
228
+ Quick version:
229
+
230
+ ```bash
231
+ # 1. Update version in pyproject.toml
232
+ # 2. Build
233
+ uv build
234
+ # or
235
+ make build
236
+
237
+ # 3. Publish to PyPI
238
+ uv publish
239
+ # or
240
+ make publish
241
+
242
+ # Or test on TestPyPI first
243
+ make testpypi
244
+ ```
245
+
246
+ ## Limitations
247
+
248
+ 1. **JavaScript Bridge Required**: You must install either `pythonmonkey` or `jsbridge`
249
+ 2. **JS Bundle Required**: The GoFish JavaScript bundle must be available
250
+ 3. **DOM Environment**: For interactive rendering, a DOM (browser/Jupyter) is needed
251
+ 4. **Performance**: Python↔JavaScript interop has overhead; complex animations may be slower
252
+
253
+ ## Future Work
254
+
255
+ - [ ] Better DOM-less rendering (static SVG export)
256
+ - [ ] Improved error messages
257
+ - [ ] Type hints and type checking
258
+ - [ ] More comprehensive examples
259
+ - [ ] Event handling from Python
260
+ - [ ] Animation control from Python
261
+
262
+ ## License
263
+
264
+ MIT