gitgraf 0.1.0__tar.gz → 0.2.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.
- gitgraf-0.2.0/LICENSE +21 -0
- gitgraf-0.2.0/PKG-INFO +132 -0
- gitgraf-0.2.0/README.md +120 -0
- gitgraf-0.2.0/pyproject.toml +23 -0
- gitgraf-0.2.0/src/gitgraf/__init__.py +6 -0
- gitgraf-0.2.0/src/gitgraf/cli.py +1471 -0
- gitgraf-0.2.0/src/gitgraf/datamodel.py +539 -0
- gitgraf-0.2.0/src/gitgraf/diff.py +75 -0
- gitgraf-0.2.0/src/gitgraf/export.py +104 -0
- gitgraf-0.2.0/src/gitgraf/gitops.py +255 -0
- gitgraf-0.2.0/src/gitgraf/graph.py +1135 -0
- gitgraf-0.2.0/src/gitgraf/hooks.py +16 -0
- gitgraf-0.2.0/src/gitgraf/model.py +133 -0
- gitgraf-0.2.0/src/gitgraf/modeledit.py +554 -0
- gitgraf-0.2.0/src/gitgraf/palette.py +117 -0
- gitgraf-0.2.0/src/gitgraf/resolve.py +167 -0
- gitgraf-0.2.0/src/gitgraf/search.py +146 -0
- gitgraf-0.2.0/src/gitgraf/settings.py +35 -0
- gitgraf-0.2.0/src/gitgraf/store.py +421 -0
- gitgraf-0.2.0/src/gitgraf/terminal.py +30 -0
- gitgraf-0.2.0/src/gitgraf/timeutil.py +74 -0
- gitgraf-0.1.0/PKG-INFO +0 -6
- gitgraf-0.1.0/README.md +0 -0
- gitgraf-0.1.0/gitgraf.egg-info/PKG-INFO +0 -6
- gitgraf-0.1.0/gitgraf.egg-info/SOURCES.txt +0 -7
- gitgraf-0.1.0/gitgraf.egg-info/dependency_links.txt +0 -1
- gitgraf-0.1.0/gitgraf.egg-info/top_level.txt +0 -1
- gitgraf-0.1.0/main.py +0 -6
- gitgraf-0.1.0/pyproject.toml +0 -7
- gitgraf-0.1.0/setup.cfg +0 -4
gitgraf-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sebastian Haglund
|
|
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.
|
gitgraf-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitgraf
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A graph of nodes, facts and edges kept as human-readable YAML files in git, with valid, knowledge and change time on every record
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: networkx>=3.3
|
|
8
|
+
Requires-Dist: pyyaml>=6.0
|
|
9
|
+
Requires-Dist: typer>=0.12
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Gitgraf
|
|
14
|
+
|
|
15
|
+
Gitgraf keeps a graph of nodes, facts and edges as human-readable YAML files in a git repository: `pip install`, no server, no database.
|
|
16
|
+
|
|
17
|
+
Every fact and edge carries three time axes, and nothing is ever overwritten:
|
|
18
|
+
|
|
19
|
+
- **Valid time** (`valid_from`, `valid_to`): when it is true in the world.
|
|
20
|
+
- **Knowledge time** (`known_at`): when it was first known.
|
|
21
|
+
- **Change time** (`changed_at`, `superseded_at`): when the record was written or replaced. An update appends a new version, so the graph can be read as it was at any earlier moment.
|
|
22
|
+
|
|
23
|
+
It is the store that bibliotheke, a knowledge graph framework, is built on, and it works on its own for any register of dated facts.
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
gitgraf init
|
|
29
|
+
gitgraf add node windfarm "Hornsea 2"
|
|
30
|
+
gitgraf add node bmu "T_HOWBO-1"
|
|
31
|
+
gitgraf add fact hornsea-2 capacity_mw 1386 --valid-from 2022-08-31
|
|
32
|
+
gitgraf add edge t-howbo-1 part_of hornsea-2 --valid-from 2021-12
|
|
33
|
+
|
|
34
|
+
gitgraf show hornsea-2 # the current graph
|
|
35
|
+
gitgraf show hornsea-2 --valid-at 2022-01 # what was true then
|
|
36
|
+
gitgraf show hornsea-2 --known-at 2024 # what had been learned by then
|
|
37
|
+
gitgraf show hornsea-2 --at-commit v1.0 # as committed at a git revision
|
|
38
|
+
gitgraf show hornsea-2 --json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`add fact` and `add edge` print a record id. Use it to change a record without losing history:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
gitgraf update f53fd77 --value 1320 # appends a new version
|
|
45
|
+
gitgraf retract f53fd77 # hides it from the current graph
|
|
46
|
+
gitgraf history hornsea-2 # every version, including superseded ones
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Sources and edge attributes
|
|
50
|
+
|
|
51
|
+
Any fact or edge can say where it comes from, and an edge can carry attributes of the link itself, such as a share of ownership:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
gitgraf add fact hornsea-2 capacity_mw 1386 --source "TEC register 2026-03"
|
|
55
|
+
gitgraf add edge hornsea-2 owned_by orsted --set share=0.5 --valid-from 2022-09 --source "company announcement"
|
|
56
|
+
gitgraf update e2778f9 --set share=0.4 --source "annual report 2025" # a new version; the old share stays in history
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A new version keeps the source and attributes it does not change. In a batch for `gitgraf import`, `source` can be set once for the whole batch, per node, or per record, and an edge takes `attrs: {share: 0.5}`.
|
|
60
|
+
|
|
61
|
+
The data model can type the attributes of a relation and require a source on every record:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
source: required # a write without a source is refused; `check` reports hand edits that drop one
|
|
65
|
+
edges:
|
|
66
|
+
owned_by:
|
|
67
|
+
from: windfarm
|
|
68
|
+
to: company
|
|
69
|
+
attrs:
|
|
70
|
+
share: {type: number, required: true}
|
|
71
|
+
role: {type: enum, values: [operator, investor]}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`gitgraf model add edge owned_by windfarm company --attr share:number` declares one from the command line. Both are stored only where present, so a graph that uses neither has the same files as before.
|
|
75
|
+
|
|
76
|
+
## Files
|
|
77
|
+
|
|
78
|
+
A graph is a directory with a `gitgraf.yaml` marker and one file per node at `nodes/<type>/<id>.yaml`, with optional Markdown next to it at `nodes/<type>/<id>.md`:
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
id: hornsea-2
|
|
82
|
+
type: windfarm
|
|
83
|
+
name: Hornsea 2
|
|
84
|
+
notes: ''
|
|
85
|
+
facts:
|
|
86
|
+
- id: f53fd77
|
|
87
|
+
key: capacity_mw
|
|
88
|
+
value: 1386
|
|
89
|
+
valid_from: 2022-08-31
|
|
90
|
+
valid_to: null
|
|
91
|
+
known_at: 2026-11-14T10:07:00Z
|
|
92
|
+
changed_at: 2026-11-14T10:07:00Z
|
|
93
|
+
superseded_at: null
|
|
94
|
+
edges: []
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
A node's file is dumped deterministically, so a git diff shows only what changed.
|
|
98
|
+
|
|
99
|
+
## Commands
|
|
100
|
+
|
|
101
|
+
| Command | What it does |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `init`, `add node\|fact\|edge`, `update`, `retract`, `import` | Write the graph; `import` merges a batch file and is safe to re-run |
|
|
104
|
+
| `show`, `history`, `list`, `types`, `search`, `export` | Read it; all take `--valid-at`, `--known-at`, `--changed-at` and `--at-commit` |
|
|
105
|
+
| `merge` | Join two nodes that are the same thing; an alias resolves wherever an id is expected |
|
|
106
|
+
| `model`, `model add\|rename\|drop`, `model diff\|log\|version\|tag` | An optional data model: what node types, facts and edges the graph allows, and how it changed |
|
|
107
|
+
| `check` | Validate the files against each other and the model; lists possible duplicates |
|
|
108
|
+
| `diff` | What changed between two git revisions |
|
|
109
|
+
| `hook install`, `ci` | A pre-commit hook and a GitHub Actions workflow that run `check` and refuse destructive model changes |
|
|
110
|
+
|
|
111
|
+
## From Python
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from gitgraf import At, Graph
|
|
115
|
+
|
|
116
|
+
graph = Graph.open("registry")
|
|
117
|
+
node = graph.node("hornsea-2")
|
|
118
|
+
facts = graph.facts(node.id, At(valid_at="2022-01", known_at="2024"))
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`Graph.nx(at)` returns a frozen `networkx.MultiDiGraph` of what is in view.
|
|
122
|
+
|
|
123
|
+
## Building on it
|
|
124
|
+
|
|
125
|
+
A package on top keeps its own names with `gitgraf.settings.configure(cli=..., package=..., markers=...)`, called before `gitgraf.cli` is imported, and adds its own commands to `gitgraf.cli.app`. `gitgraf.hooks.checks` and `gitgraf.hooks.rewrites` let it check and maintain its own sections of the marker file.
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
uv sync
|
|
131
|
+
uv run pytest
|
|
132
|
+
```
|
gitgraf-0.2.0/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Gitgraf
|
|
2
|
+
|
|
3
|
+
Gitgraf keeps a graph of nodes, facts and edges as human-readable YAML files in a git repository: `pip install`, no server, no database.
|
|
4
|
+
|
|
5
|
+
Every fact and edge carries three time axes, and nothing is ever overwritten:
|
|
6
|
+
|
|
7
|
+
- **Valid time** (`valid_from`, `valid_to`): when it is true in the world.
|
|
8
|
+
- **Knowledge time** (`known_at`): when it was first known.
|
|
9
|
+
- **Change time** (`changed_at`, `superseded_at`): when the record was written or replaced. An update appends a new version, so the graph can be read as it was at any earlier moment.
|
|
10
|
+
|
|
11
|
+
It is the store that bibliotheke, a knowledge graph framework, is built on, and it works on its own for any register of dated facts.
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
gitgraf init
|
|
17
|
+
gitgraf add node windfarm "Hornsea 2"
|
|
18
|
+
gitgraf add node bmu "T_HOWBO-1"
|
|
19
|
+
gitgraf add fact hornsea-2 capacity_mw 1386 --valid-from 2022-08-31
|
|
20
|
+
gitgraf add edge t-howbo-1 part_of hornsea-2 --valid-from 2021-12
|
|
21
|
+
|
|
22
|
+
gitgraf show hornsea-2 # the current graph
|
|
23
|
+
gitgraf show hornsea-2 --valid-at 2022-01 # what was true then
|
|
24
|
+
gitgraf show hornsea-2 --known-at 2024 # what had been learned by then
|
|
25
|
+
gitgraf show hornsea-2 --at-commit v1.0 # as committed at a git revision
|
|
26
|
+
gitgraf show hornsea-2 --json
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`add fact` and `add edge` print a record id. Use it to change a record without losing history:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
gitgraf update f53fd77 --value 1320 # appends a new version
|
|
33
|
+
gitgraf retract f53fd77 # hides it from the current graph
|
|
34
|
+
gitgraf history hornsea-2 # every version, including superseded ones
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Sources and edge attributes
|
|
38
|
+
|
|
39
|
+
Any fact or edge can say where it comes from, and an edge can carry attributes of the link itself, such as a share of ownership:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
gitgraf add fact hornsea-2 capacity_mw 1386 --source "TEC register 2026-03"
|
|
43
|
+
gitgraf add edge hornsea-2 owned_by orsted --set share=0.5 --valid-from 2022-09 --source "company announcement"
|
|
44
|
+
gitgraf update e2778f9 --set share=0.4 --source "annual report 2025" # a new version; the old share stays in history
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A new version keeps the source and attributes it does not change. In a batch for `gitgraf import`, `source` can be set once for the whole batch, per node, or per record, and an edge takes `attrs: {share: 0.5}`.
|
|
48
|
+
|
|
49
|
+
The data model can type the attributes of a relation and require a source on every record:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
source: required # a write without a source is refused; `check` reports hand edits that drop one
|
|
53
|
+
edges:
|
|
54
|
+
owned_by:
|
|
55
|
+
from: windfarm
|
|
56
|
+
to: company
|
|
57
|
+
attrs:
|
|
58
|
+
share: {type: number, required: true}
|
|
59
|
+
role: {type: enum, values: [operator, investor]}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`gitgraf model add edge owned_by windfarm company --attr share:number` declares one from the command line. Both are stored only where present, so a graph that uses neither has the same files as before.
|
|
63
|
+
|
|
64
|
+
## Files
|
|
65
|
+
|
|
66
|
+
A graph is a directory with a `gitgraf.yaml` marker and one file per node at `nodes/<type>/<id>.yaml`, with optional Markdown next to it at `nodes/<type>/<id>.md`:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
id: hornsea-2
|
|
70
|
+
type: windfarm
|
|
71
|
+
name: Hornsea 2
|
|
72
|
+
notes: ''
|
|
73
|
+
facts:
|
|
74
|
+
- id: f53fd77
|
|
75
|
+
key: capacity_mw
|
|
76
|
+
value: 1386
|
|
77
|
+
valid_from: 2022-08-31
|
|
78
|
+
valid_to: null
|
|
79
|
+
known_at: 2026-11-14T10:07:00Z
|
|
80
|
+
changed_at: 2026-11-14T10:07:00Z
|
|
81
|
+
superseded_at: null
|
|
82
|
+
edges: []
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A node's file is dumped deterministically, so a git diff shows only what changed.
|
|
86
|
+
|
|
87
|
+
## Commands
|
|
88
|
+
|
|
89
|
+
| Command | What it does |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `init`, `add node\|fact\|edge`, `update`, `retract`, `import` | Write the graph; `import` merges a batch file and is safe to re-run |
|
|
92
|
+
| `show`, `history`, `list`, `types`, `search`, `export` | Read it; all take `--valid-at`, `--known-at`, `--changed-at` and `--at-commit` |
|
|
93
|
+
| `merge` | Join two nodes that are the same thing; an alias resolves wherever an id is expected |
|
|
94
|
+
| `model`, `model add\|rename\|drop`, `model diff\|log\|version\|tag` | An optional data model: what node types, facts and edges the graph allows, and how it changed |
|
|
95
|
+
| `check` | Validate the files against each other and the model; lists possible duplicates |
|
|
96
|
+
| `diff` | What changed between two git revisions |
|
|
97
|
+
| `hook install`, `ci` | A pre-commit hook and a GitHub Actions workflow that run `check` and refuse destructive model changes |
|
|
98
|
+
|
|
99
|
+
## From Python
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from gitgraf import At, Graph
|
|
103
|
+
|
|
104
|
+
graph = Graph.open("registry")
|
|
105
|
+
node = graph.node("hornsea-2")
|
|
106
|
+
facts = graph.facts(node.id, At(valid_at="2022-01", known_at="2024"))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`Graph.nx(at)` returns a frozen `networkx.MultiDiGraph` of what is in view.
|
|
110
|
+
|
|
111
|
+
## Building on it
|
|
112
|
+
|
|
113
|
+
A package on top keeps its own names with `gitgraf.settings.configure(cli=..., package=..., markers=...)`, called before `gitgraf.cli` is imported, and adds its own commands to `gitgraf.cli.app`. `gitgraf.hooks.checks` and `gitgraf.hooks.rewrites` let it check and maintain its own sections of the marker file.
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
uv sync
|
|
119
|
+
uv run pytest
|
|
120
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "gitgraf"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "A graph of nodes, facts and edges kept as human-readable YAML files in git, with valid, knowledge and change time on every record"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"networkx>=3.3",
|
|
11
|
+
"pyyaml>=6.0",
|
|
12
|
+
"typer>=0.12",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
gitgraf = "gitgraf.cli:main"
|
|
17
|
+
|
|
18
|
+
[dependency-groups]
|
|
19
|
+
dev = ["pytest>=8"]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["uv_build>=0.9,<0.10"]
|
|
23
|
+
build-backend = "uv_build"
|