nadata 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.
- nadata-0.1.0/LICENSE +21 -0
- nadata-0.1.0/PKG-INFO +191 -0
- nadata-0.1.0/README.md +178 -0
- nadata-0.1.0/nadata/__init__.py +15 -0
- nadata-0.1.0/nadata/api.py +894 -0
- nadata-0.1.0/nadata/cli.py +445 -0
- nadata-0.1.0/nadata/console.py +486 -0
- nadata-0.1.0/nadata/core/__init__.py +0 -0
- nadata-0.1.0/nadata/core/database/__init__.py +38 -0
- nadata-0.1.0/nadata/core/database/builtins.py +87 -0
- nadata-0.1.0/nadata/core/database/database.py +958 -0
- nadata-0.1.0/nadata/core/database/dumper.py +285 -0
- nadata-0.1.0/nadata/core/database/entity_id.py +142 -0
- nadata-0.1.0/nadata/core/database/instance.py +706 -0
- nadata-0.1.0/nadata/core/database/network_index.py +1142 -0
- nadata-0.1.0/nadata/core/database/page_manager.py +175 -0
- nadata-0.1.0/nadata/core/database/persistence/__init__.py +28 -0
- nadata-0.1.0/nadata/core/database/persistence/binary_cells.py +1141 -0
- nadata-0.1.0/nadata/core/database/persistence/compaction.py +97 -0
- nadata-0.1.0/nadata/core/database/persistence/dumper.py +798 -0
- nadata-0.1.0/nadata/core/database/persistence/lazy_instances.py +1537 -0
- nadata-0.1.0/nadata/core/database/persistence/loader.py +424 -0
- nadata-0.1.0/nadata/core/database/persistence/record_store.py +228 -0
- nadata-0.1.0/nadata/core/database/persistence/serialization.py +605 -0
- nadata-0.1.0/nadata/core/database/query_engine.py +222 -0
- nadata-0.1.0/nadata/core/database/queryset.py +508 -0
- nadata-0.1.0/nadata/core/database/reconciliation.py +287 -0
- nadata-0.1.0/nadata/core/database/slotted_page.py +190 -0
- nadata-0.1.0/nadata/core/database/spatial_index.py +1080 -0
- nadata-0.1.0/nadata/core/expressions/__init__.py +44 -0
- nadata-0.1.0/nadata/core/expressions/autograd.py +2909 -0
- nadata-0.1.0/nadata/core/expressions/builtins.py +4673 -0
- nadata-0.1.0/nadata/core/expressions/expression.py +2658 -0
- nadata-0.1.0/nadata/core/expressions/io_builtins.py +972 -0
- nadata-0.1.0/nadata/core/expressions/scope.py +336 -0
- nadata-0.1.0/nadata/core/expressions/statement.py +953 -0
- nadata-0.1.0/nadata/core/struct/__init__.py +14 -0
- nadata-0.1.0/nadata/core/struct/struct.py +218 -0
- nadata-0.1.0/nadata/core/struct/struct_attribute.py +100 -0
- nadata-0.1.0/nadata/core/struct/struct_method.py +324 -0
- nadata-0.1.0/nadata/core/types/__init__.py +33 -0
- nadata-0.1.0/nadata/core/types/bits/__init__.py +0 -0
- nadata-0.1.0/nadata/core/types/bits/bits.py +686 -0
- nadata-0.1.0/nadata/core/types/home_types/__init__.py +19 -0
- nadata-0.1.0/nadata/core/types/home_types/color.py +102 -0
- nadata-0.1.0/nadata/core/types/home_types/coordinate.py +1008 -0
- nadata-0.1.0/nadata/core/types/home_types/datetime.py +362 -0
- nadata-0.1.0/nadata/core/types/home_types/geogrid.py +92 -0
- nadata-0.1.0/nadata/core/types/home_types/geometry.py +1223 -0
- nadata-0.1.0/nadata/core/types/home_types/graph.py +0 -0
- nadata-0.1.0/nadata/core/types/home_types/planet.py +359 -0
- nadata-0.1.0/nadata/core/types/home_types/sea_level.py +98 -0
- nadata-0.1.0/nadata/core/types/home_types/vec.py +0 -0
- nadata-0.1.0/nadata/core/types/types.py +1345 -0
- nadata-0.1.0/nadata/core/values/__init__.py +14 -0
- nadata-0.1.0/nadata/core/values/values.py +1568 -0
- nadata-0.1.0/nadata/parser/__init__.py +0 -0
- nadata-0.1.0/nadata/parser/expressions/__init__.py +6 -0
- nadata-0.1.0/nadata/parser/expressions/dependencies.py +318 -0
- nadata-0.1.0/nadata/parser/expressions/expression_parser.py +993 -0
- nadata-0.1.0/nadata/parser/expressions/splitter.py +98 -0
- nadata-0.1.0/nadata/parser/expressions/statement_parser.py +1425 -0
- nadata-0.1.0/nadata/parser/expressions/tokenizer.py +402 -0
- nadata-0.1.0/nadata/parser/expressions/type_parser.py +187 -0
- nadata-0.1.0/nadata/parser/nadata_loader/__init__.py +8 -0
- nadata-0.1.0/nadata/parser/nadata_loader/loader.py +951 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/__init__.py +0 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/declaration.py +105 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/imports.py +164 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/nastruct_parser.py +209 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/parse_attributes.py +149 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/parse_callables.py +436 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/parse_expression.py +59 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/parse_structs.py +206 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/parser_state.py +84 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/resolver.py +1412 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/struct_body_state.py +50 -0
- nadata-0.1.0/nadata/parser/nastruct_parser/tmp_structs.py +156 -0
- nadata-0.1.0/nadata/parser/utils/__init__.py +20 -0
- nadata-0.1.0/nadata/parser/utils/brackets.py +252 -0
- nadata-0.1.0/nadata/parser/utils/comments_remove.py +149 -0
- nadata-0.1.0/nadata/parser/utils/identifiers.py +121 -0
- nadata-0.1.0/nadata/session.py +868 -0
- nadata-0.1.0/nadata.egg-info/PKG-INFO +191 -0
- nadata-0.1.0/nadata.egg-info/SOURCES.txt +131 -0
- nadata-0.1.0/nadata.egg-info/dependency_links.txt +1 -0
- nadata-0.1.0/nadata.egg-info/entry_points.txt +2 -0
- nadata-0.1.0/nadata.egg-info/requires.txt +4 -0
- nadata-0.1.0/nadata.egg-info/top_level.txt +1 -0
- nadata-0.1.0/pyproject.toml +35 -0
- nadata-0.1.0/setup.cfg +4 -0
- nadata-0.1.0/tests/test_api.py +381 -0
- nadata-0.1.0/tests/test_autograd.py +1507 -0
- nadata-0.1.0/tests/test_binary_persistence.py +532 -0
- nadata-0.1.0/tests/test_builtins.py +227 -0
- nadata-0.1.0/tests/test_cli.py +170 -0
- nadata-0.1.0/tests/test_console.py +150 -0
- nadata-0.1.0/tests/test_const_dims.py +383 -0
- nadata-0.1.0/tests/test_core.py +173 -0
- nadata-0.1.0/tests/test_database.py +344 -0
- nadata-0.1.0/tests/test_error_handling.py +231 -0
- nadata-0.1.0/tests/test_examples.py +307 -0
- nadata-0.1.0/tests/test_expression_parser.py +710 -0
- nadata-0.1.0/tests/test_expressions.py +309 -0
- nadata-0.1.0/tests/test_geodesy.py +1025 -0
- nadata-0.1.0/tests/test_geogrid.py +599 -0
- nadata-0.1.0/tests/test_geometry.py +896 -0
- nadata-0.1.0/tests/test_grammar.py +319 -0
- nadata-0.1.0/tests/test_imports.py +287 -0
- nadata-0.1.0/tests/test_indexing.py +327 -0
- nadata-0.1.0/tests/test_io.py +805 -0
- nadata-0.1.0/tests/test_language_features.py +528 -0
- nadata-0.1.0/tests/test_loops.py +506 -0
- nadata-0.1.0/tests/test_membership.py +307 -0
- nadata-0.1.0/tests/test_memory.py +976 -0
- nadata-0.1.0/tests/test_nadata_loader.py +248 -0
- nadata-0.1.0/tests/test_network.py +538 -0
- nadata-0.1.0/tests/test_nid.py +442 -0
- nadata-0.1.0/tests/test_osm.py +390 -0
- nadata-0.1.0/tests/test_parser.py +378 -0
- nadata-0.1.0/tests/test_persistence.py +669 -0
- nadata-0.1.0/tests/test_queryset.py +220 -0
- nadata-0.1.0/tests/test_queue_types.py +430 -0
- nadata-0.1.0/tests/test_reconciliation.py +308 -0
- nadata-0.1.0/tests/test_resolution.py +470 -0
- nadata-0.1.0/tests/test_session.py +592 -0
- nadata-0.1.0/tests/test_set_type.py +376 -0
- nadata-0.1.0/tests/test_spatial_index.py +831 -0
- nadata-0.1.0/tests/test_spatial_tensor.py +459 -0
- nadata-0.1.0/tests/test_strings_and_indexes.py +295 -0
- nadata-0.1.0/tests/test_target_assignment.py +361 -0
- nadata-0.1.0/tests/test_tensor_ops.py +1807 -0
- nadata-0.1.0/tests/test_tensor_slicing.py +356 -0
nadata-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nathan Cerisara
|
|
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.
|
nadata-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nadata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A declarative data schema and object-graph modeling framework
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
11
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Nadata
|
|
15
|
+
|
|
16
|
+
[](https://github.com/nath54/Nadata/actions/workflows/ci.yml)
|
|
17
|
+
|
|
18
|
+
**Nadata** is a declarative data schema and object-graph framework with its own
|
|
19
|
+
language. You describe your data model in `.nastruct` schema files, populate it
|
|
20
|
+
in `.nadata` data files, and get a typed, queryable, persistent object graph —
|
|
21
|
+
usable from the command line or as an embedded Python library.
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
# structs.nastruct — the model
|
|
25
|
+
class Human {
|
|
26
|
+
name: Str;
|
|
27
|
+
birthday: DateTime = DateTime();
|
|
28
|
+
|
|
29
|
+
@age(now: DateTime = DateTime.now()) -> DateTime {
|
|
30
|
+
return now - self.birthday;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# data.nadata — the data
|
|
35
|
+
tom = Human(name="Tom", birthday=DateTime(d=12, m=4, y=2003));
|
|
36
|
+
|
|
37
|
+
print("Tom is an adult:", tom.age(DateTime.now()).year >= 18);
|
|
38
|
+
Array[Human] adults = Human.where((h: Human) -> h.age(DateTime.now()).year >= 18);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Typed schema language** — structs, inheritance, attributes with defaults,
|
|
44
|
+
`const` bind-once attributes, methods and computed properties, standalone
|
|
45
|
+
functions; `import "...";` shares schema libraries across projects
|
|
46
|
+
- **String library and hash indexes** — typed string members (`split`,
|
|
47
|
+
`join`, `replace`, `contains`, ...), and opt-in per-attribute hash
|
|
48
|
+
indexes (`index(Human, "email")` + `get_by(Human, "email", x)`) with
|
|
49
|
+
automatic insert / update / removal maintenance — O(1) equality
|
|
50
|
+
lookups instead of full scans
|
|
51
|
+
- **Rich type system** — sized integers/floats (`Int32`, `UFloat16`, ...),
|
|
52
|
+
`Str`, `Bool`, `DateTime`, `Color`, `Array[T]`, `Dict[K, V]`, `Set[T]`,
|
|
53
|
+
`Queue[T]` / `PriorityQueue[T, P]`, sparse spatial grids
|
|
54
|
+
(`GridSquare2D[T]`, `GridHex2D[T]`, `GridCube3D[T]`), shape-checked
|
|
55
|
+
`Tensor[T, d1, ...]` with symbolic dims bound to `const` attributes,
|
|
56
|
+
entity references; indexing (`arr[0]`,
|
|
57
|
+
`dict["k"]`) and string concatenation
|
|
58
|
+
- **Error handling** — `raise "message";` and `try { ... } catch (err) { ... }`
|
|
59
|
+
in scripts and method bodies; runtime errors (indexing, I/O builtins)
|
|
60
|
+
are catchable too, while `return` / `break` / `continue` pass through
|
|
61
|
+
- **Declarative data files** — forward and circular references, script
|
|
62
|
+
statements, `print`, chained polymorphic queries
|
|
63
|
+
- **Runtime introspection** — `elt.id`, `type(x)`, `elt.list_attr()` /
|
|
64
|
+
`list_methods()`, schema-constrained `getattr`/`setattr`, and database-wide
|
|
65
|
+
`schema_classes()` / `schema_functions()`
|
|
66
|
+
- **Persistence** — whole-database dumps, dirty-only delta appends, and
|
|
67
|
+
removal tombstones to a single `.ndb` file
|
|
68
|
+
- **Bounded memory** — disk-backed lazy rows (~50 bytes/row index), a
|
|
69
|
+
bounded LRU decode cache with clean-only eviction, `pin`/`unpin`,
|
|
70
|
+
`flush`/`clear_cache`, and `remove_from_db` from scripts — stream
|
|
71
|
+
millions of rows while the model stays hot
|
|
72
|
+
- **Autograd and training** — tape-based reverse-mode differentiation on Float
|
|
73
|
+
tensors (arithmetic, `matmul`, reductions, shape ops, `gather`, slices,
|
|
74
|
+
`relu`), seeded data partitioning for train/valid/test splits, and built-in
|
|
75
|
+
`SGD` — train models end-to-end in `.nadata` scripts
|
|
76
|
+
- **Sessions & identity** — a project folder is a session: `#init` seeds once
|
|
77
|
+
per world, `#auto` syncs every open, `#manual` scripts take parameters
|
|
78
|
+
(`#manual(lr: Float = 0.05)`), and `nid = "name"` gives instances stable,
|
|
79
|
+
updatable identity (`get_by_nid`, `nids`, `first`/`last`) — schema files
|
|
80
|
+
re-merge on every open, and schema evolution is reconciled against
|
|
81
|
+
persisted rows (removed attributes are dropped; type changes are
|
|
82
|
+
reported, never fatal). I/O builtins (`read_json`, `write_csv`,
|
|
83
|
+
`file_hash`, ...) resolve against the project root, with
|
|
84
|
+
`get_setting`/`set_setting` freshness markers
|
|
85
|
+
- **Interactive console** — `nadata console <path>` REPL over any loaded
|
|
86
|
+
database, with persistent state and expression echoing
|
|
87
|
+
- **Python API** — load, query, mutate, execute raw source, persist
|
|
88
|
+
- **Zero dependencies** — pure Python 3.10+
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
git clone <repository-url>
|
|
94
|
+
cd Nadata
|
|
95
|
+
pip install -e .
|
|
96
|
+
pip install -e .[dev] # optional: pytest + mypy for development
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Quick start
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Run a project (schema + data) and execute its scripts
|
|
103
|
+
nadata run examples/ex0_simple
|
|
104
|
+
|
|
105
|
+
# Print a summary of a project or a saved .ndb database
|
|
106
|
+
nadata info examples/ex0_simple
|
|
107
|
+
nadata info store.ndb
|
|
108
|
+
|
|
109
|
+
# Persist a project to a single database file
|
|
110
|
+
nadata dump examples/ex0_simple store.ndb
|
|
111
|
+
|
|
112
|
+
# Explore it interactively (works on folders and .ndb files)
|
|
113
|
+
nadata console examples/ex0_simple
|
|
114
|
+
nadata console store.ndb
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Or from Python:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import nadata
|
|
121
|
+
|
|
122
|
+
app = nadata.Nadata.load("./examples/ex0_simple")
|
|
123
|
+
|
|
124
|
+
print(app.get_attribute("tom", "birthplace")) # Paris
|
|
125
|
+
print(app.count("Human")) # 3
|
|
126
|
+
|
|
127
|
+
app.dump("store.ndb") # persist
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Documentation
|
|
131
|
+
|
|
132
|
+
| Document | Contents |
|
|
133
|
+
|---|---|
|
|
134
|
+
| [docs/tutorial.md](docs/tutorial.md) | Step-by-step tutorial: your first project |
|
|
135
|
+
| [docs/syntax.md](docs/syntax.md) | Full language reference: rules and syntax |
|
|
136
|
+
| [docs/architecture.md](docs/architecture.md) | How the engine works, stage by stage |
|
|
137
|
+
| [docs/api.md](docs/api.md) | Python API and CLI reference |
|
|
138
|
+
| [docs/persistence.md](docs/persistence.md) | The `.ndb` format, dumps and incremental saves |
|
|
139
|
+
| [docs/benchmarks.md](docs/benchmarks.md) | Engine stage profiling, synthetic benchmarks, SQLite comparison |
|
|
140
|
+
| [docs/development.md](docs/development.md) | Code style, testing, contributing |
|
|
141
|
+
|
|
142
|
+
## Examples
|
|
143
|
+
|
|
144
|
+
The `examples/` folder contains self-contained projects, from basics to
|
|
145
|
+
edge cases:
|
|
146
|
+
|
|
147
|
+
| Example | Demonstrates |
|
|
148
|
+
|---|---|
|
|
149
|
+
| `ex0_simple` | Family graph: inheritance, methods, forward refs, queries |
|
|
150
|
+
| `ex1_primitives` | Every sized integer/float type and boundary values |
|
|
151
|
+
| `ex2_inheritance` | Circular references, polymorphic queries |
|
|
152
|
+
| `ex3_collections` | Nested arrays, dictionaries, `Color`, `DateTime` math |
|
|
153
|
+
| `ex4_expressions` | `if`/`else`, boolean operators, local declarations |
|
|
154
|
+
| `ex5_edge_cases` | Parser edge cases: comments, spacing, empty constructs |
|
|
155
|
+
| `ex6_loops_collections` | Loops (`for-in`, C-style, `while`), fuel guards, collections |
|
|
156
|
+
| `ex7_queues_sets` | FIFO / priority queues, typed sets, membership probes |
|
|
157
|
+
| `ex8_grids_tensors` | Sparse spatial grids (square/hex/cube), shape-checked tensors |
|
|
158
|
+
| `ex9_constants` | `const` bind-once attributes, symbolic tensor dims |
|
|
159
|
+
| `ex10_cnn` | Conv1d/conv2d, pooling, and a basic convolutional neural network |
|
|
160
|
+
| `ex11_transformer` | A minimal transformer block: attention, LayerNorm, feed-forward, `topk` sampling |
|
|
161
|
+
| `ex12_optimizer_checkpoint` | Training a gelu network with Adam, checkpointing optimizer state to a sidecar file, and resuming from it |
|
|
162
|
+
|
|
163
|
+
## Editor support
|
|
164
|
+
|
|
165
|
+
Syntax highlighting for `.nastruct` and `.nadata` files ships as a
|
|
166
|
+
VS Code / VSCodium extension in
|
|
167
|
+
[`editors/vscode-nadata`](editors/vscode-nadata). `.vsix` packages are
|
|
168
|
+
not stored in git — build one and install it:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
cd editors/vscode-nadata
|
|
172
|
+
npx -y @vscode/vsce package --allow-missing-repository # -> nadata-support-<version>.vsix
|
|
173
|
+
code --install-extension nadata-support-<version>.vsix
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Packaged releases attach the current `.vsix` to the matching git tag.
|
|
177
|
+
|
|
178
|
+
A sync test (`tests/test_grammar.py`) keeps the grammar aligned with the
|
|
179
|
+
language: it fails whenever a builtin type, keyword, or scope is missing.
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
python -m pytest tests/ -q # run the test suite
|
|
185
|
+
python -m mypy nadata/ # type check (strict)
|
|
186
|
+
python -m scripts.inspect_parse examples/ex0_simple # inspect the parse IR
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT — see [LICENSE](LICENSE).
|
nadata-0.1.0/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Nadata
|
|
2
|
+
|
|
3
|
+
[](https://github.com/nath54/Nadata/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
**Nadata** is a declarative data schema and object-graph framework with its own
|
|
6
|
+
language. You describe your data model in `.nastruct` schema files, populate it
|
|
7
|
+
in `.nadata` data files, and get a typed, queryable, persistent object graph —
|
|
8
|
+
usable from the command line or as an embedded Python library.
|
|
9
|
+
|
|
10
|
+
```text
|
|
11
|
+
# structs.nastruct — the model
|
|
12
|
+
class Human {
|
|
13
|
+
name: Str;
|
|
14
|
+
birthday: DateTime = DateTime();
|
|
15
|
+
|
|
16
|
+
@age(now: DateTime = DateTime.now()) -> DateTime {
|
|
17
|
+
return now - self.birthday;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# data.nadata — the data
|
|
22
|
+
tom = Human(name="Tom", birthday=DateTime(d=12, m=4, y=2003));
|
|
23
|
+
|
|
24
|
+
print("Tom is an adult:", tom.age(DateTime.now()).year >= 18);
|
|
25
|
+
Array[Human] adults = Human.where((h: Human) -> h.age(DateTime.now()).year >= 18);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **Typed schema language** — structs, inheritance, attributes with defaults,
|
|
31
|
+
`const` bind-once attributes, methods and computed properties, standalone
|
|
32
|
+
functions; `import "...";` shares schema libraries across projects
|
|
33
|
+
- **String library and hash indexes** — typed string members (`split`,
|
|
34
|
+
`join`, `replace`, `contains`, ...), and opt-in per-attribute hash
|
|
35
|
+
indexes (`index(Human, "email")` + `get_by(Human, "email", x)`) with
|
|
36
|
+
automatic insert / update / removal maintenance — O(1) equality
|
|
37
|
+
lookups instead of full scans
|
|
38
|
+
- **Rich type system** — sized integers/floats (`Int32`, `UFloat16`, ...),
|
|
39
|
+
`Str`, `Bool`, `DateTime`, `Color`, `Array[T]`, `Dict[K, V]`, `Set[T]`,
|
|
40
|
+
`Queue[T]` / `PriorityQueue[T, P]`, sparse spatial grids
|
|
41
|
+
(`GridSquare2D[T]`, `GridHex2D[T]`, `GridCube3D[T]`), shape-checked
|
|
42
|
+
`Tensor[T, d1, ...]` with symbolic dims bound to `const` attributes,
|
|
43
|
+
entity references; indexing (`arr[0]`,
|
|
44
|
+
`dict["k"]`) and string concatenation
|
|
45
|
+
- **Error handling** — `raise "message";` and `try { ... } catch (err) { ... }`
|
|
46
|
+
in scripts and method bodies; runtime errors (indexing, I/O builtins)
|
|
47
|
+
are catchable too, while `return` / `break` / `continue` pass through
|
|
48
|
+
- **Declarative data files** — forward and circular references, script
|
|
49
|
+
statements, `print`, chained polymorphic queries
|
|
50
|
+
- **Runtime introspection** — `elt.id`, `type(x)`, `elt.list_attr()` /
|
|
51
|
+
`list_methods()`, schema-constrained `getattr`/`setattr`, and database-wide
|
|
52
|
+
`schema_classes()` / `schema_functions()`
|
|
53
|
+
- **Persistence** — whole-database dumps, dirty-only delta appends, and
|
|
54
|
+
removal tombstones to a single `.ndb` file
|
|
55
|
+
- **Bounded memory** — disk-backed lazy rows (~50 bytes/row index), a
|
|
56
|
+
bounded LRU decode cache with clean-only eviction, `pin`/`unpin`,
|
|
57
|
+
`flush`/`clear_cache`, and `remove_from_db` from scripts — stream
|
|
58
|
+
millions of rows while the model stays hot
|
|
59
|
+
- **Autograd and training** — tape-based reverse-mode differentiation on Float
|
|
60
|
+
tensors (arithmetic, `matmul`, reductions, shape ops, `gather`, slices,
|
|
61
|
+
`relu`), seeded data partitioning for train/valid/test splits, and built-in
|
|
62
|
+
`SGD` — train models end-to-end in `.nadata` scripts
|
|
63
|
+
- **Sessions & identity** — a project folder is a session: `#init` seeds once
|
|
64
|
+
per world, `#auto` syncs every open, `#manual` scripts take parameters
|
|
65
|
+
(`#manual(lr: Float = 0.05)`), and `nid = "name"` gives instances stable,
|
|
66
|
+
updatable identity (`get_by_nid`, `nids`, `first`/`last`) — schema files
|
|
67
|
+
re-merge on every open, and schema evolution is reconciled against
|
|
68
|
+
persisted rows (removed attributes are dropped; type changes are
|
|
69
|
+
reported, never fatal). I/O builtins (`read_json`, `write_csv`,
|
|
70
|
+
`file_hash`, ...) resolve against the project root, with
|
|
71
|
+
`get_setting`/`set_setting` freshness markers
|
|
72
|
+
- **Interactive console** — `nadata console <path>` REPL over any loaded
|
|
73
|
+
database, with persistent state and expression echoing
|
|
74
|
+
- **Python API** — load, query, mutate, execute raw source, persist
|
|
75
|
+
- **Zero dependencies** — pure Python 3.10+
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
git clone <repository-url>
|
|
81
|
+
cd Nadata
|
|
82
|
+
pip install -e .
|
|
83
|
+
pip install -e .[dev] # optional: pytest + mypy for development
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Quick start
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Run a project (schema + data) and execute its scripts
|
|
90
|
+
nadata run examples/ex0_simple
|
|
91
|
+
|
|
92
|
+
# Print a summary of a project or a saved .ndb database
|
|
93
|
+
nadata info examples/ex0_simple
|
|
94
|
+
nadata info store.ndb
|
|
95
|
+
|
|
96
|
+
# Persist a project to a single database file
|
|
97
|
+
nadata dump examples/ex0_simple store.ndb
|
|
98
|
+
|
|
99
|
+
# Explore it interactively (works on folders and .ndb files)
|
|
100
|
+
nadata console examples/ex0_simple
|
|
101
|
+
nadata console store.ndb
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or from Python:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
import nadata
|
|
108
|
+
|
|
109
|
+
app = nadata.Nadata.load("./examples/ex0_simple")
|
|
110
|
+
|
|
111
|
+
print(app.get_attribute("tom", "birthplace")) # Paris
|
|
112
|
+
print(app.count("Human")) # 3
|
|
113
|
+
|
|
114
|
+
app.dump("store.ndb") # persist
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Documentation
|
|
118
|
+
|
|
119
|
+
| Document | Contents |
|
|
120
|
+
|---|---|
|
|
121
|
+
| [docs/tutorial.md](docs/tutorial.md) | Step-by-step tutorial: your first project |
|
|
122
|
+
| [docs/syntax.md](docs/syntax.md) | Full language reference: rules and syntax |
|
|
123
|
+
| [docs/architecture.md](docs/architecture.md) | How the engine works, stage by stage |
|
|
124
|
+
| [docs/api.md](docs/api.md) | Python API and CLI reference |
|
|
125
|
+
| [docs/persistence.md](docs/persistence.md) | The `.ndb` format, dumps and incremental saves |
|
|
126
|
+
| [docs/benchmarks.md](docs/benchmarks.md) | Engine stage profiling, synthetic benchmarks, SQLite comparison |
|
|
127
|
+
| [docs/development.md](docs/development.md) | Code style, testing, contributing |
|
|
128
|
+
|
|
129
|
+
## Examples
|
|
130
|
+
|
|
131
|
+
The `examples/` folder contains self-contained projects, from basics to
|
|
132
|
+
edge cases:
|
|
133
|
+
|
|
134
|
+
| Example | Demonstrates |
|
|
135
|
+
|---|---|
|
|
136
|
+
| `ex0_simple` | Family graph: inheritance, methods, forward refs, queries |
|
|
137
|
+
| `ex1_primitives` | Every sized integer/float type and boundary values |
|
|
138
|
+
| `ex2_inheritance` | Circular references, polymorphic queries |
|
|
139
|
+
| `ex3_collections` | Nested arrays, dictionaries, `Color`, `DateTime` math |
|
|
140
|
+
| `ex4_expressions` | `if`/`else`, boolean operators, local declarations |
|
|
141
|
+
| `ex5_edge_cases` | Parser edge cases: comments, spacing, empty constructs |
|
|
142
|
+
| `ex6_loops_collections` | Loops (`for-in`, C-style, `while`), fuel guards, collections |
|
|
143
|
+
| `ex7_queues_sets` | FIFO / priority queues, typed sets, membership probes |
|
|
144
|
+
| `ex8_grids_tensors` | Sparse spatial grids (square/hex/cube), shape-checked tensors |
|
|
145
|
+
| `ex9_constants` | `const` bind-once attributes, symbolic tensor dims |
|
|
146
|
+
| `ex10_cnn` | Conv1d/conv2d, pooling, and a basic convolutional neural network |
|
|
147
|
+
| `ex11_transformer` | A minimal transformer block: attention, LayerNorm, feed-forward, `topk` sampling |
|
|
148
|
+
| `ex12_optimizer_checkpoint` | Training a gelu network with Adam, checkpointing optimizer state to a sidecar file, and resuming from it |
|
|
149
|
+
|
|
150
|
+
## Editor support
|
|
151
|
+
|
|
152
|
+
Syntax highlighting for `.nastruct` and `.nadata` files ships as a
|
|
153
|
+
VS Code / VSCodium extension in
|
|
154
|
+
[`editors/vscode-nadata`](editors/vscode-nadata). `.vsix` packages are
|
|
155
|
+
not stored in git — build one and install it:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
cd editors/vscode-nadata
|
|
159
|
+
npx -y @vscode/vsce package --allow-missing-repository # -> nadata-support-<version>.vsix
|
|
160
|
+
code --install-extension nadata-support-<version>.vsix
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Packaged releases attach the current `.vsix` to the matching git tag.
|
|
164
|
+
|
|
165
|
+
A sync test (`tests/test_grammar.py`) keeps the grammar aligned with the
|
|
166
|
+
language: it fails whenever a builtin type, keyword, or scope is missing.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
python -m pytest tests/ -q # run the test suite
|
|
172
|
+
python -m mypy nadata/ # type check (strict)
|
|
173
|
+
python -m scripts.inspect_parse examples/ex0_simple # inspect the parse IR
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Nadata package entry point.
|
|
3
|
+
|
|
4
|
+
Re-exports the high level Nadata facade and the CLI main function so the
|
|
5
|
+
library can be imported (import nadata) and the console script installed
|
|
6
|
+
(nadata = nadata.cli:main) from a single package.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Import Modules
|
|
10
|
+
from nadata.api import Nadata
|
|
11
|
+
from nadata.cli import main
|
|
12
|
+
|
|
13
|
+
__all__ = ["Nadata", "main", "__version__"]
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|