odatadol.store#
A read-only Mapping over one OData entity set, keyed on a declared key.
ODataReader is a thin facade over odatadol.read: len is one
$count, iterating reads only the key column, store[k] and k in store are one
filtered request each, and items()/values() read in bulk (column groups joined on
the key when select is wide), never one request per key.
>>> from odatadol.testing import FakeService
>>> server = FakeService([{'ProductID': 1, 'Name': 'Tea'}, {'ProductID': 2, 'Name': 'Jam'}])
>>> store = ODataReader('https://example.com/odata', 'Products', key='ProductID',
... fetch=server)
>>> len(store), list(store), store[2]
(2, [1, 2], {'ProductID': 2, 'Name': 'Jam'})
>>> 3 in store
False
Writes are not here, and not behind a flag: a writer, if one is ever needed, is a separate class, so code holding a reader cannot reach one by passing the wrong argument.
Functions
|
|
Classes
|
The records of |
- class odatadol.store.ODataReader(service, entity, *, key, select=None, filter=None, version=None, credentials=None, fetch=None, max_url=2000, page_size=1000, parse_float=None, literal=None)[source]#
Bases:
MappingThe records of
entityatservice, as{key value: record}.- Parameters:
service (
str) – The OData service root URL.entity (
str) – The entity set name.key (
str) – The property records are addressed, ordered and joined by. It must be unique and never empty within the reader’sfilter.select (
Iterable[str] |None) – The properties a record holds.Nonefetches all of them; a wide list is split into column groups undermax_urlfor bulk reads.filter (
str|None) – A$filterscoping the reader: keys outside it are not in it.version (
str|None) – A property rewritten on every edit, checked per key across column groups so a bulk read is one moment (seeodatadol.read.entity_columns()).credentials (
Union[None,_HasHeader,Callable[[],Any]]) –None, aBasicAuthorBearerToken, or a callable returning one.fetch (
Callable[[str,Mapping[str,str]],tuple[int,bytes]] |None) – The transport,(url, headers) -> (status, bytes).literal (
Callable[[Any],str] |None) – Writes a key as a$filterliteral, forstore[k]andk in store. Defaults toodata_literal(); anEdm.Guidkey read back as text by iteration needsliteral=str. RaisesTypeErrorfor a key it cannot write, which the reader reports as missing.parse_float (
Callable[[str],Any] |None) – Applied to fractional JSON numbers (decimal.Decimalkeeps every digit).
- odatadol.store.odata_literal(value)[source]#
valuewritten as an OData$filterliteral.>>> odata_literal("O'Brien"), odata_literal(42), odata_literal(True) ("'O''Brien'", '42', 'true') >>> odata_literal(float('nan')), odata_literal(Decimal('1E+2')) ('NaN', '100') >>> odata_literal(uuid.UUID(int=1)), odata_literal(datetime.date(2026, 1, 2)) ('00000000-0000-0000-0000-000000000001', '2026-01-02')
A
stris always a quoted string literal: pass auuid.UUIDfor anEdm.Guidand adatetimeobject for a date or time.- Return type: