causality-protocol 0.1.0a1__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.
- causality_protocol-0.1.0a1/LICENSE +21 -0
- causality_protocol-0.1.0a1/PKG-INFO +51 -0
- causality_protocol-0.1.0a1/README.md +38 -0
- causality_protocol-0.1.0a1/pyproject.toml +24 -0
- causality_protocol-0.1.0a1/setup.cfg +4 -0
- causality_protocol-0.1.0a1/src/causality_protocol.egg-info/PKG-INFO +51 -0
- causality_protocol-0.1.0a1/src/causality_protocol.egg-info/SOURCES.txt +10 -0
- causality_protocol-0.1.0a1/src/causality_protocol.egg-info/dependency_links.txt +1 -0
- causality_protocol-0.1.0a1/src/causality_protocol.egg-info/entry_points.txt +2 -0
- causality_protocol-0.1.0a1/src/causality_protocol.egg-info/top_level.txt +1 -0
- causality_protocol-0.1.0a1/src/causality_protocol.py +40 -0
- causality_protocol-0.1.0a1/tests/test_jsonl.py +37 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Contributors
|
|
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,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: causality-protocol
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Streaming JSON Lines reader and record counter
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# causality-protocol
|
|
15
|
+
|
|
16
|
+
Version 0.1.0a1 is a standalone streaming JSON Lines reader and record counter.
|
|
17
|
+
It reads ordinary JSON values without imposing a schema. This alpha does not
|
|
18
|
+
implement learning, a memory protocol, or a model. Python 3.11 or later; no
|
|
19
|
+
third-party dependencies.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
python -m pip install causality-protocol==0.1.0a1
|
|
23
|
+
causality-protocol records.jsonl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For a UTF-8 file containing:
|
|
27
|
+
|
|
28
|
+
```jsonl
|
|
29
|
+
{"name": "Ada", "score": 3}
|
|
30
|
+
{"name": "Lin", "score": 5}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
the command prints `{"records": 2}`. Use the Python API to process values:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from causality_protocol import iter_jsonl
|
|
37
|
+
|
|
38
|
+
for value in iter_jsonl("records.jsonl"):
|
|
39
|
+
print(value)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Blank lines are skipped. Any JSON value is accepted, including objects, arrays,
|
|
43
|
+
numbers, strings, booleans and null. Malformed records raise ValueError with the
|
|
44
|
+
file path and physical line number. Non-standard NaN and Infinity literals are
|
|
45
|
+
rejected. Values use Python's normal JSON decoding, including floating-point
|
|
46
|
+
numbers; this is not an arbitrary-precision decoder. The file is read lazily,
|
|
47
|
+
with memory proportional to the largest line. Filesystem and decoding errors
|
|
48
|
+
propagate to Python callers; the command prints errors on stderr and exits 2.
|
|
49
|
+
|
|
50
|
+
`python -m causality_protocol` is also supported. The API may change during alpha
|
|
51
|
+
development. Licensed under MIT; see LICENSE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# causality-protocol
|
|
2
|
+
|
|
3
|
+
Version 0.1.0a1 is a standalone streaming JSON Lines reader and record counter.
|
|
4
|
+
It reads ordinary JSON values without imposing a schema. This alpha does not
|
|
5
|
+
implement learning, a memory protocol, or a model. Python 3.11 or later; no
|
|
6
|
+
third-party dependencies.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
python -m pip install causality-protocol==0.1.0a1
|
|
10
|
+
causality-protocol records.jsonl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a UTF-8 file containing:
|
|
14
|
+
|
|
15
|
+
```jsonl
|
|
16
|
+
{"name": "Ada", "score": 3}
|
|
17
|
+
{"name": "Lin", "score": 5}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
the command prints `{"records": 2}`. Use the Python API to process values:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from causality_protocol import iter_jsonl
|
|
24
|
+
|
|
25
|
+
for value in iter_jsonl("records.jsonl"):
|
|
26
|
+
print(value)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Blank lines are skipped. Any JSON value is accepted, including objects, arrays,
|
|
30
|
+
numbers, strings, booleans and null. Malformed records raise ValueError with the
|
|
31
|
+
file path and physical line number. Non-standard NaN and Infinity literals are
|
|
32
|
+
rejected. Values use Python's normal JSON decoding, including floating-point
|
|
33
|
+
numbers; this is not an arbitrary-precision decoder. The file is read lazily,
|
|
34
|
+
with memory proportional to the largest line. Filesystem and decoding errors
|
|
35
|
+
propagate to Python callers; the command prints errors on stderr and exits 2.
|
|
36
|
+
|
|
37
|
+
`python -m causality_protocol` is also supported. The API may change during alpha
|
|
38
|
+
development. Licensed under MIT; see LICENSE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "causality-protocol"
|
|
7
|
+
version = "0.1.0a1"
|
|
8
|
+
description = "Streaming JSON Lines reader and record counter"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
causality-protocol = "causality_protocol:main"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools]
|
|
23
|
+
py-modules = ["causality_protocol"]
|
|
24
|
+
package-dir = {"" = "src"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: causality-protocol
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: Streaming JSON Lines reader and record counter
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# causality-protocol
|
|
15
|
+
|
|
16
|
+
Version 0.1.0a1 is a standalone streaming JSON Lines reader and record counter.
|
|
17
|
+
It reads ordinary JSON values without imposing a schema. This alpha does not
|
|
18
|
+
implement learning, a memory protocol, or a model. Python 3.11 or later; no
|
|
19
|
+
third-party dependencies.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
python -m pip install causality-protocol==0.1.0a1
|
|
23
|
+
causality-protocol records.jsonl
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For a UTF-8 file containing:
|
|
27
|
+
|
|
28
|
+
```jsonl
|
|
29
|
+
{"name": "Ada", "score": 3}
|
|
30
|
+
{"name": "Lin", "score": 5}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
the command prints `{"records": 2}`. Use the Python API to process values:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from causality_protocol import iter_jsonl
|
|
37
|
+
|
|
38
|
+
for value in iter_jsonl("records.jsonl"):
|
|
39
|
+
print(value)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Blank lines are skipped. Any JSON value is accepted, including objects, arrays,
|
|
43
|
+
numbers, strings, booleans and null. Malformed records raise ValueError with the
|
|
44
|
+
file path and physical line number. Non-standard NaN and Infinity literals are
|
|
45
|
+
rejected. Values use Python's normal JSON decoding, including floating-point
|
|
46
|
+
numbers; this is not an arbitrary-precision decoder. The file is read lazily,
|
|
47
|
+
with memory proportional to the largest line. Filesystem and decoding errors
|
|
48
|
+
propagate to Python callers; the command prints errors on stderr and exits 2.
|
|
49
|
+
|
|
50
|
+
`python -m causality_protocol` is also supported. The API may change during alpha
|
|
51
|
+
development. Licensed under MIT; see LICENSE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/causality_protocol.py
|
|
5
|
+
src/causality_protocol.egg-info/PKG-INFO
|
|
6
|
+
src/causality_protocol.egg-info/SOURCES.txt
|
|
7
|
+
src/causality_protocol.egg-info/dependency_links.txt
|
|
8
|
+
src/causality_protocol.egg-info/entry_points.txt
|
|
9
|
+
src/causality_protocol.egg-info/top_level.txt
|
|
10
|
+
tests/test_jsonl.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
causality_protocol
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Read ordinary UTF-8 JSON Lines files one record at a time."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _reject_constant(value: str) -> None:
|
|
9
|
+
raise ValueError(f"non-standard JSON number: {value}")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def iter_jsonl(path: str | Path):
|
|
13
|
+
"""Yield JSON values, skipping blank lines and reporting malformed line numbers.
|
|
14
|
+
|
|
15
|
+
Memory use is proportional to the largest line, not the total file size.
|
|
16
|
+
NaN and Infinity are rejected because they are not standard JSON numbers.
|
|
17
|
+
"""
|
|
18
|
+
with open(path, encoding="utf-8") as stream:
|
|
19
|
+
for number, line in enumerate(stream, 1):
|
|
20
|
+
if not line.strip():
|
|
21
|
+
continue
|
|
22
|
+
try:
|
|
23
|
+
yield json.loads(line, parse_constant=_reject_constant)
|
|
24
|
+
except ValueError as error:
|
|
25
|
+
raise ValueError(f"{path}:{number}: {error}") from error
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main() -> None:
|
|
29
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
30
|
+
parser.add_argument("path", help="UTF-8 JSON Lines file to validate and count")
|
|
31
|
+
args = parser.parse_args()
|
|
32
|
+
try:
|
|
33
|
+
count = sum(1 for _ in iter_jsonl(args.path))
|
|
34
|
+
print(json.dumps({"records": count}))
|
|
35
|
+
except (OSError, ValueError) as error:
|
|
36
|
+
parser.error(str(error))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
from causality_protocol import iter_jsonl
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class JsonLinesTests(unittest.TestCase):
|
|
12
|
+
def test_values_blanks_and_cli(self):
|
|
13
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
14
|
+
path = Path(directory) / "records.jsonl"
|
|
15
|
+
path.write_text('\n{"name":"猫"}\n\n[1,2]\nnull\ntrue\n', encoding="utf-8")
|
|
16
|
+
self.assertEqual(list(iter_jsonl(path)), [{"name": "猫"}, [1, 2], None, True])
|
|
17
|
+
result = subprocess.run([sys.executable, "-m", "causality_protocol", str(path)],
|
|
18
|
+
text=True, capture_output=True)
|
|
19
|
+
self.assertEqual(result.returncode, 0, result.stderr)
|
|
20
|
+
self.assertEqual(json.loads(result.stdout), {"records": 4})
|
|
21
|
+
path.write_text("")
|
|
22
|
+
self.assertEqual(list(iter_jsonl(path)), [])
|
|
23
|
+
|
|
24
|
+
def test_lazy_line_errors_and_constants(self):
|
|
25
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
26
|
+
path = Path(directory) / "records.jsonl"
|
|
27
|
+
for invalid in ("{bad}", "NaN", "Infinity", "-Infinity"):
|
|
28
|
+
path.write_text('1\n\n' + invalid + '\n', encoding="utf-8")
|
|
29
|
+
values = iter_jsonl(path)
|
|
30
|
+
self.assertEqual(next(values), 1)
|
|
31
|
+
with self.assertRaisesRegex(ValueError, ":3:"):
|
|
32
|
+
next(values)
|
|
33
|
+
result = subprocess.run([sys.executable, "-m", "causality_protocol", str(path)],
|
|
34
|
+
text=True, capture_output=True)
|
|
35
|
+
self.assertEqual(result.returncode, 2)
|
|
36
|
+
self.assertIn(":3:", result.stderr)
|
|
37
|
+
self.assertNotIn("Traceback", result.stderr)
|