Python API¶
Import the public API from ogc_records_parquet. The reference below is
generated from its exported objects, signatures, and Google-style docstrings.
For column types and metadata contracts, see the storage format. See errors and limitations for failure timing and migration for API changes.
Store PySTAC OGCRecord objects alongside Arrow and GeoParquet query projections.
Use records_to_arrow() and to_parquet() to write records, then
read_parquet() to reconstruct them. arrow_to_records() reconstructs records
from an in-memory table or stream. Readers use the preserved JSON payload,
independently of query columns and storage-only collection membership.
Record parsing and serialization belong to pystac-ext-ogc-record. This package
checks storage compatibility and projection safety; OGC profile validation and
query execution remain the caller's responsibility.
records_to_arrow(records, *, schema=None, batch_size=1024, collections=None, collection_ids=None)
¶
Project Records into a lazy Arrow stream with PySTAC-serialized payloads.
Record and membership iterables are consumed only when the reader is advanced. Records are serialized at that time, so changes made before consumption are visible. Collection descriptions are instead validated and serialized immediately. The input records and descriptions are not modified.
Each row retains the document produced by
OGCRecord.to_dict(transform_hrefs=False), including self links and
unmodified relative hrefs. PySTAC normalization applies before storage;
original JSON bytes and pre-normalization timestamp precision are not
preserved. Null geometry and records without STAC temporal fields are
supported. Non-null geometry must already use CRS84 longitude/latitude.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Examples:
Create a stream and inspect a default query column:
>>> from pystac.extensions.ogc_record import OGCRecord
>>> from ogc_records_parquet import records_to_arrow
>>> record = OGCRecord(id="workflow", properties={"title": "Flood mapping"})
>>> table = records_to_arrow([record], batch_size=1).read_all()
>>> table["properties.title"].to_pylist()
['Flood mapping']
Source code in src/ogc_records_parquet/arrow.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
arrow_to_records(table)
¶
Decode OGCRecord objects from a library-produced Arrow stream.
Stored payloads are authoritative: editing query or membership columns does
not edit the exported records. Decoding follows OGCRecord.from_dict(),
including its normalization rules for legacy payloads. No OGC profile
validation is performed.
Validation and decoding begin on iteration, not when this function is called.
A supplied reader is consumed from its current position. A table is not
modified. Storage formats 1.0.0 and 1.1.0 are accepted.
| Parameters: |
|
|---|
| Yields: |
|
|---|
| Raises: |
|
|---|
Examples:
Reconstruct from only the payload column, retaining schema metadata:
>>> from pystac.extensions.ogc_record import OGCRecord
>>> from ogc_records_parquet import arrow_to_records, records_to_arrow
>>> table = records_to_arrow([OGCRecord(id="workflow")]).read_all()
>>> restored = next(arrow_to_records(table.select(["__record_json"])))
>>> restored.id
'workflow'
Source code in src/ogc_records_parquet/arrow.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
to_parquet(table, path, *, compression='zstd')
¶
Write a library-produced Arrow stream to a local GeoParquet file.
Consumes batches in source order and replaces an existing destination only after successful conversion and writing. A failed conversion leaves the destination unchanged. Temporary data is created in the destination directory. Remote/object-storage paths are not supported.
Schema metadata and the supplied storage format version are retained; writing a valid legacy stream does not upgrade it. Storage structure is checked, but arbitrary input tables do not receive per-payload Record or OGC schema validation.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Examples:
Write a local file and read its records:
>>> from pathlib import Path
>>> from tempfile import TemporaryDirectory
>>> from pystac.extensions.ogc_record import OGCRecord
>>> from ogc_records_parquet import read_parquet, records_to_arrow, to_parquet
>>> with TemporaryDirectory() as directory:
... path = Path(directory) / "records.parquet"
... to_parquet(records_to_arrow([OGCRecord(id="workflow")]), path)
... identifiers = [record.id for record in read_parquet(path)]
>>> identifiers
['workflow']
Source code in src/ogc_records_parquet/parquet.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
read_parquet(path, *, batch_size=1024)
¶
Read OGCRecord objects in file order from GeoParquet.
Opens the file and validates its format when iteration begins. Records are
reconstructed from their stored JSON payloads, not from query projections.
Storage formats 1.0.0 and 1.1.0 are accepted; current PySTAC parsing
and normalization apply to both.
The file remains open while the iterator is active. Exhaust the iterator or
call its close() method when abandoning iteration early.
| Parameters: |
|
|---|
| Yields: |
|
|---|
| Raises: |
|
|---|
Source code in src/ogc_records_parquet/parquet.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
read_metadata(path)
¶
Read the library's format metadata without decoding Record payloads.
Reads the Parquet schema and returns its ogc-records-parquet metadata.
It does not return the complete Arrow or GeoParquet metadata, validate
storage column types, or inspect row membership values.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/ogc_records_parquet/parquet.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
read_collections(path)
¶
Read stored collection descriptions independently of row membership.
Only schema metadata is read; Record payloads are not decoded. Descriptions
neither assign membership nor validate the IDs in __collection_id.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Source code in src/ogc_records_parquet/parquet.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
read_collection_ids(path, *, batch_size=1024)
¶
Read storage-only memberships in file row order, independently of Record JSON.
File access and validation begin on iteration. Format 1.1.0 reads only
the membership column; Record payloads are not decoded or validated. Format
1.0.0 returns unknown membership for every row, even if descriptions or
a similarly named column exist.
The file remains open until the iterator is exhausted or closed. Pair its results with records only when reading identical rows in identical order. Duplicate record IDs do not affect membership.
| Parameters: |
|
|---|
| Yields: |
|
|---|
| Raises: |
|
|---|
Source code in src/ogc_records_parquet/parquet.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
default_schema()
¶
Return stable query projections of common Records members.
All fields are nullable. The projection names are literal Arrow column names and dot-separated lookup paths in serialized Record objects.
| Field | Arrow type |
|---|---|
id |
string |
type |
string |
properties.type |
string |
properties.title |
string |
properties.description |
string |
properties.created |
string |
properties.updated |
string |
properties.keywords |
list of string |
Integer identifiers are converted to strings only in the query column. Timestamp columns contain PySTAC's serialized strings, including its normalization. Original serialized values remain authoritative in the payload. This schema does not validate OGC conformance.
| Returns: |
|
|---|
Examples:
>>> from ogc_records_parquet import default_schema
>>> schema = default_schema()
>>> schema.field("properties.title").nullable
True
>>> "__record_json" in schema.names
False
Source code in src/ogc_records_parquet/_schema.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
JSONValue = bool | int | float | str | list['JSONValue'] | dict[str, 'JSONValue'] | None
module-attribute
¶
Recursive type alias for JSON scalars, lists, objects, and null.
This alias describes generic JSON values, not an OGC Record schema. Storage validation additionally rejects non-finite floats; annotations alone cannot express that constraint. Tuples and non-string object keys are not accepted.
JSONObject = dict[str, JSONValue]
module-attribute
¶
Type alias for a JSON object with string keys and recursively JSON-compatible values.
Used for decoded file metadata and catalog descriptions. It is not a Record
model or a validation function; use OGCRecord for record manipulation.
__version__ = '0.1.0'
module-attribute
¶
Package version recorded as writer_version when a storage schema is created.
This version is independent of the OGC Records storage format and GeoParquet metadata versions. Rewriting an existing Arrow schema preserves its metadata.