jtoken 0.2.1__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jtoken
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Compress JSON-shaped documents for LLM prompts with normalization, CLI, and token measurement
5
5
  Project-URL: Homepage, https://github.com/hermannsamimi/jtoken
6
6
  Project-URL: Repository, https://github.com/hermannsamimi/jtoken
@@ -126,6 +126,41 @@ nulls: ref
126
126
  - Reserved top-level keys: `nulls`, `trues`, `falses`.
127
127
  - Lists are normalized into nested dicts with numeric keys before encoding.
128
128
 
129
+ ## Input and output formats
130
+
131
+ Use `source=` / `target=` in Python or `--input-format` / `--output-format` on the CLI. `encode`, `stats`, and `count` accept `--input-format` (default `auto`). `decode` accepts `--output-format` (default `json`).
132
+
133
+ | Input (`source` / `--input-format`) | Use when |
134
+ |---|---|
135
+ | `auto` | Let jtoken detect the dialect from the text or object shape |
136
+ | `json` | Standard JSON object |
137
+ | `python` | Same JSON parser as `json` |
138
+ | `mongo_extended` | MongoDB Extended JSON with `$oid`, `$date`, `$numberInt`, `$numberLong`, `$numberDouble`, `$numberDecimal` |
139
+ | `mongo_shell` | MongoDB shell document with `ObjectId()`, `ISODate()`, `NumberInt()`, `NumberLong()` |
140
+ | `elastic_hit` | Elasticsearch search hit with `_source` (and optional `fields`) |
141
+ | `elastic_source` | `_source` payload only, or a document wrapped as `{"_source": {...}}` |
142
+
143
+ | Output (`target` / `--output-format`) | Use when |
144
+ |---|---|
145
+ | `python` | Python `repr` (Python API default) |
146
+ | `json` | Pretty-printed JSON (CLI `decode` default) |
147
+ | `mongo_extended` | Extended JSON; requires a context sidecar for BSON-like types |
148
+ | `mongo_shell` | Mongo shell document; requires a context sidecar for BSON-like types |
149
+ | `elastic_hit` | Full Elasticsearch hit envelope; requires a context sidecar |
150
+ | `elastic_source` | JSON shaped like an Elasticsearch `_source` wrapper |
151
+
152
+ With `auto`, jtoken picks `mongo_shell` when it sees `ObjectId(...)` or `ISODate(...)`, `elastic_hit` when the object has a dict `_source`, `mongo_extended` when Extended JSON markers such as `$oid` or `$date` appear, and otherwise `json`.
153
+
154
+ Write the normalization context to a sidecar on encode (`--context-out` / `NormalizationContext.to_dict()`) and pass it back on decode when the output dialect is not plain JSON or Python. The sidecar records list paths, dotted keys, Elasticsearch envelope metadata, and MongoDB type markers in `typed_values` (`object_id`, `datetime`, `long`).
155
+
156
+ ### MongoDB shell and Extended JSON
157
+
158
+ Mongo shell input is parsed as JSON after rewriting shell literals: `ObjectId("...")` and `ISODate("...")` become Extended JSON, `NumberInt(n)` becomes a plain integer, and `NumberLong(n)` becomes `{"$numberLong": "n"}`. On normalize, `object_id`, `datetime`, and `long` values are stored in the context so `mongo_extended` and `mongo_shell` output can restore `{"$oid": ...}` / `ObjectId(...)`, `{"$date": ...}` / `ISODate(...)`, and `{"$numberLong": ...}` / `NumberLong(...)`. `$numberInt`, `$numberDouble`, and `$numberDecimal` are coerced to Python scalars and are not tracked in `typed_values`.
159
+
160
+ ### Elasticsearch hits
161
+
162
+ `elastic_hit` encodes the merged `_source` document (plus any `fields` values that are not already present in `_source`) and stores `_index`, `_id`, `_version`, `_score`, `_type`, and `_routing` in the context for lossless `elastic_hit` output.
163
+
129
164
  ## Public API reference
130
165
 
131
166
  ### Package metadata
@@ -90,9 +90,40 @@ jtoken encode --input-format elastic_hit -f hit.json --context-out hit.ctx.json
90
90
  jtoken decode --output-format mongo_shell -f hit.jtoken --context-in hit.ctx.json
91
91
  ```
92
92
 
93
- Supported input dialects: `auto`, `json`, `python`, `mongo_extended`, `mongo_shell`, `elastic_hit`, `elastic_source`.
93
+ ### Input and output formats
94
94
 
95
- Supported output dialects: `python`, `json`, `mongo_extended`, `mongo_shell`, `elastic_hit`, `elastic_source`.
95
+ Use `source=` / `target=` in Python or `--input-format` / `--output-format` on the CLI. `encode`, `stats`, and `count` accept `--input-format` (default `auto`). `decode` accepts `--output-format` (default `json`).
96
+
97
+ | Input (`source` / `--input-format`) | Use when |
98
+ |---|---|
99
+ | `auto` | Let jtoken detect the dialect from the text or object shape |
100
+ | `json` | Standard JSON object |
101
+ | `python` | Same JSON parser as `json` |
102
+ | `mongo_extended` | MongoDB Extended JSON with `$oid`, `$date`, `$numberInt`, `$numberLong`, `$numberDouble`, `$numberDecimal` |
103
+ | `mongo_shell` | MongoDB shell document with `ObjectId()`, `ISODate()`, `NumberInt()`, `NumberLong()` |
104
+ | `elastic_hit` | Elasticsearch search hit with `_source` (and optional `fields`) |
105
+ | `elastic_source` | `_source` payload only, or a document wrapped as `{"_source": {...}}` |
106
+
107
+ | Output (`target` / `--output-format`) | Use when |
108
+ |---|---|
109
+ | `python` | Python `repr` (Python API default) |
110
+ | `json` | Pretty-printed JSON (CLI `decode` default) |
111
+ | `mongo_extended` | Extended JSON; requires a context sidecar for BSON-like types |
112
+ | `mongo_shell` | Mongo shell document; requires a context sidecar for BSON-like types |
113
+ | `elastic_hit` | Full Elasticsearch hit envelope; requires a context sidecar |
114
+ | `elastic_source` | JSON shaped like an Elasticsearch `_source` wrapper |
115
+
116
+ With `auto`, jtoken picks `mongo_shell` when it sees `ObjectId(...)` or `ISODate(...)`, `elastic_hit` when the object has a dict `_source`, `mongo_extended` when Extended JSON markers such as `$oid` or `$date` appear, and otherwise `json`.
117
+
118
+ Write the normalization context to a sidecar on encode (`--context-out` / `NormalizationContext.to_dict()`) and pass it back on decode when the output dialect is not plain JSON or Python. The sidecar records list paths, dotted keys, Elasticsearch envelope metadata, and MongoDB type markers in `typed_values` (`object_id`, `datetime`, `long`).
119
+
120
+ ### MongoDB shell and Extended JSON
121
+
122
+ Mongo shell input is parsed as JSON after rewriting shell literals: `ObjectId("...")` and `ISODate("...")` become Extended JSON, `NumberInt(n)` becomes a plain integer, and `NumberLong(n)` becomes `{"$numberLong": "n"}`. On normalize, `object_id`, `datetime`, and `long` values are stored in the context so `mongo_extended` and `mongo_shell` output can restore `{"$oid": ...}` / `ObjectId(...)`, `{"$date": ...}` / `ISODate(...)`, and `{"$numberLong": ...}` / `NumberLong(...)`. `$numberInt`, `$numberDouble`, and `$numberDecimal` are coerced to Python scalars and are not tracked in `typed_values`.
123
+
124
+ ### Elasticsearch hits
125
+
126
+ `elastic_hit` encodes the merged `_source` document (plus any `fields` values that are not already present in `_source`) and stores `_index`, `_id`, `_version`, `_score`, `_type`, and `_routing` in the context for lossless `elastic_hit` output.
96
127
 
97
128
  ## CLI
98
129
 
@@ -94,6 +94,41 @@ nulls: ref
94
94
  - Reserved top-level keys: `nulls`, `trues`, `falses`.
95
95
  - Lists are normalized into nested dicts with numeric keys before encoding.
96
96
 
97
+ ## Input and output formats
98
+
99
+ Use `source=` / `target=` in Python or `--input-format` / `--output-format` on the CLI. `encode`, `stats`, and `count` accept `--input-format` (default `auto`). `decode` accepts `--output-format` (default `json`).
100
+
101
+ | Input (`source` / `--input-format`) | Use when |
102
+ |---|---|
103
+ | `auto` | Let jtoken detect the dialect from the text or object shape |
104
+ | `json` | Standard JSON object |
105
+ | `python` | Same JSON parser as `json` |
106
+ | `mongo_extended` | MongoDB Extended JSON with `$oid`, `$date`, `$numberInt`, `$numberLong`, `$numberDouble`, `$numberDecimal` |
107
+ | `mongo_shell` | MongoDB shell document with `ObjectId()`, `ISODate()`, `NumberInt()`, `NumberLong()` |
108
+ | `elastic_hit` | Elasticsearch search hit with `_source` (and optional `fields`) |
109
+ | `elastic_source` | `_source` payload only, or a document wrapped as `{"_source": {...}}` |
110
+
111
+ | Output (`target` / `--output-format`) | Use when |
112
+ |---|---|
113
+ | `python` | Python `repr` (Python API default) |
114
+ | `json` | Pretty-printed JSON (CLI `decode` default) |
115
+ | `mongo_extended` | Extended JSON; requires a context sidecar for BSON-like types |
116
+ | `mongo_shell` | Mongo shell document; requires a context sidecar for BSON-like types |
117
+ | `elastic_hit` | Full Elasticsearch hit envelope; requires a context sidecar |
118
+ | `elastic_source` | JSON shaped like an Elasticsearch `_source` wrapper |
119
+
120
+ With `auto`, jtoken picks `mongo_shell` when it sees `ObjectId(...)` or `ISODate(...)`, `elastic_hit` when the object has a dict `_source`, `mongo_extended` when Extended JSON markers such as `$oid` or `$date` appear, and otherwise `json`.
121
+
122
+ Write the normalization context to a sidecar on encode (`--context-out` / `NormalizationContext.to_dict()`) and pass it back on decode when the output dialect is not plain JSON or Python. The sidecar records list paths, dotted keys, Elasticsearch envelope metadata, and MongoDB type markers in `typed_values` (`object_id`, `datetime`, `long`).
123
+
124
+ ### MongoDB shell and Extended JSON
125
+
126
+ Mongo shell input is parsed as JSON after rewriting shell literals: `ObjectId("...")` and `ISODate("...")` become Extended JSON, `NumberInt(n)` becomes a plain integer, and `NumberLong(n)` becomes `{"$numberLong": "n"}`. On normalize, `object_id`, `datetime`, and `long` values are stored in the context so `mongo_extended` and `mongo_shell` output can restore `{"$oid": ...}` / `ObjectId(...)`, `{"$date": ...}` / `ISODate(...)`, and `{"$numberLong": ...}` / `NumberLong(...)`. `$numberInt`, `$numberDouble`, and `$numberDecimal` are coerced to Python scalars and are not tracked in `typed_values`.
127
+
128
+ ### Elasticsearch hits
129
+
130
+ `elastic_hit` encodes the merged `_source` document (plus any `fields` values that are not already present in `_source`) and stores `_index`, `_id`, `_version`, `_score`, `_type`, and `_routing` in the context for lossless `elastic_hit` output.
131
+
97
132
  ## Public API reference
98
133
 
99
134
  ### Package metadata
@@ -19,7 +19,7 @@ from .tokens import (
19
19
  token_savings,
20
20
  )
21
21
 
22
- __version__ = "0.2.1"
22
+ __version__ = "0.2.2"
23
23
  __author__ = "Hermann Samimi"
24
24
 
25
25
  # json-style aliases
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "jtoken"
7
- version = "0.2.1"
7
+ version = "0.2.2"
8
8
  description = "Compress JSON-shaped documents for LLM prompts with normalization, CLI, and token measurement"
9
9
  readme = "README.pypi.md"
10
10
  requires-python = ">=3.8"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes