dataclass-native 1.0.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.
Files changed (99) hide show
  1. dataclass_native-1.0.0/.github/workflows/ci.yml +29 -0
  2. dataclass_native-1.0.0/.github/workflows/release.yml +20 -0
  3. dataclass_native-1.0.0/.gitignore +174 -0
  4. dataclass_native-1.0.0/.pre-commit-config.yaml +17 -0
  5. dataclass_native-1.0.0/ARROW_FORMAT.md +128 -0
  6. dataclass_native-1.0.0/DESIGN.md +371 -0
  7. dataclass_native-1.0.0/JSON_FORMAT.md +112 -0
  8. dataclass_native-1.0.0/LICENSE +21 -0
  9. dataclass_native-1.0.0/PKG-INFO +339 -0
  10. dataclass_native-1.0.0/README.md +294 -0
  11. dataclass_native-1.0.0/WIRE_FORMAT.md +117 -0
  12. dataclass_native-1.0.0/examples/README.md +45 -0
  13. dataclass_native-1.0.0/examples/functions/CMakeLists.txt +24 -0
  14. dataclass_native-1.0.0/examples/functions/cpp/bindings.cpp +12 -0
  15. dataclass_native-1.0.0/examples/functions/cpp/pricing.hpp +26 -0
  16. dataclass_native-1.0.0/examples/functions/demo.py +22 -0
  17. dataclass_native-1.0.0/examples/functions/pyproject.toml +14 -0
  18. dataclass_native-1.0.0/examples/functions/src/shop/__init__.py +0 -0
  19. dataclass_native-1.0.0/examples/functions/src/shop/model.py +48 -0
  20. dataclass_native-1.0.0/examples/functions/src/shop/pricing.py +18 -0
  21. dataclass_native-1.0.0/examples/parquet/CMakeLists.txt +23 -0
  22. dataclass_native-1.0.0/examples/parquet/main.cpp +42 -0
  23. dataclass_native-1.0.0/examples/parquet/parquet.hpp +120 -0
  24. dataclass_native-1.0.0/examples/parquet/read.py +11 -0
  25. dataclass_native-1.0.0/examples/parquet/src/shop/__init__.py +0 -0
  26. dataclass_native-1.0.0/examples/parquet/src/shop/model.py +48 -0
  27. dataclass_native-1.0.0/examples/quickstart/CMakeLists.txt +17 -0
  28. dataclass_native-1.0.0/examples/quickstart/demo.py +25 -0
  29. dataclass_native-1.0.0/examples/quickstart/pyproject.toml +14 -0
  30. dataclass_native-1.0.0/examples/quickstart/src/shop/__init__.py +0 -0
  31. dataclass_native-1.0.0/examples/quickstart/src/shop/model.py +48 -0
  32. dataclass_native-1.0.0/examples/ruff.toml +2 -0
  33. dataclass_native-1.0.0/pyproject.toml +97 -0
  34. dataclass_native-1.0.0/setup.cfg +4 -0
  35. dataclass_native-1.0.0/src/dataclass_native/__init__.py +60 -0
  36. dataclass_native-1.0.0/src/dataclass_native/__main__.py +5 -0
  37. dataclass_native-1.0.0/src/dataclass_native/_arrow.py +822 -0
  38. dataclass_native-1.0.0/src/dataclass_native/_json.py +783 -0
  39. dataclass_native-1.0.0/src/dataclass_native/_mode.py +57 -0
  40. dataclass_native-1.0.0/src/dataclass_native/_msgpack.py +207 -0
  41. dataclass_native-1.0.0/src/dataclass_native/_native.py +234 -0
  42. dataclass_native-1.0.0/src/dataclass_native/_runtime.py +607 -0
  43. dataclass_native-1.0.0/src/dataclass_native/_version.py +24 -0
  44. dataclass_native-1.0.0/src/dataclass_native/_wire.py +901 -0
  45. dataclass_native-1.0.0/src/dataclass_native/arrays.py +13 -0
  46. dataclass_native-1.0.0/src/dataclass_native/backends/__init__.py +0 -0
  47. dataclass_native-1.0.0/src/dataclass_native/backends/bindings.py +74 -0
  48. dataclass_native-1.0.0/src/dataclass_native/backends/cpp.py +574 -0
  49. dataclass_native-1.0.0/src/dataclass_native/backends/templates/bindings.cpp.j2 +58 -0
  50. dataclass_native-1.0.0/src/dataclass_native/backends/templates/extensions.cmake.j2 +12 -0
  51. dataclass_native-1.0.0/src/dataclass_native/backends/templates/header.hpp.j2 +75 -0
  52. dataclass_native-1.0.0/src/dataclass_native/cli.py +125 -0
  53. dataclass_native-1.0.0/src/dataclass_native/cmake/dataclass_native-config.cmake +67 -0
  54. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/arrow.hpp +2022 -0
  55. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/json.hpp +1903 -0
  56. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/msgpack.hpp +1513 -0
  57. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/python.hpp +594 -0
  58. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/reflect.hpp +63 -0
  59. dataclass_native-1.0.0/src/dataclass_native/include/dataclass_native/types.hpp +417 -0
  60. dataclass_native-1.0.0/src/dataclass_native/introspect.py +811 -0
  61. dataclass_native-1.0.0/src/dataclass_native/py.typed +0 -0
  62. dataclass_native-1.0.0/src/dataclass_native/schema.py +553 -0
  63. dataclass_native-1.0.0/src/dataclass_native/types.py +103 -0
  64. dataclass_native-1.0.0/src/dataclass_native.egg-info/PKG-INFO +339 -0
  65. dataclass_native-1.0.0/src/dataclass_native.egg-info/SOURCES.txt +97 -0
  66. dataclass_native-1.0.0/src/dataclass_native.egg-info/dependency_links.txt +1 -0
  67. dataclass_native-1.0.0/src/dataclass_native.egg-info/entry_points.txt +2 -0
  68. dataclass_native-1.0.0/src/dataclass_native.egg-info/requires.txt +10 -0
  69. dataclass_native-1.0.0/src/dataclass_native.egg-info/scm_file_list.json +92 -0
  70. dataclass_native-1.0.0/src/dataclass_native.egg-info/scm_version.json +8 -0
  71. dataclass_native-1.0.0/src/dataclass_native.egg-info/top_level.txt +1 -0
  72. dataclass_native-1.0.0/tests/cmake/CMakeLists.txt +29 -0
  73. dataclass_native-1.0.0/tests/conftest.py +33 -0
  74. dataclass_native-1.0.0/tests/cpp/functions.cpp +58 -0
  75. dataclass_native-1.0.0/tests/schemas/__init__.py +1 -0
  76. dataclass_native-1.0.0/tests/schemas/arrays.py +40 -0
  77. dataclass_native-1.0.0/tests/schemas/common.py +37 -0
  78. dataclass_native-1.0.0/tests/schemas/functions.py +67 -0
  79. dataclass_native-1.0.0/tests/schemas/kinds.py +60 -0
  80. dataclass_native-1.0.0/tests/schemas/mutable.py +76 -0
  81. dataclass_native-1.0.0/tests/schemas/scalars.py +110 -0
  82. dataclass_native-1.0.0/tests/schemas/sub/__init__.py +0 -0
  83. dataclass_native-1.0.0/tests/schemas/sub/inner.py +14 -0
  84. dataclass_native-1.0.0/tests/schemas/trades.py +44 -0
  85. dataclass_native-1.0.0/tests/schemas/tree.py +32 -0
  86. dataclass_native-1.0.0/tests/schemas/validated.py +32 -0
  87. dataclass_native-1.0.0/tests/test_arrays.py +477 -0
  88. dataclass_native-1.0.0/tests/test_arrow.py +477 -0
  89. dataclass_native-1.0.0/tests/test_bindings.py +386 -0
  90. dataclass_native-1.0.0/tests/test_cpp.py +936 -0
  91. dataclass_native-1.0.0/tests/test_examples.py +138 -0
  92. dataclass_native-1.0.0/tests/test_introspect.py +431 -0
  93. dataclass_native-1.0.0/tests/test_json.py +892 -0
  94. dataclass_native-1.0.0/tests/test_mode.py +167 -0
  95. dataclass_native-1.0.0/tests/test_msgpack.py +536 -0
  96. dataclass_native-1.0.0/tests/test_mutable.py +290 -0
  97. dataclass_native-1.0.0/tests/test_runtime.py +493 -0
  98. dataclass_native-1.0.0/tests/test_scalars.py +476 -0
  99. dataclass_native-1.0.0/uv.lock +881 -0
@@ -0,0 +1,29 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ # Each OS and version runs to completion, though another fails
13
+ fail-fast: false
14
+ matrix:
15
+ os: [ubuntu-latest, macos-latest, windows-latest]
16
+ python-version: ["3.13", "3.14"]
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ with:
20
+ # setuptools-scm derives the version from the tags
21
+ fetch-depth: 0
22
+ - uses: astral-sh/setup-uv@v6
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+ - run: uv sync --locked
26
+ # ruff and pyright, as when committing
27
+ - run: uv run pre-commit run --all-files --show-diff-on-failure
28
+ # Builds the extensions of tests/schemas, and the examples, with the runner's C++ compiler
29
+ - run: uv run pytest --cov
@@ -0,0 +1,20 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ with:
16
+ # setuptools-scm derives the version from the tags
17
+ fetch-depth: 0
18
+ - uses: astral-sh/setup-uv@v6
19
+ - run: uv build
20
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,174 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ .idea/
163
+
164
+ # VS Code: its settings hold paths of this machine
165
+ .vscode/
166
+
167
+ # setuptools-scm
168
+ src/dataclass_native/_version.py
169
+
170
+ # Generated C++ in tests and builds
171
+ generated/
172
+
173
+ # The examples are built with this repository's dataclass-native, so are not locked
174
+ examples/*/uv.lock
@@ -0,0 +1,17 @@
1
+ repos:
2
+ # Keep rev in line with ruff's version in uv.lock, so that both apply the same rules
3
+ - repo: https://github.com/astral-sh/ruff-pre-commit
4
+ rev: v0.17.5
5
+ hooks:
6
+ - id: ruff-check
7
+ args: [--fix]
8
+ - id: ruff-format
9
+ # The project's own pyright and environment, from uv.lock
10
+ - repo: local
11
+ hooks:
12
+ - id: pyright
13
+ name: pyright
14
+ entry: uv run pyright
15
+ language: system
16
+ types_or: [python, pyi]
17
+ pass_filenames: false
@@ -0,0 +1,128 @@
1
+ # dataclass-native: Arrow and Parquet layout
2
+
3
+ How objects of a `@native` class are held in [Arrow](https://arrow.apache.org/docs/format/Columnar.html) tables,
4
+ and in the Parquet files of those tables. There are two implementations, in Python and in C++. The Python one
5
+ is the reference: where this document and it disagree, one of them has a bug.
6
+
7
+ The objects of a class are a table: a row for each object, and a column for each field. A reader is given the class
8
+ it is to read.
9
+
10
+ ## Types
11
+
12
+ | Type | Arrow type |
13
+ |---|---|
14
+ | `bool` | `bool` |
15
+ | `int`, and the sized ints | `int64`, and `int8` ... `uint64` |
16
+ | `float`, `Float32` | `float64`, `float32` |
17
+ | `str` | `string` |
18
+ | `bytes`, `tuple[UInt8, ...]` | `binary` |
19
+ | `datetime.date` | `date32` |
20
+ | `datetime.time` | `time64[us]` |
21
+ | `datetime.datetime` | `timestamp[us, UTC]` |
22
+ | `NaiveDatetime` | `timestamp[us]`, of no timezone |
23
+ | `datetime.timedelta` | `duration[us]` |
24
+ | `uuid.UUID` | `arrow.uuid`, which is stored as `fixed_size_binary[16]` |
25
+ | `Decimal` | `decimal128(18, places)` |
26
+ | an enum | `dictionary<int32, string>`: the member's name |
27
+ | `X \| None` | as `X`, null for `None` |
28
+ | `tuple[X, ...]` | `list<X>` |
29
+ | a numpy array of numbers, of one dimension | as the `tuple` of its numbers: `list<X>`, or `binary` if they are `uint8` |
30
+ | one of more dimensions | `struct<data, shape: fixed_size_list<int32>[N]>`: `data` is its numbers as those of one dimension are, the last dimension varying fastest. As `arrow.variable_shape_tensor` is stored |
31
+ | `frozenset[K]` | `list<K>`, in ascending order |
32
+ | `tuple[A, B]` | `struct<0: A, 1: B>` |
33
+ | `Mapping[K, V]` | `map<K, V>`, in ascending order of key |
34
+ | a `@native` class | `struct`, of a field for each of its fields |
35
+ | `A \| B`, `DiscriminatedUnion[A, B]` | `struct`, of a field for each member: see [Unions](#unions) |
36
+ | `Shared[A]` | `uint32`: see [Shared objects](#shared-objects) |
37
+
38
+ Details:
39
+
40
+ - **Null.** No field is declared as not null. A value is null only where its type has `None`, and a reader rejects
41
+ a null elsewhere.
42
+ - **Order** of a set's elements and a map's keys is as in [WIRE_FORMAT.md](WIRE_FORMAT.md): enums by the value of
43
+ their members, not by name.
44
+ - **Enums.** Which names an enum's dictionary holds, and in what order, is not specified: only the name each value
45
+ refers to.
46
+ - **Metadata.** A table's schema has `dataclass_native:tag`, the tag of the class its rows are of.
47
+ - **A class which holds itself**, such as a tree whose nodes hold nodes, cannot be written: an Arrow type cannot
48
+ contain itself. A class may hold its own class through a `Shared` field.
49
+
50
+ ## Unions
51
+
52
+ A union is a struct with a field for each of its members, exactly one of which is not null. Where the union's
53
+ type has `None`, the struct itself is null for `None`.
54
+
55
+ Arrow has a union type, but Parquet has not, and few tools read Arrow's. A struct is read by all of them.
56
+
57
+ A member's field is named by its tag, as in a discriminated union when written as msgpack: for a class its tag,
58
+ for an enum `module.QualName`, and for the rest `bool`, `int`, `int8` ... `uint64`, `float`, `float32`, `str`,
59
+ `bytes`, `date`, `time`, `datetime`, `naivedatetime`, `timedelta`, `uuid` and `decimal`. A member which has no tag, as it is not allowed in a
60
+ discriminated union, is named `array` if it is a tuple or a frozenset, `map` if a `Mapping`, and `bytes` if a
61
+ `tuple[UInt8, ...]`, which is held as `bytes` is.
62
+
63
+ A plain union and a discriminated union are held alike: the field which is not null says which member it is.
64
+
65
+ ## Shared objects
66
+
67
+ Besides the table of the objects themselves, the **root**, there is a table for each class which they may share,
68
+ however deeply. Which classes those are is known from the schema, so each has a table even when it has no rows.
69
+
70
+ - A `Shared[A]` field is the row, in the table of `A`, of the object it shares. Its field has the metadata
71
+ `dataclass_native:shared`, which is the tag of `A`.
72
+ - An object is a row once however many fields share it, across all the rows of the root. Objects are the same by
73
+ identity, not by value. Reading gives back one object for each row, so what was shared still is.
74
+ - A shared object's own `Shared` fields are rows too, of any of the tables, its own included.
75
+ - A root object is not a row of its class's shared table, even if that class is shared elsewhere: the root is a
76
+ table of its own.
77
+ - `Shared[A | B]` is a union as any other: a struct of a row in the table of `A` and one in the table of `B`, of
78
+ which one is not null.
79
+ - Rows are in the order in which their objects are first met, in writing the root: row by row, fields in order, a
80
+ shared object's own fields when it is first met.
81
+
82
+ This is how a database holds them: a shared object is a row of its own table, and a field which shares it is a
83
+ foreign key.
84
+
85
+ In Python the tables are an `ArrowTables`: `root`, and `shared`, the other tables by tag.
86
+
87
+ ## Parquet
88
+
89
+ Each table is a file, written by pyarrow, in one directory:
90
+
91
+ ```
92
+ trades/
93
+ root.parquet
94
+ shared/
95
+ party.v1.parquet
96
+ schemas.common.Fund.parquet
97
+ ```
98
+
99
+ A shared table's file is named by its tag, percent-encoded but for letters, digits and `-._~`.
100
+
101
+ A class with no fields cannot be written as Parquet, where it is a field of another: Parquet has no struct without
102
+ fields.
103
+
104
+ ## Reading
105
+
106
+ - A field which has no column takes its default. If it has none, the table is rejected.
107
+ - A column which is not a field is ignored, and columns may be in any order. The same holds for the fields of a
108
+ struct.
109
+ - An enum's names may be in a dictionary or not, and a string or binary may be of the large kind.
110
+ - A reference to a table or a row which is not there is rejected, as is an object which refers to itself, directly
111
+ or through others.
112
+
113
+ ## In C++
114
+
115
+ `dataclass_native/arrow.hpp` builds and reads the tables as the
116
+ [Arrow C data interface](https://arrow.apache.org/docs/format/CDataInterface.html) has them, which any Arrow
117
+ library imports and exports without copying. It needs no Arrow library itself.
118
+
119
+ - What it builds is as above, with every member's name in an enum's dictionary, in the order of the members.
120
+ - It reads the layout above, with columns in any order, missing or added. It does not read the variations which
121
+ the Python implementation allows, such as an enum's names which are not in a dictionary of `int32`, or a large
122
+ list: from Python, such tables are read by the Python implementation instead.
123
+ - It does not check that the tables it is given are valid Arrow.
124
+
125
+ ## Not decided
126
+
127
+ - Holding a class which holds itself, as rows which refer to rows of its own table.
128
+ - Writing a table in batches, and appending to Parquet files.