pivograph 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,4 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ dist/
4
+ .venv/
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ First release, for schema version 3 of the PivoGraph project file format.
6
+
7
+ - Check project files: every problem at once, each with its place in the file and what is allowed there.
8
+ - Save documents as project files; nothing is written while there is a problem.
9
+ - Read data tables as Python records, pandas data frames or CSV.
10
+ - Command line: `check`, `tables`, `csv`, `graphs`, `schema`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PivoGraph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.5
2
+ Name: pivograph
3
+ Version: 0.1.0
4
+ Summary: Read, check and save PivoGraph project files: scientific graphs that stay editable.
5
+ Project-URL: Homepage, https://pivograph.com
6
+ Project-URL: Documentation, https://pivograph.com/developers/project-format/
7
+ Project-URL: Source, https://github.com/pivograph/pivograph
8
+ Project-URL: Issues, https://github.com/pivograph/pivograph/issues
9
+ Project-URL: Changelog, https://github.com/pivograph/pivograph/blob/main/python/CHANGELOG.md
10
+ Author-email: PivoGraph <support@pivograph.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: biology,graphs,json schema,pivograph,publication figures,scientific figures,statistics
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
19
+ Classifier: Topic :: Scientific/Engineering :: Visualization
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+
24
+ # pivograph
25
+
26
+ Read, check and save [PivoGraph](https://pivograph.com) project files in Python.
27
+
28
+ PivoGraph is a free editor for scientific graphs and statistics that runs in the browser. A project
29
+ file (`.pivograph`) is plain JSON in an [open format](https://pivograph.com/developers/project-format/):
30
+ data tables together with their graphs, analyses and annotations. A figure written by a script or an
31
+ AI assistant opens in PivoGraph with everything still editable, and can be exported for a journal as
32
+ TIFF, PDF, EPS, SVG or PNG.
33
+
34
+ ```
35
+ pip install pivograph
36
+ ```
37
+
38
+ Python 3.9 or later. No dependencies.
39
+
40
+ ## Check a file
41
+
42
+ ```
43
+ python -m pivograph check figure.pivograph
44
+ ```
45
+
46
+ Every problem is listed at once, with its place in the file and what is allowed there:
47
+
48
+ ```
49
+ 2 errors: PivoGraph will not open this file.
50
+ 1. [error] tables[0].graph.variantId
51
+ "box-plot" is not allowed for a column table. Allowed: column-scatter-only, scatter-bar, ...
52
+ 2. [error] tables[0].analyses[0].method
53
+ "t-test" is not allowed for a column table. Did you mean "ttest"? Allowed: ttest, oneWayAnova, ...
54
+ ```
55
+
56
+ In Python, `pivograph.check()` takes a path or a document and returns a report:
57
+
58
+ - `report.errors`: PivoGraph would not open the file.
59
+ - `report.warnings`: the file opens, but something in it would be ignored or could not be matched,
60
+ such as a t test on a group that is not in the table.
61
+ - `report.ok`: neither. Everything in the file takes effect as written.
62
+
63
+ Checks follow the PivoGraph application. The test suite compares the two on several hundred damaged
64
+ files, and both must reach the same verdict on each of them.
65
+
66
+ ## Save a figure
67
+
68
+ `pivograph.save()` checks a document and writes it unchanged. While there is any problem, it raises
69
+ `InvalidProjectError`, which lists all of them, and writes nothing.
70
+
71
+ ```python
72
+ import pivograph
73
+
74
+ viability = {
75
+ "Vehicle": [98, 102, 95, 100, 97],
76
+ "Compound": [71, 68, 74, 70, 66],
77
+ }
78
+
79
+ document = {
80
+ "format": "pivograph-project",
81
+ "schemaVersion": pivograph.SCHEMA_VERSION,
82
+ "meta": {"title": "Cell viability"},
83
+ "tables": [
84
+ {
85
+ "name": "Cell viability",
86
+ "format": "column",
87
+ # values[row][replicate]: one inner list per row
88
+ "dataSets": [
89
+ {"name": name, "values": [[value] for value in values]}
90
+ for name, values in viability.items()
91
+ ],
92
+ "graph": {
93
+ "variantId": "scatter-bar",
94
+ "plot": {"family": "column", "options": {"mode": "meanWithSem"}},
95
+ },
96
+ "titles": {"y": {"text": "Viability (% of vehicle)"}},
97
+ "analyses": [
98
+ {
99
+ "method": "ttest",
100
+ "params": {
101
+ "groupA": "Vehicle",
102
+ "groupB": "Compound",
103
+ "design": "unpaired",
104
+ "variance": "welch",
105
+ },
106
+ }
107
+ ],
108
+ }
109
+ ],
110
+ }
111
+
112
+ pivograph.save(document, "viability.pivograph")
113
+ ```
114
+
115
+ Open the file at [pivograph.com](https://pivograph.com/app/) with File > Open Project, or drop it on
116
+ the page. The data stays in your browser.
117
+
118
+ What a table offers is available in code and on the command line (`python -m pivograph graphs`):
119
+
120
+ ```python
121
+ pivograph.variants_for("column") # graph types of column tables
122
+ pivograph.analyses_for("column") # analyses of column tables
123
+ pivograph.json_schema() # the JSON Schema of the file format
124
+ ```
125
+
126
+ ## Read data
127
+
128
+ ```python
129
+ project = pivograph.load("viability.pivograph")
130
+ table = project.table("Cell viability")
131
+
132
+ table.data_sets # ['Vehicle', 'Compound']
133
+ table.values("Compound") # [[71], [68], [74], [70], [66]]
134
+ table.to_dataframe() # one record per value; needs pandas
135
+ table.to_csv("viability.csv")
136
+ ```
137
+
138
+ ## For AI assistants
139
+
140
+ 1. Read measurements from the user's file in code. Do not retype numbers.
141
+ 2. Build the document as a Python dict and write it with `pivograph.save()`.
142
+ 3. If it raises, correct every problem it lists and save again.
143
+ 4. Do not write P values or asterisks into the figure. Add the analysis; PivoGraph computes it from
144
+ the data.
145
+ 5. Choose the error bar (`meanWithSd`, `meanWithSem`, ...), the test and the pairing the user asked
146
+ for. If they did not say, ask.
147
+
148
+ The complete specification: https://pivograph.com/developers/project-format/v3.md
149
+
150
+ ## License
151
+
152
+ MIT. The license covers this package and the file format documents, not the PivoGraph web
153
+ application or the PivoGraph name and logo.
@@ -0,0 +1,130 @@
1
+ # pivograph
2
+
3
+ Read, check and save [PivoGraph](https://pivograph.com) project files in Python.
4
+
5
+ PivoGraph is a free editor for scientific graphs and statistics that runs in the browser. A project
6
+ file (`.pivograph`) is plain JSON in an [open format](https://pivograph.com/developers/project-format/):
7
+ data tables together with their graphs, analyses and annotations. A figure written by a script or an
8
+ AI assistant opens in PivoGraph with everything still editable, and can be exported for a journal as
9
+ TIFF, PDF, EPS, SVG or PNG.
10
+
11
+ ```
12
+ pip install pivograph
13
+ ```
14
+
15
+ Python 3.9 or later. No dependencies.
16
+
17
+ ## Check a file
18
+
19
+ ```
20
+ python -m pivograph check figure.pivograph
21
+ ```
22
+
23
+ Every problem is listed at once, with its place in the file and what is allowed there:
24
+
25
+ ```
26
+ 2 errors: PivoGraph will not open this file.
27
+ 1. [error] tables[0].graph.variantId
28
+ "box-plot" is not allowed for a column table. Allowed: column-scatter-only, scatter-bar, ...
29
+ 2. [error] tables[0].analyses[0].method
30
+ "t-test" is not allowed for a column table. Did you mean "ttest"? Allowed: ttest, oneWayAnova, ...
31
+ ```
32
+
33
+ In Python, `pivograph.check()` takes a path or a document and returns a report:
34
+
35
+ - `report.errors`: PivoGraph would not open the file.
36
+ - `report.warnings`: the file opens, but something in it would be ignored or could not be matched,
37
+ such as a t test on a group that is not in the table.
38
+ - `report.ok`: neither. Everything in the file takes effect as written.
39
+
40
+ Checks follow the PivoGraph application. The test suite compares the two on several hundred damaged
41
+ files, and both must reach the same verdict on each of them.
42
+
43
+ ## Save a figure
44
+
45
+ `pivograph.save()` checks a document and writes it unchanged. While there is any problem, it raises
46
+ `InvalidProjectError`, which lists all of them, and writes nothing.
47
+
48
+ ```python
49
+ import pivograph
50
+
51
+ viability = {
52
+ "Vehicle": [98, 102, 95, 100, 97],
53
+ "Compound": [71, 68, 74, 70, 66],
54
+ }
55
+
56
+ document = {
57
+ "format": "pivograph-project",
58
+ "schemaVersion": pivograph.SCHEMA_VERSION,
59
+ "meta": {"title": "Cell viability"},
60
+ "tables": [
61
+ {
62
+ "name": "Cell viability",
63
+ "format": "column",
64
+ # values[row][replicate]: one inner list per row
65
+ "dataSets": [
66
+ {"name": name, "values": [[value] for value in values]}
67
+ for name, values in viability.items()
68
+ ],
69
+ "graph": {
70
+ "variantId": "scatter-bar",
71
+ "plot": {"family": "column", "options": {"mode": "meanWithSem"}},
72
+ },
73
+ "titles": {"y": {"text": "Viability (% of vehicle)"}},
74
+ "analyses": [
75
+ {
76
+ "method": "ttest",
77
+ "params": {
78
+ "groupA": "Vehicle",
79
+ "groupB": "Compound",
80
+ "design": "unpaired",
81
+ "variance": "welch",
82
+ },
83
+ }
84
+ ],
85
+ }
86
+ ],
87
+ }
88
+
89
+ pivograph.save(document, "viability.pivograph")
90
+ ```
91
+
92
+ Open the file at [pivograph.com](https://pivograph.com/app/) with File > Open Project, or drop it on
93
+ the page. The data stays in your browser.
94
+
95
+ What a table offers is available in code and on the command line (`python -m pivograph graphs`):
96
+
97
+ ```python
98
+ pivograph.variants_for("column") # graph types of column tables
99
+ pivograph.analyses_for("column") # analyses of column tables
100
+ pivograph.json_schema() # the JSON Schema of the file format
101
+ ```
102
+
103
+ ## Read data
104
+
105
+ ```python
106
+ project = pivograph.load("viability.pivograph")
107
+ table = project.table("Cell viability")
108
+
109
+ table.data_sets # ['Vehicle', 'Compound']
110
+ table.values("Compound") # [[71], [68], [74], [70], [66]]
111
+ table.to_dataframe() # one record per value; needs pandas
112
+ table.to_csv("viability.csv")
113
+ ```
114
+
115
+ ## For AI assistants
116
+
117
+ 1. Read measurements from the user's file in code. Do not retype numbers.
118
+ 2. Build the document as a Python dict and write it with `pivograph.save()`.
119
+ 3. If it raises, correct every problem it lists and save again.
120
+ 4. Do not write P values or asterisks into the figure. Add the analysis; PivoGraph computes it from
121
+ the data.
122
+ 5. Choose the error bar (`meanWithSd`, `meanWithSem`, ...), the test and the pairing the user asked
123
+ for. If they did not say, ask.
124
+
125
+ The complete specification: https://pivograph.com/developers/project-format/v3.md
126
+
127
+ ## License
128
+
129
+ MIT. The license covers this package and the file format documents, not the PivoGraph web
130
+ application or the PivoGraph name and logo.
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pivograph"
7
+ dynamic = ["version"]
8
+ description = "Read, check and save PivoGraph project files: scientific graphs that stay editable."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "PivoGraph", email = "support@pivograph.com" }]
14
+ keywords = [
15
+ "pivograph",
16
+ "scientific figures",
17
+ "publication figures",
18
+ "statistics",
19
+ "biology",
20
+ "graphs",
21
+ "json schema",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 4 - Beta",
25
+ "Intended Audience :: Science/Research",
26
+ "Operating System :: OS Independent",
27
+ "Programming Language :: Python :: 3",
28
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
29
+ "Topic :: Scientific/Engineering :: Visualization",
30
+ "Typing :: Typed",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://pivograph.com"
35
+ Documentation = "https://pivograph.com/developers/project-format/"
36
+ Source = "https://github.com/pivograph/pivograph"
37
+ Issues = "https://github.com/pivograph/pivograph/issues"
38
+ Changelog = "https://github.com/pivograph/pivograph/blob/main/python/CHANGELOG.md"
39
+
40
+ [project.scripts]
41
+ pivograph = "pivograph.__main__:main"
42
+
43
+ [tool.hatch.version]
44
+ path = "src/pivograph/__init__.py"
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["src/pivograph"]
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = ["src", "README.md", "CHANGELOG.md", "LICENSE"]
@@ -0,0 +1,37 @@
1
+ """Read, check and save PivoGraph project files (.pivograph)."""
2
+
3
+ from ._check import check, check_bytes, check_document, check_text, save
4
+ from ._project import Project, Table, load
5
+ from ._report import InvalidProjectError, Issue, Report
6
+ from ._rules import analyses_for, load_data, rules, variants_for
7
+
8
+ __version__ = "0.1.0"
9
+
10
+ #: The file format version this package writes and checks in full.
11
+ SCHEMA_VERSION: int = rules()["schemaVersion"]
12
+
13
+
14
+ def json_schema(version: int = SCHEMA_VERSION) -> dict:
15
+ """The published JSON Schema of a file format version."""
16
+ schema: dict = load_data(f"v{version}.json")
17
+ return schema
18
+
19
+
20
+ __all__ = [
21
+ "InvalidProjectError",
22
+ "Issue",
23
+ "Project",
24
+ "Report",
25
+ "SCHEMA_VERSION",
26
+ "Table",
27
+ "analyses_for",
28
+ "check",
29
+ "check_bytes",
30
+ "check_document",
31
+ "check_text",
32
+ "json_schema",
33
+ "load",
34
+ "save",
35
+ "variants_for",
36
+ "__version__",
37
+ ]
@@ -0,0 +1,103 @@
1
+ """Command line: ``python -m pivograph check figure.pivograph``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import sys
8
+ from typing import List, Optional
9
+
10
+ from . import (
11
+ SCHEMA_VERSION,
12
+ InvalidProjectError,
13
+ __version__,
14
+ analyses_for,
15
+ check,
16
+ json_schema,
17
+ load,
18
+ rules,
19
+ variants_for,
20
+ )
21
+
22
+
23
+ def main(argv: Optional[List[str]] = None) -> int:
24
+ for stream in (sys.stdout, sys.stderr):
25
+ reconfigure = getattr(stream, "reconfigure", None)
26
+ if reconfigure is not None:
27
+ reconfigure(encoding="utf-8", errors="backslashreplace")
28
+
29
+ parser = argparse.ArgumentParser(
30
+ prog="pivograph", description="Read and check PivoGraph project files (.pivograph)."
31
+ )
32
+ parser.add_argument("--version", action="version", version=f"pivograph {__version__}")
33
+ commands = parser.add_subparsers(dest="command", required=True)
34
+
35
+ command = commands.add_parser("check", help="report every problem in a project file")
36
+ command.add_argument("file", nargs="+")
37
+ command.add_argument(
38
+ "--allow-warnings", action="store_true", help="exit with 0 when there are only warnings"
39
+ )
40
+
41
+ command = commands.add_parser("tables", help="list the data tables of a project file")
42
+ command.add_argument("file")
43
+
44
+ command = commands.add_parser("csv", help="write one data table as CSV")
45
+ command.add_argument("file")
46
+ command.add_argument("output")
47
+ command.add_argument("--table", help="name of the table (default: the first one)")
48
+
49
+ command = commands.add_parser("graphs", help="list graph types and analyses for each table type")
50
+
51
+ command = commands.add_parser("schema", help="print the JSON Schema of the file format")
52
+ command.add_argument("--schema-version", type=int, default=SCHEMA_VERSION)
53
+
54
+ arguments = parser.parse_args(argv)
55
+ try:
56
+ return _run(arguments)
57
+ except InvalidProjectError as error:
58
+ print(error, file=sys.stderr)
59
+ return 1
60
+ except (OSError, KeyError, ValueError) as error:
61
+ print(error.args[-1] if error.args else error, file=sys.stderr)
62
+ return 1
63
+
64
+
65
+ def _run(arguments: argparse.Namespace) -> int:
66
+ if arguments.command == "check":
67
+ failed = False
68
+ for file in arguments.file:
69
+ report = check(file)
70
+ if len(arguments.file) > 1:
71
+ print(f"{file}:")
72
+ print(report)
73
+ failed |= bool(report.errors) or (bool(report.warnings) and not arguments.allow_warnings)
74
+ return 1 if failed else 0
75
+ if arguments.command == "tables":
76
+ project = load(arguments.file)
77
+ print(f"{project.title or 'Untitled project'}: {len(project.tables)} table(s)")
78
+ for number, table in enumerate(project.tables, start=1):
79
+ kind = f"{table.format}, derived" if table.derived else table.format
80
+ print(f"{number}. {table.name or '(no name)'} ({kind}): {len(table)} rows")
81
+ if table.data_sets:
82
+ print(f" {', '.join(table.data_sets)}")
83
+ return 0
84
+ if arguments.command == "csv":
85
+ project = load(arguments.file)
86
+ if not project.tables:
87
+ raise ValueError("The project has no tables.")
88
+ table = project.table(arguments.table) if arguments.table else project.tables[0]
89
+ table.to_csv(arguments.output)
90
+ print(f"Wrote {arguments.output}")
91
+ return 0
92
+ if arguments.command == "graphs":
93
+ for table_format in rules()["tables"]:
94
+ print(f"{table_format} tables")
95
+ print(f" graph types: {', '.join(variants_for(table_format))}")
96
+ print(f" analyses: {', '.join(analyses_for(table_format)) or 'none'}")
97
+ return 0
98
+ print(json.dumps(json_schema(arguments.schema_version), indent=2, ensure_ascii=False))
99
+ return 0
100
+
101
+
102
+ if __name__ == "__main__":
103
+ sys.exit(main())