transit-python 0.8.302__tar.gz → 0.8.321__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.
- transit_python-0.8.321/LICENSE +202 -0
- transit_python-0.8.321/MANIFEST.in +1 -0
- transit_python-0.8.321/PKG-INFO +302 -0
- transit_python-0.8.321/README.md +274 -0
- transit_python-0.8.321/csrc/transit.h +191 -0
- transit_python-0.8.321/csrc/transit_c_version.h +3 -0
- transit_python-0.8.321/csrc/transit_internal.h +109 -0
- transit_python-0.8.321/csrc/transit_json.c +317 -0
- transit_python-0.8.321/csrc/transit_msgpack.c +213 -0
- transit_python-0.8.321/csrc/transit_read.c +564 -0
- transit_python-0.8.321/csrc/transit_util.c +420 -0
- transit_python-0.8.321/csrc/transit_value.c +264 -0
- transit_python-0.8.321/csrc/transit_write.c +408 -0
- transit_python-0.8.321/pyproject.toml +74 -0
- transit_python-0.8.321/setup.cfg +4 -0
- transit_python-0.8.321/setup.py +42 -0
- {transit-python-0.8.302/tests → transit_python-0.8.321/transit}/__init__.py +3 -0
- transit_python-0.8.321/transit/_accel.py +27 -0
- transit_python-0.8.321/transit/_native.c +631 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/class_hash.py +3 -4
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/decoder.py +22 -23
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/helpers.py +13 -3
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/read_handlers.py +66 -45
- transit_python-0.8.321/transit/reader.py +137 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/rolling_cache.py +32 -20
- transit_python-0.8.321/transit/sosjson.py +129 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/transit_types.py +18 -23
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/write_handlers.py +45 -59
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/writer.py +86 -64
- transit_python-0.8.321/transit_python.egg-info/PKG-INFO +302 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit_python.egg-info/SOURCES.txt +14 -7
- transit_python-0.8.321/transit_python.egg-info/requires.txt +7 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit_python.egg-info/top_level.txt +0 -1
- transit-python-0.8.302/PKG-INFO +0 -10
- transit-python-0.8.302/README.md +0 -217
- transit-python-0.8.302/setup.cfg +0 -8
- transit-python-0.8.302/setup.py +0 -27
- transit-python-0.8.302/tests/exemplars_test.py +0 -242
- transit-python-0.8.302/tests/helpers.py +0 -33
- transit-python-0.8.302/tests/regression.py +0 -163
- transit-python-0.8.302/tests/seattle_benchmark.py +0 -53
- transit-python-0.8.302/transit/__init__.py +0 -13
- transit-python-0.8.302/transit/pyversion.py +0 -53
- transit-python-0.8.302/transit/reader.py +0 -92
- transit-python-0.8.302/transit/sosjson.py +0 -77
- transit-python-0.8.302/transit_python.egg-info/PKG-INFO +0 -10
- transit-python-0.8.302/transit_python.egg-info/requires.txt +0 -2
- {transit-python-0.8.302 → transit_python-0.8.321}/transit/constants.py +0 -0
- {transit-python-0.8.302 → transit_python-0.8.321}/transit_python.egg-info/dependency_links.txt +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include csrc/*.c csrc/*.h transit/_native.c
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: transit-python
|
|
3
|
+
Version: 0.8.321
|
|
4
|
+
Summary: Transit marshalling for Python
|
|
5
|
+
Author: Cognitect
|
|
6
|
+
Maintainer: Vendekagon Labs LLC
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/vendekagon-labs/transit-python
|
|
9
|
+
Project-URL: Issues, https://github.com/vendekagon-labs/transit-python/issues
|
|
10
|
+
Project-URL: Specification, https://github.com/cognitect/transit-format
|
|
11
|
+
Project-URL: Original, https://github.com/cognitect/transit-python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: msgpack
|
|
23
|
+
Requires-Dist: msgpack>=1.0; extra == "msgpack"
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest; extra == "test"
|
|
26
|
+
Requires-Dist: msgpack>=1.0; extra == "test"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
transit-python
|
|
30
|
+
==============
|
|
31
|
+
|
|
32
|
+
Transit is a format and set of libraries for conveying values between
|
|
33
|
+
applications written in different programming languages. The library provides
|
|
34
|
+
support for marshalling data to/from Python.
|
|
35
|
+
|
|
36
|
+
transit-python is maintained by [Vendekagon Labs](https://github.com/vendekagon-labs),
|
|
37
|
+
which has taken it over as the successor to Cognitect's original
|
|
38
|
+
[cognitect/transit-python](https://github.com/cognitect/transit-python),
|
|
39
|
+
bringing it up to date: Python 3.10 and later, all three transit encodings,
|
|
40
|
+
and a native extension for speed. It continues the same PyPI package,
|
|
41
|
+
[`transit-python`](https://pypi.org/project/transit-python/).
|
|
42
|
+
|
|
43
|
+
* [Rationale](http://blog.cognitect.com/blog/2014/7/22/transit)
|
|
44
|
+
* [Specification](http://github.com/cognitect/transit-format)
|
|
45
|
+
|
|
46
|
+
This implementation's major.minor version number corresponds to the
|
|
47
|
+
version of the Transit specification it supports.
|
|
48
|
+
|
|
49
|
+
_NOTE: Transit is intended primarily as a wire protocol for transferring data between applications. If storing Transit data durably, readers and writers are expected to use the same version of Transit and you are responsible for migrating/transforming/re-storing that data when and if the transit format changes._
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pip install transit-python # JSON and JSON-verbose
|
|
55
|
+
pip install 'transit-python[msgpack]' # also msgpack, when running as pure Python
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
transit-python releases up to 0.8.302 support Python 2.7 and 3.5; later
|
|
59
|
+
releases, from this repository, support Python 3.10 and later.
|
|
60
|
+
|
|
61
|
+
The package includes a native extension, built from
|
|
62
|
+
[transit-c](https://github.com/vendekagon-labs/transit-c), that reads and
|
|
63
|
+
writes transit 4-15 times faster than pure Python, with identical results.
|
|
64
|
+
PyPI has wheels with it compiled for Linux, macOS and Windows (x86_64 and
|
|
65
|
+
ARM); elsewhere pip builds it from the source distribution if there's a C
|
|
66
|
+
compiler, and otherwise installs the package as pure Python. Set
|
|
67
|
+
`TRANSIT_PUREPYTHON=1` to use pure Python regardless (or, when installing
|
|
68
|
+
from source, to not build the extension).
|
|
69
|
+
|
|
70
|
+
The native extension reads and writes msgpack itself. Pure Python needs the
|
|
71
|
+
[msgpack](https://pypi.org/project/msgpack/) package for that, installed
|
|
72
|
+
with the `msgpack` extra; without it, creating a msgpack `Reader` or `Writer`
|
|
73
|
+
raises an `ImportError` saying so.
|
|
74
|
+
|
|
75
|
+
To install from GitHub:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
pip install "transit-python[msgpack] @ git+https://github.com/vendekagon-labs/transit-python.git"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
(add `@<tag or commit>` to the URL to pin a version, or use
|
|
82
|
+
`git+ssh://git@github.com/...` to install over SSH). In a `pyproject.toml` or
|
|
83
|
+
`requirements.txt`, use the same `transit-python @ git+https://...` form.
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# io can be any Python file descriptor,
|
|
89
|
+
# like you would typically use with JSON's load/dump
|
|
90
|
+
|
|
91
|
+
from transit.writer import Writer
|
|
92
|
+
from transit.reader import Reader
|
|
93
|
+
|
|
94
|
+
writer = Writer(io, "json") # or "json-verbose", "msgpack"
|
|
95
|
+
writer.write(value)
|
|
96
|
+
|
|
97
|
+
reader = Reader("json") # or "msgpack"
|
|
98
|
+
val = reader.read(io)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
For example:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
>>> from transit.writer import Writer
|
|
105
|
+
>>> from transit.reader import Reader
|
|
106
|
+
>>> from io import StringIO
|
|
107
|
+
>>> io = StringIO()
|
|
108
|
+
>>> writer = Writer(io, "json")
|
|
109
|
+
>>> writer.write(["abc", 1234567890])
|
|
110
|
+
>>> s = io.getvalue()
|
|
111
|
+
>>> reader = Reader()
|
|
112
|
+
>>> vals = reader.read(StringIO(s))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
To read a sequence of values as they arrive (e.g. from a pipe or socket),
|
|
117
|
+
use `readeach`, which yields each value as soon as it has been read and stops
|
|
118
|
+
at the end of the stream. A `Writer` can likewise write any number of values.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
reader = Reader("json")
|
|
122
|
+
for value in reader.readeach(sys.stdin.buffer):
|
|
123
|
+
writer.write(value)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
## Supported Python versions
|
|
128
|
+
|
|
129
|
+
* 3.10 and later
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Type Mapping
|
|
133
|
+
|
|
134
|
+
### Typed arrays, lists, and chars
|
|
135
|
+
|
|
136
|
+
The [transit spec](https://github.com/cognitect/transit-format)
|
|
137
|
+
defines several semantic types that map to more general types in Python:
|
|
138
|
+
|
|
139
|
+
* lists map to Python Tuples
|
|
140
|
+
* typed arrays (ints, longs, doubles, floats, bools), chars and bytes are
|
|
141
|
+
read as TaggedValues (e.g. `TaggedValue("ints", (1, 2, 3))`), so they
|
|
142
|
+
are written back out unchanged
|
|
143
|
+
|
|
144
|
+
Use a TaggedValue to write these out if it will benefit a consuming
|
|
145
|
+
app e.g.:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
writer.write(TaggedValue("ints", [1,2,3]))
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Python's bool and int
|
|
152
|
+
|
|
153
|
+
In Python, bools are subclasses of int (that is, `True` is actually `1`).
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
>>> hash(1)
|
|
157
|
+
1
|
|
158
|
+
>>> hash(True)
|
|
159
|
+
1
|
|
160
|
+
>>> True == 1
|
|
161
|
+
True
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
This becomes problematic when decoding a map that contains bool and
|
|
165
|
+
int keys. The bool keys may be overridden (ie: you'll only see the int key),
|
|
166
|
+
and the value will be one of any possible bool/int keyed value.
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
>>> {1: "Hello", True: "World"}
|
|
170
|
+
{1: 'World'}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
To counter this problem, the latest version of Transit Python introduces a
|
|
174
|
+
Boolean type with singleton (by convention of use) instances of "true" and
|
|
175
|
+
"false." A Boolean can be converted to a native Python bool with bool(x) where
|
|
176
|
+
x is the "true" or "false" instance. Logical evaluation works correctly with
|
|
177
|
+
Booleans (that is, they override the __bool__ method and correctly evaluate
|
|
178
|
+
as true and false in simple logical evaluation), but uses of a Boolean as an
|
|
179
|
+
integer will fail.
|
|
180
|
+
|
|
181
|
+
### Default type mapping
|
|
182
|
+
|
|
183
|
+
|Transit type|Write accepts|Read returns|
|
|
184
|
+
|------------|-------------|------------|
|
|
185
|
+
|null|None|None|
|
|
186
|
+
|string|str|str|
|
|
187
|
+
|boolean|bool, transit\_types.Boolean|transit\_types.true, transit\_types.false|
|
|
188
|
+
|integer|int|int|
|
|
189
|
+
|decimal|float|float|
|
|
190
|
+
|keyword|transit\_types.Keyword|transit\_types.Keyword|
|
|
191
|
+
|symbol|transit\_types.Symbol|transit\_types.Symbol|
|
|
192
|
+
|big decimal|decimal.Decimal|decimal.Decimal|
|
|
193
|
+
|big integer|int|int|
|
|
194
|
+
|time|datetime (timezone aware)|datetime (UTC)|
|
|
195
|
+
|uri|transit\_types.URI|transit\_types.URI|
|
|
196
|
+
|uuid|uuid.UUID|uuid.UUID|
|
|
197
|
+
|char|transit\_types.TaggedValue|transit\_types.TaggedValue|
|
|
198
|
+
|array|list, tuple|tuple|
|
|
199
|
+
|list|transit\_types.TaggedValue|tuple|
|
|
200
|
+
|set|set, frozenset|frozenset|
|
|
201
|
+
|map|dict, transit\_types.frozendict|transit\_types.frozendict|
|
|
202
|
+
|bytes|transit\_types.TaggedValue|transit\_types.TaggedValue|
|
|
203
|
+
|shorts, ints, longs, floats, doubles, chars, bools|transit\_types.TaggedValue|transit\_types.TaggedValue|
|
|
204
|
+
|link|transit\_types.Link|transit\_types.Link|
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## Development
|
|
208
|
+
|
|
209
|
+
### Setup
|
|
210
|
+
|
|
211
|
+
The tests read the exemplar files from
|
|
212
|
+
[transit-format](http://github.com/cognitect/transit-format), which is
|
|
213
|
+
expected to be checked out next to transit-python (or inside it, or set
|
|
214
|
+
`TRANSIT_FORMAT_DIR` to its location).
|
|
215
|
+
|
|
216
|
+
```sh
|
|
217
|
+
pip install -e '.[test]'
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The `test` extra includes msgpack. The msgpack tests are skipped when it
|
|
221
|
+
isn't installed, so run the tests both with and without it.
|
|
222
|
+
|
|
223
|
+
### Running the tests
|
|
224
|
+
|
|
225
|
+
```sh
|
|
226
|
+
pytest
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Running the transit-format verify harness
|
|
230
|
+
|
|
231
|
+
transit-format's `bin/verify` drives `bin/roundtrip`, which runs with the
|
|
232
|
+
`python3` on your `PATH`, so activate an environment with transit-python's
|
|
233
|
+
dependencies installed first.
|
|
234
|
+
|
|
235
|
+
```sh
|
|
236
|
+
cd ../transit-format
|
|
237
|
+
bin/verify -impls python
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Benchmarks
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
python -m tests.seattle_benchmark
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### The native extension
|
|
247
|
+
|
|
248
|
+
`transit/_native.c` wraps transit-c, whose sources are in `csrc/`, copied
|
|
249
|
+
from [transit-c](https://github.com/vendekagon-labs/transit-c) by
|
|
250
|
+
`bin/sync-transit-c` (which records the commit in `csrc/transit_c_version.h`);
|
|
251
|
+
change them there, not here. `pip install -e .` builds the extension in place.
|
|
252
|
+
The tests check that native and pure Python read and write identically;
|
|
253
|
+
run them both ways (`TRANSIT_PUREPYTHON=1 pytest` for pure Python).
|
|
254
|
+
|
|
255
|
+
`bin/verify` runs transit-format's verify harness in each encoding, with the
|
|
256
|
+
[clojure CLI](https://clojure.org/guides/install_clojure), and fails if any
|
|
257
|
+
roundtrip does.
|
|
258
|
+
|
|
259
|
+
### Releasing
|
|
260
|
+
|
|
261
|
+
The version is 0.8.<number of commits>. To release:
|
|
262
|
+
|
|
263
|
+
```sh
|
|
264
|
+
bin/make-release # stamps the version into transit/__init__.py
|
|
265
|
+
git commit -am "Release 0.8.N"
|
|
266
|
+
git tag v0.8.N
|
|
267
|
+
git push origin main v0.8.N
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Pushing the tag runs `.github/workflows/wheels.yml`, which tests, builds the
|
|
271
|
+
sdist and wheels (with [cibuildwheel](https://cibuildwheel.pypa.io)), and
|
|
272
|
+
publishes them to PyPI with trusted publishing.
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
## Contributing
|
|
276
|
+
|
|
277
|
+
transit-python is maintained by [Vendekagon Labs](https://github.com/vendekagon-labs).
|
|
278
|
+
Report problems and suggest changes with GitHub
|
|
279
|
+
[issues](https://github.com/vendekagon-labs/transit-python/issues).
|
|
280
|
+
|
|
281
|
+
Pull requests are welcome, but make sure they're well tested first: add tests
|
|
282
|
+
for what you change, and check that the tests and transit-format's verify
|
|
283
|
+
harness (`bin/verify`) pass, with both the native extension and pure Python
|
|
284
|
+
(`TRANSIT_PUREPYTHON=1`).
|
|
285
|
+
|
|
286
|
+
## Copyright and License
|
|
287
|
+
|
|
288
|
+
Copyright © 2026 Vendekagon Labs LLC
|
|
289
|
+
|
|
290
|
+
Copyright © 2014-2016 Cognitect
|
|
291
|
+
|
|
292
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
293
|
+
you may not use this file except in compliance with the License.
|
|
294
|
+
You may obtain a copy of the License at
|
|
295
|
+
|
|
296
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
297
|
+
|
|
298
|
+
Unless required by applicable law or agreed to in writing, software
|
|
299
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
300
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
301
|
+
See the License for the specific language governing permissions and
|
|
302
|
+
limitations under the License.
|