shillelagh.adapters.memory package

Submodules

shillelagh.adapters.memory.holidays module

shillelagh.adapters.memory.pandas module

shillelagh.adapters.memory.virtual module

An adapter for data generated on-the-fly.

class shillelagh.adapters.memory.virtual.VirtualMemory(cols: dict[str, str], start: str, rows: int)[source]

Bases: Adapter

An adapter for data generated on-the-fly:

🍀> SELECT * FROM “virtual://?cols=id:int,t:day&rows=10”;

get_columns() dict[str, Field][source]

Return the columns available in the table.

This method is called for every query, so make sure it’s cheap. For most (all?) tables this won’t change, so you can store it in an instance attribute.

get_data(bounds: dict[str, Filter], order: list[tuple[str, Literal[Order.ASCENDING, Order.DESCENDING]]], **kwargs: Any) Iterator[dict[str, Any]][source]

Yield rows as adapter-specific types.

This method expects rows to be in the storage format. Eg, for the CSV adapter datetime columns would be stored (and yielded) as strings. The get_rows method will use the adapter fields to convert these values into native Python types (in this case, a proper datetime.datetime).

Missing values (NULLs) may be omitted from the dictionary; they will be replaced by None by the backend.

static parse_uri(uri: str) tuple[dict[str, str], str, int][source]

Parse table name, and return arguments to instantiate adapter.

safe = True
static supports(uri: str, fast: bool = True, **kwargs: Any) bool | None[source]

Return if a given table is supported by the adapter.

The discovery is done in 2 passes. First all adapters have their methods called with fast=True. On the first pass adapters should implement a cheap method, without any network calls.

If no adapter returns True a second pass is made with fast=False using only adapters that returned None on the first pass. In this second pass adapters can perform network requests to get more information about the URI.

The method receives the table URI, as well as the adapter connection arguments, eg:

>>> from shillelagh.backends.apsw.db import connect
>>> connection = connect(
...     ':memory:',
...     adapter_kwargs={"gsheetsapi": {"catalog":
...         {"table": "https://docs.google.com/spreadsheets/d/1/"}}},
... )

This would call all adapters in order to find which one should handle the table table. The Gsheets adapter would be called with:

>>> from shillelagh.adapters.api.gsheets.adapter import GSheetsAPI
>>> GSheetsAPI.supports("table", fast=True,  # first pass
...     catalog={"table": "https://docs.google.com/spreadsheets/d/1"})
True
supports_limit = False
supports_offset = False
supports_requested_columns = False
shillelagh.adapters.memory.virtual.int_to_base26(n: int) str[source]

Convert 0→a, 1→b, …, 25→z, 26→aa, etc.

shillelagh.adapters.memory.virtual.make_seq(delta: Any) Iterator[source]

Generate a sequence of values starting from 0, incrementing by delta.

Module contents