rida-format 2.0.1__tar.gz → 3.0.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.
Files changed (31) hide show
  1. {rida_format-2.0.1 → rida_format-3.0.2}/CHANGELOG.md +12 -0
  2. {rida_format-2.0.1/src/rida_format.egg-info → rida_format-3.0.2}/PKG-INFO +15 -24
  3. {rida_format-2.0.1 → rida_format-3.0.2}/RIDA-FORMAT.md +7 -2
  4. {rida_format-2.0.1 → rida_format-3.0.2}/RIDA-README.md +13 -21
  5. {rida_format-2.0.1 → rida_format-3.0.2}/pyproject.toml +2 -7
  6. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida/__init__.py +68 -23
  7. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida/_encryption.py +5 -5
  8. {rida_format-2.0.1 → rida_format-3.0.2/src/rida_format.egg-info}/PKG-INFO +15 -24
  9. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida_format.egg-info/requires.txt +0 -2
  10. {rida_format-2.0.1 → rida_format-3.0.2}/tests/test_rida.py +23 -0
  11. {rida_format-2.0.1 → rida_format-3.0.2}/LICENSE +0 -0
  12. {rida_format-2.0.1 → rida_format-3.0.2}/MANIFEST.in +0 -0
  13. {rida_format-2.0.1 → rida_format-3.0.2}/docs/rida-metadata.html +0 -0
  14. {rida_format-2.0.1 → rida_format-3.0.2}/setup.cfg +0 -0
  15. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida/__main__.py +0 -0
  16. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida_format.egg-info/SOURCES.txt +0 -0
  17. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida_format.egg-info/dependency_links.txt +0 -0
  18. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida_format.egg-info/entry_points.txt +0 -0
  19. {rida_format-2.0.1 → rida_format-3.0.2}/src/rida_format.egg-info/top_level.txt +0 -0
  20. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixture_spec.py +0 -0
  21. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-source-dictionary.json +0 -0
  22. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-source-sequential.json +0 -0
  23. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-denseData.rida +0 -0
  24. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-denseIndex.rida +0 -0
  25. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-sparseData.rida +0 -0
  26. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-sparseIndex.rida +0 -0
  27. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-denseData.rida +0 -0
  28. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-denseIndex.rida +0 -0
  29. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-sparseData.rida +0 -0
  30. {rida_format-2.0.1 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-sparseIndex.rida +0 -0
  31. {rida_format-2.0.1 → rida_format-3.0.2}/tests/make_fixtures.py +0 -0
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.2
4
+
5
+ - Aligned the version numbering for Python, Node.js, and RIDA Studio.
6
+ - Made encrypted and unencrypted datasets readable across all three editions, including existing files written with either index header layout.
7
+
8
+ ## 2.0.2 — Encryption included in the default install
9
+
10
+ - Made cryptography a required dependency so pip install rida-format includes encryption support.
11
+ - Removed the separate encryption extra from install instructions.
12
+ - The RIDA data format and encryption algorithm are unchanged.
13
+
14
+
3
15
  ## 2.0.1 — Encrypted delivery and application examples
4
16
 
5
17
  - Added direct encrypted CDN delivery guidance and server-only key handling.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rida-format
3
- Version: 2.0.1
3
+ Version: 3.0.2
4
4
  Summary: Range Indexed Data Access (RIDA) static data format and library
5
5
  Author: Syed Ali Hamza Chishty
6
6
  Maintainer-email: Qasra Foundation <admin@qasra.org>
@@ -19,11 +19,10 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Requires-Python: >=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Provides-Extra: encryption
23
- Requires-Dist: cryptography>=42.0; extra == "encryption"
22
+ Requires-Dist: cryptography>=42.0
24
23
  Dynamic: license-file
25
24
 
26
- # RIDA Python library — 2.0.1
25
+ # RIDA Python library — 3.0.2
27
26
 
28
27
  RIDA means **Range Indexed Data Access**. It is an installable Python library
29
28
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -64,7 +63,7 @@ case, and any JSON collection of the same shape behaves the same way.
64
63
  From this project folder:
65
64
 
66
65
  ```sh
67
- python3 -m pip install .
66
+ pip install .
68
67
  ```
69
68
 
70
69
  After that, the `rida` command is available in the same Python environment.
@@ -74,7 +73,7 @@ account, or server process is required.
74
73
  Install the published package with:
75
74
 
76
75
  ```sh
77
- python3 -m pip install rida-format
76
+ pip install rida-format
78
77
  ```
79
78
 
80
79
  The PyPI package name is `rida-format`. After installation, the terminal
@@ -115,20 +114,12 @@ individual `.py` file: they use `import rida`, `rida ...`, or `python -m rida`.
115
114
  ## Requirements and downloads
116
115
 
117
116
  - Python **3.10 or newer** and `pip` are required.
118
- - RIDA has **no required third-party runtime dependencies**. It uses only
119
- Python's built-in `json`, `zlib`, `lzma`, `hashlib`, `urllib`, and related
120
- standard modules.
121
- - **Value encryption is the one optional extra.** It needs the
122
- `cryptography` package, so install it only when you build or read encrypted
123
- files:
124
-
125
- ```sh
126
- python3 -m pip install "rida-format[encryption]"
127
- ```
128
-
129
- Everything else — building unencrypted files, local reads, remote reads,
130
- verification — works without it. `rida.encryption_available()` reports
131
- whether it is importable in the current environment.
117
+ - A single `pip install rida-format` installs RIDA and its `cryptography`
118
+ dependency. Building and reading encrypted datasets is included; there is
119
+ no separate encryption install or extra to choose.
120
+ - JSON, compression, hashing, and HTTP reads use Python's standard modules.
121
+ `rida.encryption_available()` reports whether the installed encryption
122
+ dependency can be imported in the current environment.
132
123
  - The `rida` command has its own progress display for loading, scanning, value
133
124
  writing, catalog compression, and final file writing. It does not require
134
125
  `tqdm`.
@@ -480,7 +471,7 @@ rida verify UsersData.rida
480
471
 
481
472
  ## Where RIDA can read data
482
473
 
483
- RIDA 2.0.1 can read a data file from the local computer or from a direct
474
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
484
475
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
485
476
  requests; it does not use a cloud-provider SDK. This makes it compatible with
486
477
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -612,7 +603,7 @@ A data file that is served from a CDN is public. Encrypting it means a scraper
612
603
  that downloads the file gets bytes it cannot read.
613
604
 
614
605
  ```sh
615
- # Needs the optional extra: pip install "rida-format[encryption]"
606
+ # Encryption support is included in pip install rida-format
616
607
  rida build ./my-data ItemsData.rida --encrypt
617
608
  ```
618
609
 
@@ -670,7 +661,7 @@ client somehow, and a client that holds a key can be studied. Looking after the
670
661
  key is the publisher's job, exactly like a password.
671
662
 
672
663
  For access control tied to a user account on every read, keep the key on your
673
- server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the optional
664
+ server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the encryption
674
665
  dependency is present before you promise encryption to a caller.
675
666
 
676
667
  ### Encrypted data directly from your CDN
@@ -990,7 +981,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
990
981
 
991
982
  ## Current scope
992
983
 
993
- RIDA 2.0.1 implements primary lookup — `record ID + field name → value` — plus
984
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
994
985
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
995
986
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
996
987
  encryption of every stored value. Optional exact-match,
@@ -103,7 +103,7 @@ The index is a fixed 72-byte header followed by one LZMA-compressed catalog.
103
103
 
104
104
  ### 2.1 Index header
105
105
 
106
- `struct` format `>8sIIIIIQI32s`:
106
+ `struct` format `>8sIIIIQII32s`:
107
107
 
108
108
  | Offset | Size | Field | Meaning |
109
109
  | --- | --- | --- | --- |
@@ -117,6 +117,11 @@ The index is a fixed 72-byte header followed by one LZMA-compressed catalog.
117
117
  | 36 | 4 | `flags` | bit 0 set means the values are encrypted |
118
118
  | 40 | 32 | `data_digest` | SHA-256 of the whole data region, all zeros when not computed |
119
119
 
120
+ Older Python writers put a 32-bit data length at offset 24, followed by a
121
+ 64-bit codec code. Readers accept that layout too. When the low word of the
122
+ length is zero, the catalog's final data offset distinguishes a legacy length
123
+ from a genuine multiple of 4 GiB.
124
+
120
125
  A reader checks `data_length` against the size of the data file before serving
121
126
  anything, so a truncated or mismatched download fails immediately rather than
122
127
  part-way through a lookup.
@@ -247,4 +252,4 @@ why `shamela/Bukhari/5` resolves to `1/1/1/5` without the caller naming it.
247
252
  decompression, catches damage before any JSON is parsed.
248
253
  * **No header to keep in step.** The data file has nothing to get out of date.
249
254
  * **Changing the field set is a rebuild.** The schema is fixed for the life of a
250
- dataset; that is what lets a lookup be a single range.
255
+ dataset; that is what lets a lookup be a single range.
@@ -1,4 +1,4 @@
1
- # RIDA Python library — 2.0.1
1
+ # RIDA Python library — 3.0.2
2
2
 
3
3
  RIDA means **Range Indexed Data Access**. It is an installable Python library
4
4
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -39,7 +39,7 @@ case, and any JSON collection of the same shape behaves the same way.
39
39
  From this project folder:
40
40
 
41
41
  ```sh
42
- python3 -m pip install .
42
+ pip install .
43
43
  ```
44
44
 
45
45
  After that, the `rida` command is available in the same Python environment.
@@ -49,7 +49,7 @@ account, or server process is required.
49
49
  Install the published package with:
50
50
 
51
51
  ```sh
52
- python3 -m pip install rida-format
52
+ pip install rida-format
53
53
  ```
54
54
 
55
55
  The PyPI package name is `rida-format`. After installation, the terminal
@@ -90,20 +90,12 @@ individual `.py` file: they use `import rida`, `rida ...`, or `python -m rida`.
90
90
  ## Requirements and downloads
91
91
 
92
92
  - Python **3.10 or newer** and `pip` are required.
93
- - RIDA has **no required third-party runtime dependencies**. It uses only
94
- Python's built-in `json`, `zlib`, `lzma`, `hashlib`, `urllib`, and related
95
- standard modules.
96
- - **Value encryption is the one optional extra.** It needs the
97
- `cryptography` package, so install it only when you build or read encrypted
98
- files:
99
-
100
- ```sh
101
- python3 -m pip install "rida-format[encryption]"
102
- ```
103
-
104
- Everything else — building unencrypted files, local reads, remote reads,
105
- verification — works without it. `rida.encryption_available()` reports
106
- whether it is importable in the current environment.
93
+ - A single `pip install rida-format` installs RIDA and its `cryptography`
94
+ dependency. Building and reading encrypted datasets is included; there is
95
+ no separate encryption install or extra to choose.
96
+ - JSON, compression, hashing, and HTTP reads use Python's standard modules.
97
+ `rida.encryption_available()` reports whether the installed encryption
98
+ dependency can be imported in the current environment.
107
99
  - The `rida` command has its own progress display for loading, scanning, value
108
100
  writing, catalog compression, and final file writing. It does not require
109
101
  `tqdm`.
@@ -455,7 +447,7 @@ rida verify UsersData.rida
455
447
 
456
448
  ## Where RIDA can read data
457
449
 
458
- RIDA 2.0.1 can read a data file from the local computer or from a direct
450
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
459
451
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
460
452
  requests; it does not use a cloud-provider SDK. This makes it compatible with
461
453
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -587,7 +579,7 @@ A data file that is served from a CDN is public. Encrypting it means a scraper
587
579
  that downloads the file gets bytes it cannot read.
588
580
 
589
581
  ```sh
590
- # Needs the optional extra: pip install "rida-format[encryption]"
582
+ # Encryption support is included in pip install rida-format
591
583
  rida build ./my-data ItemsData.rida --encrypt
592
584
  ```
593
585
 
@@ -645,7 +637,7 @@ client somehow, and a client that holds a key can be studied. Looking after the
645
637
  key is the publisher's job, exactly like a password.
646
638
 
647
639
  For access control tied to a user account on every read, keep the key on your
648
- server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the optional
640
+ server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the encryption
649
641
  dependency is present before you promise encryption to a caller.
650
642
 
651
643
  ### Encrypted data directly from your CDN
@@ -965,7 +957,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
965
957
 
966
958
  ## Current scope
967
959
 
968
- RIDA 2.0.1 implements primary lookup — `record ID + field name → value` — plus
960
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
969
961
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
970
962
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
971
963
  encryption of every stored value. Optional exact-match,
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rida-format"
7
- version = "2.0.1"
7
+ version = "3.0.2"
8
8
  description = "Range Indexed Data Access (RIDA) static data format and library"
9
9
  readme = "RIDA-README.md"
10
10
  requires-python = ">=3.10"
11
- dependencies = []
11
+ dependencies = ["cryptography>=42.0"]
12
12
  license = "LicenseRef-Proprietary"
13
13
  license-files = ["LICENSE"]
14
14
  authors = [
@@ -35,11 +35,6 @@ classifiers = [
35
35
  PyPI = "https://pypi.org/project/rida-format/"
36
36
  Changelog = "https://pypi.org/project/rida-format/#history"
37
37
 
38
- [project.optional-dependencies]
39
- # Catalog encryption (``rida build --encrypt`` and ``key=`` readers).
40
- # Every other RIDA feature runs on the standard library alone.
41
- encryption = ["cryptography>=42.0"]
42
-
43
38
  [project.scripts]
44
39
  rida = "rida:main"
45
40
 
@@ -35,6 +35,7 @@ import http.client
35
35
  import json
36
36
  import lzma
37
37
  import os
38
+ import re
38
39
  import select
39
40
  import struct
40
41
  import sys
@@ -44,7 +45,7 @@ import time
44
45
  import urllib.error
45
46
  import urllib.parse
46
47
  import urllib.request
47
- from dataclasses import dataclass, field
48
+ from dataclasses import dataclass, field, replace
48
49
  from pathlib import Path
49
50
  from typing import Any, BinaryIO, Callable, Iterable, Iterator
50
51
 
@@ -77,7 +78,7 @@ INDEX_MAGIC = b"RIDAIDX1"
77
78
  INDEX_VERSION = 1
78
79
  #: magic, index version, catalog length, raw catalog length, record count,
79
80
  #: data length, value codec code, flags, data digest.
80
- INDEX_HEADER = struct.Struct(">8sIIIIIQI32s")
81
+ INDEX_HEADER = struct.Struct(">8sIIIIQII32s")
81
82
  INDEX_FLAG_ENCRYPTED = 0x01
82
83
  _INDEX_SIZE = INDEX_HEADER.size
83
84
  _CODEC_CODES = {VALUE_CODEC_DEFLATE: 1, VALUE_CODEC_PLAIN: 2}
@@ -88,7 +89,7 @@ CATALOG_HEADER = struct.Struct(">8sIIQIIIQ")
88
89
  MODE_DENSE = 1
89
90
  MODE_SPARSE = 2
90
91
  _READ_BLOCK = 1024 * 1024
91
- __version__ = "2.0.1"
92
+ __version__ = "3.0.2"
92
93
  ProgressCallback = Callable[[str, int, int], None]
93
94
 
94
95
 
@@ -123,16 +124,15 @@ __all__ = [
123
124
  "verify",
124
125
  ]
125
126
 
126
- #: Raised when encryption is requested but the optional dependency is missing.
127
+ #: Raised when encryption is requested but the encryption dependency is missing.
127
128
  EncryptionUnavailable = _encryption.EncryptionUnavailable
128
129
 
129
130
 
130
131
  def encryption_available() -> bool:
131
132
  """Return True when catalog encryption can run in this environment.
132
133
 
133
- Encryption needs the optional ``cryptography`` package
134
- (``pip install "rida-format[encryption]"``). Every other RIDA feature works
135
- without it.
134
+ Encryption uses the ``cryptography`` dependency, installed automatically
135
+ with ``pip install rida-format``.
136
136
  """
137
137
  return _encryption.is_available()
138
138
 
@@ -2590,7 +2590,7 @@ def _pack_index_bytes(
2590
2590
  )
2591
2591
 
2592
2592
 
2593
- def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2593
+ def _unpack_index(raw: bytes) -> tuple[Index, bytes]:
2594
2594
  """Parse an index entry and return ``(Index, compressed_catalog)``."""
2595
2595
  if len(raw) < _INDEX_SIZE:
2596
2596
  raise RidaError("RIDA index is incomplete")
@@ -2629,6 +2629,34 @@ def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2629
2629
  return index, catalog
2630
2630
 
2631
2631
 
2632
+ def _resolve_index_length(index: Index, catalog: Catalog) -> Index:
2633
+ # Older Python files stored the 32-bit length in the high word of the
2634
+ # 64-bit length field. A genuine multiple of 4 GiB has the same encoding,
2635
+ # so use the end of the final catalog row to distinguish the two cases.
2636
+ length = index.data_length
2637
+ if not length or length & 0xFFFFFFFF:
2638
+ return index
2639
+ catalog_end = catalog._data_end()
2640
+ if catalog_end == length:
2641
+ return index
2642
+ if catalog_end == length >> 32:
2643
+ return replace(index, data_length=catalog_end)
2644
+ raise RidaError("RIDA data length does not match its catalog")
2645
+
2646
+
2647
+ def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2648
+ index, compressed = _unpack_index(raw)
2649
+ if index.data_length and not index.data_length & 0xFFFFFFFF:
2650
+ index = _resolve_index_length(index, Catalog(index, compressed))
2651
+ return index, compressed
2652
+
2653
+
2654
+ def _open_index(raw: bytes) -> tuple[Index, Catalog]:
2655
+ index, compressed = _unpack_index(raw)
2656
+ catalog = Catalog(index, compressed)
2657
+ return _resolve_index_length(index, catalog), catalog
2658
+
2659
+
2632
2660
  class Catalog:
2633
2661
  """Decompressed RIDA catalog with record and field location lookups."""
2634
2662
 
@@ -2694,6 +2722,16 @@ class Catalog:
2694
2722
  raw, self.row_offsets_start, self.row_data_start, record_count, row_data_length
2695
2723
  )
2696
2724
 
2725
+ def _data_end(self) -> int:
2726
+ if not self.record_count:
2727
+ return 0
2728
+ start = self.row_data_start + self.row_offsets[-2]
2729
+ end = self.row_data_start + self.row_offsets[-1]
2730
+ offset, _ = _decode_varint(memoryview(self.raw)[start:end], 0)
2731
+ record_id = self.ids[-1] if self.ids else self.record_count
2732
+ pointers = self.pointer_many(record_id, self.fields)
2733
+ return max((start + length for start, length in pointers.values()), default=offset)
2734
+
2697
2735
  def _record_number(self, record_id: str | int) -> int:
2698
2736
  normalized = str(record_id)
2699
2737
  if self.id_to_record is not None:
@@ -3064,8 +3102,8 @@ def build(
3064
3102
  key = _encryption.generate_key()
3065
3103
  if key is not None and not _encryption.is_available():
3066
3104
  raise EncryptionUnavailable(
3067
- "Data encryption needs the optional 'cryptography' package. "
3068
- 'Install it with: pip install "rida-format[encryption]"'
3105
+ "Data encryption needs the 'cryptography' dependency installed with RIDA. "
3106
+ 'Install it with: pip install rida-format'
3069
3107
  )
3070
3108
  source_path = Path(source)
3071
3109
  selected_input = _resolve_record_directory(
@@ -3173,14 +3211,13 @@ class RidaFile:
3173
3211
  self.path = Path(path)
3174
3212
  self._key = key
3175
3213
  raw_index = _read_index_file(self.path, index)
3176
- self.index, catalog = _parse_index(raw_index)
3214
+ self.index, self.catalog = _open_index(raw_index)
3177
3215
  if self.index.encrypted and key is None:
3178
3216
  raise RidaError(
3179
3217
  "This RIDA file has an encrypted data region. Pass key= to RidaFile."
3180
3218
  )
3181
3219
  if self.path.stat().st_size != self.index.data_length:
3182
3220
  raise RidaError("RIDA data file does not match its index")
3183
- self.catalog = Catalog(self.index, catalog)
3184
3221
  self.file = self.path.open("rb")
3185
3222
  self.map = self._load_map()
3186
3223
 
@@ -3627,13 +3664,12 @@ class RemoteRidaFile:
3627
3664
  "No local index for this RIDA file. Build the dataset to write one, "
3628
3665
  "or pass index= pointing at it."
3629
3666
  )
3630
- self.index, catalog = _parse_index(raw_index)
3667
+ self.index, self.catalog = _open_index(raw_index)
3631
3668
  if self.index.encrypted and key is None:
3632
3669
  raise RidaError(
3633
3670
  "This RIDA file has an encrypted data region. Pass key= to RemoteRidaFile."
3634
3671
  )
3635
3672
  self.cache_hit = True
3636
- self.catalog = Catalog(self.index, catalog)
3637
3673
 
3638
3674
  @property
3639
3675
  def value_codec(self) -> str:
@@ -3722,11 +3758,11 @@ def open_reader(
3722
3758
  def inspect_metadata(path: Path) -> dict[str, Any]:
3723
3759
  """Describe a dataset from its index and data file. Nothing is fetched."""
3724
3760
  path = Path(path)
3725
- index, catalog = _parse_index(_read_index_file(path))
3726
- catalog_object = Catalog(index, catalog)
3761
+ raw_index = _read_index_file(path)
3762
+ index, catalog_object = _open_index(raw_index)
3727
3763
  return {
3728
3764
  "index": {
3729
- "index_bytes": len(_read_index_file(path)),
3765
+ "index_bytes": len(raw_index),
3730
3766
  "format_version": index.version,
3731
3767
  "value_codec": index.value_codec,
3732
3768
  "catalog_bytes": index.catalog_length,
@@ -3763,9 +3799,9 @@ def verify(
3763
3799
  index: Index | None = None
3764
3800
  encrypted = False
3765
3801
  try:
3766
- index, catalog = _parse_index(_read_index_file(path))
3802
+ index, compressed = _unpack_index(_read_index_file(path))
3767
3803
  encrypted = index.encrypted
3768
- Catalog(index, catalog)
3804
+ index = _resolve_index_length(index, Catalog(index, compressed))
3769
3805
  catalog_ok = True
3770
3806
  except RidaError:
3771
3807
  catalog_ok = False
@@ -4005,7 +4041,7 @@ def _ask_build_encoding_options(args: Any) -> Any:
4005
4041
  if args.encrypt and not _encryption.is_available():
4006
4042
  print(
4007
4043
  " 'cryptography' is not installed, so encryption is not available.\n"
4008
- ' Install it with: pip install "rida-format[encryption]"'
4044
+ ' Install it with: pip install rida-format'
4009
4045
  )
4010
4046
  args.encrypt = False
4011
4047
  if not args.encrypt:
@@ -4334,12 +4370,21 @@ def _main() -> int:
4334
4370
  cache_parser.add_argument("--url", help="Only act on the cache entry for this URL")
4335
4371
  cache_parser.add_argument("--cache-dir", type=Path)
4336
4372
 
4337
- args = parser.parse_args()
4373
+ argv = sys.argv[1:]
4374
+ for i in range(len(argv) - 1):
4375
+ if argv[i] == "--":
4376
+ break
4377
+ if argv[i] == "--key" and re.fullmatch(r"-[A-Za-z0-9_-]{42}=?", argv[i + 1]):
4378
+ # URL-safe base64 may begin with a dash. Bind it before argparse
4379
+ # can mistake it for another option.
4380
+ argv[i:i + 2] = [f"--key={argv[i + 1]}"]
4381
+ break
4382
+ args = parser.parse_args(argv)
4338
4383
  if args.command == "build" and (getattr(args, "key", None) or getattr(args, "encrypt", False)):
4339
4384
  if not _encryption.is_available():
4340
4385
  print(
4341
- "RIDA error: Data encryption needs the optional 'cryptography' package. "
4342
- 'Install it with: pip install "rida-format[encryption]"',
4386
+ "RIDA error: Data encryption needs the 'cryptography' dependency installed with RIDA. "
4387
+ 'Install it with: pip install rida-format',
4343
4388
  file=sys.stderr,
4344
4389
  )
4345
4390
  return 1
@@ -6,9 +6,9 @@ a scraper that reads the catalog region gets ciphertext, not LZMA data.
6
6
 
7
7
  Keys are 256-bit (32 bytes), carried as URL-safe base64 strings (44 chars).
8
8
 
9
- This module needs the optional ``cryptography`` package::
9
+ This module needs the ``cryptography`` package installed with RIDA::
10
10
 
11
- pip install "rida-format[encryption]"
11
+ pip install rida-format
12
12
 
13
13
  Everything else in the library runs on the standard library alone, so a
14
14
  build that never passes ``encrypt=True`` never touches this module.
@@ -37,14 +37,14 @@ def _load_aesgcm() -> object:
37
37
  from cryptography.hazmat.primitives.ciphers.aead import AESGCM
38
38
  except ImportError as exc: # pragma: no cover - depends on the environment
39
39
  raise EncryptionUnavailable(
40
- "Catalog encryption needs the optional 'cryptography' package. "
41
- 'Install it with: pip install "rida-format[encryption]"'
40
+ "Encryption needs the 'cryptography' dependency installed with RIDA. "
41
+ 'Install it with: pip install rida-format'
42
42
  ) from exc
43
43
  return AESGCM
44
44
 
45
45
 
46
46
  def is_available() -> bool:
47
- """Return True when the optional encryption dependency is importable."""
47
+ """Return True when the encryption dependency is importable."""
48
48
  try:
49
49
  _load_aesgcm()
50
50
  except EncryptionUnavailable:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rida-format
3
- Version: 2.0.1
3
+ Version: 3.0.2
4
4
  Summary: Range Indexed Data Access (RIDA) static data format and library
5
5
  Author: Syed Ali Hamza Chishty
6
6
  Maintainer-email: Qasra Foundation <admin@qasra.org>
@@ -19,11 +19,10 @@ Classifier: Programming Language :: Python :: 3.13
19
19
  Requires-Python: >=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Provides-Extra: encryption
23
- Requires-Dist: cryptography>=42.0; extra == "encryption"
22
+ Requires-Dist: cryptography>=42.0
24
23
  Dynamic: license-file
25
24
 
26
- # RIDA Python library — 2.0.1
25
+ # RIDA Python library — 3.0.2
27
26
 
28
27
  RIDA means **Range Indexed Data Access**. It is an installable Python library
29
28
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -64,7 +63,7 @@ case, and any JSON collection of the same shape behaves the same way.
64
63
  From this project folder:
65
64
 
66
65
  ```sh
67
- python3 -m pip install .
66
+ pip install .
68
67
  ```
69
68
 
70
69
  After that, the `rida` command is available in the same Python environment.
@@ -74,7 +73,7 @@ account, or server process is required.
74
73
  Install the published package with:
75
74
 
76
75
  ```sh
77
- python3 -m pip install rida-format
76
+ pip install rida-format
78
77
  ```
79
78
 
80
79
  The PyPI package name is `rida-format`. After installation, the terminal
@@ -115,20 +114,12 @@ individual `.py` file: they use `import rida`, `rida ...`, or `python -m rida`.
115
114
  ## Requirements and downloads
116
115
 
117
116
  - Python **3.10 or newer** and `pip` are required.
118
- - RIDA has **no required third-party runtime dependencies**. It uses only
119
- Python's built-in `json`, `zlib`, `lzma`, `hashlib`, `urllib`, and related
120
- standard modules.
121
- - **Value encryption is the one optional extra.** It needs the
122
- `cryptography` package, so install it only when you build or read encrypted
123
- files:
124
-
125
- ```sh
126
- python3 -m pip install "rida-format[encryption]"
127
- ```
128
-
129
- Everything else — building unencrypted files, local reads, remote reads,
130
- verification — works without it. `rida.encryption_available()` reports
131
- whether it is importable in the current environment.
117
+ - A single `pip install rida-format` installs RIDA and its `cryptography`
118
+ dependency. Building and reading encrypted datasets is included; there is
119
+ no separate encryption install or extra to choose.
120
+ - JSON, compression, hashing, and HTTP reads use Python's standard modules.
121
+ `rida.encryption_available()` reports whether the installed encryption
122
+ dependency can be imported in the current environment.
132
123
  - The `rida` command has its own progress display for loading, scanning, value
133
124
  writing, catalog compression, and final file writing. It does not require
134
125
  `tqdm`.
@@ -480,7 +471,7 @@ rida verify UsersData.rida
480
471
 
481
472
  ## Where RIDA can read data
482
473
 
483
- RIDA 2.0.1 can read a data file from the local computer or from a direct
474
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
484
475
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
485
476
  requests; it does not use a cloud-provider SDK. This makes it compatible with
486
477
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -612,7 +603,7 @@ A data file that is served from a CDN is public. Encrypting it means a scraper
612
603
  that downloads the file gets bytes it cannot read.
613
604
 
614
605
  ```sh
615
- # Needs the optional extra: pip install "rida-format[encryption]"
606
+ # Encryption support is included in pip install rida-format
616
607
  rida build ./my-data ItemsData.rida --encrypt
617
608
  ```
618
609
 
@@ -670,7 +661,7 @@ client somehow, and a client that holds a key can be studied. Looking after the
670
661
  key is the publisher's job, exactly like a password.
671
662
 
672
663
  For access control tied to a user account on every read, keep the key on your
673
- server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the optional
664
+ server, check permission there, and return decrypted content rather than the key. `rida.encryption_available()` tells you whether the encryption
674
665
  dependency is present before you promise encryption to a caller.
675
666
 
676
667
  ### Encrypted data directly from your CDN
@@ -990,7 +981,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
990
981
 
991
982
  ## Current scope
992
983
 
993
- RIDA 2.0.1 implements primary lookup — `record ID + field name → value` — plus
984
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
994
985
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
995
986
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
996
987
  encryption of every stored value. Optional exact-match,
@@ -1,3 +1 @@
1
-
2
- [encryption]
3
1
  cryptography>=42.0
@@ -379,6 +379,19 @@ class GetManyTests(TempDirTestCase):
379
379
 
380
380
 
381
381
  class IntegrityTests(TempDirTestCase):
382
+ def test_reads_legacy_python_index_with_a_final_empty_record(self) -> None:
383
+ target = self.build("legacy.json", {"1": {"v": "hello"}, "2": {}})
384
+ index_path = rida._index_path_for_output(target)
385
+ index_bytes = index_path.read_bytes()
386
+ size = target.stat().st_size
387
+ self.assertEqual(struct.unpack_from(">Q", index_bytes, 24)[0], size)
388
+ index_path.write_bytes(index_bytes[:24] + struct.pack(">II", size, 0) + index_bytes[32:])
389
+
390
+ with rida.open_reader(target) as data:
391
+ self.assertEqual(data.index.data_length, size)
392
+ self.assertEqual(data.get("1", "v"), "hello")
393
+ self.assertTrue(rida.verify(target)["ok"])
394
+
382
395
  def test_verify_detects_a_corrupted_data_region(self) -> None:
383
396
  target = self.build("packed.json", {"1": {"v": "hello"}, "2": {"v": "world"}})
384
397
  raw = bytearray(target.read_bytes())
@@ -1149,6 +1162,16 @@ class EncryptionTests(TempDirTestCase):
1149
1162
  self.assertEqual(result.returncode, 0, result.stderr)
1150
1163
  self.assertIn("Fields: 4", result.stdout)
1151
1164
 
1165
+ def test_cli_accepts_urlsafe_keys_starting_with_two_dashes(self) -> None:
1166
+ key = rida._encryption.encode_key(bytes.fromhex("fbe0") + bytes(30))
1167
+ self.assertTrue(key.startswith("--"))
1168
+ source = _write_json(self.tmp / "dash-key.json", {"1": {"v": "hello"}})
1169
+ target = self.tmp / "DashData.rida"
1170
+ rida.build(source, target, key=key)
1171
+ result = self._run("get", str(target), "1", "v", "--key", key)
1172
+ self.assertEqual(result.returncode, 0, result.stderr)
1173
+ self.assertEqual(result.stdout.strip(), "hello")
1174
+
1152
1175
  def test_cli_remote_get_accepts_a_key(self) -> None:
1153
1176
  target = self._build_encrypted()
1154
1177
  base, _ = self._serve(self.tmp)
File without changes
File without changes
File without changes