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

odata_literal(value)

value written as an OData $filter literal.

Classes

ODataReader(service, entity, *, key[, ...])

The records of entity at service, as {key value: record}.

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: Mapping

The records of entity at service, 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’s filter.

  • select (Iterable[str] | None) – The properties a record holds. None fetches all of them; a wide list is split into column groups under max_url for bulk reads.

  • filter (str | None) – A $filter scoping 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 (see odatadol.read.entity_columns()).

  • credentials (Union[None, _HasHeader, Callable[[], Any]]) – None, a BasicAuth or BearerToken, 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 $filter literal, for store[k] and k in store. Defaults to odata_literal(); an Edm.Guid key read back as text by iteration needs literal=str. Raises TypeError for a key it cannot write, which the reader reports as missing.

  • parse_float (Callable[[str], Any] | None) – Applied to fractional JSON numbers (decimal.Decimal keeps every digit).

items()[source]#

Every (key, record), read in bulk.

Return type:

ItemsView

values()[source]#

Every record, read in bulk.

Return type:

ValuesView

odatadol.store.odata_literal(value)[source]#

value written as an OData $filter literal.

>>> 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 str is always a quoted string literal: pass a uuid.UUID for an Edm.Guid and a datetime object for a date or time.

Return type:

str