shillelagh.adapters package¶
Subpackages¶
- shillelagh.adapters.api package
- Subpackages
- Submodules
- shillelagh.adapters.api.datasette module
- shillelagh.adapters.api.generic_json module
- shillelagh.adapters.api.generic_xml module
- shillelagh.adapters.api.github module
- shillelagh.adapters.api.html_table module
- shillelagh.adapters.api.preset module
- shillelagh.adapters.api.s3select module
- shillelagh.adapters.api.socrata module
- shillelagh.adapters.api.system module
- shillelagh.adapters.api.weatherapi module
WeatherAPI
WeatherAPI.chance_of_rain
WeatherAPI.chance_of_snow
WeatherAPI.cloud
WeatherAPI.dewpoint_c
WeatherAPI.dewpoint_f
WeatherAPI.feelslike_c
WeatherAPI.feelslike_f
WeatherAPI.get_cost()
WeatherAPI.get_data()
WeatherAPI.gust_kph
WeatherAPI.gust_mph
WeatherAPI.heatindex_c
WeatherAPI.heatindex_f
WeatherAPI.humidity
WeatherAPI.is_day
WeatherAPI.parse_uri()
WeatherAPI.precip_in
WeatherAPI.precip_mm
WeatherAPI.pressure_in
WeatherAPI.pressure_mb
WeatherAPI.safe
WeatherAPI.supports()
WeatherAPI.supports_limit
WeatherAPI.supports_offset
WeatherAPI.temp_c
WeatherAPI.temp_f
WeatherAPI.time
WeatherAPI.time_epoch
WeatherAPI.vis_km
WeatherAPI.vis_miles
WeatherAPI.will_it_rain
WeatherAPI.will_it_snow
WeatherAPI.wind_degree
WeatherAPI.wind_dir
WeatherAPI.wind_kph
WeatherAPI.wind_mph
WeatherAPI.windchill_c
WeatherAPI.windchill_f
combine_time_filters()
- Module contents
- shillelagh.adapters.file package
- shillelagh.adapters.memory package
Submodules¶
shillelagh.adapters.base module¶
Base class for adapters.
- class shillelagh.adapters.base.Adapter(*args: Any, **kwargs: Any)[source]¶
Bases:
object
An adapter to a table.
Adapters provide an interface to resources, so they can be queried via SQL. An adapter instance represents a virtual table, and the adapter is responsible for fetching data and metadata from the resource, and possibly insert, delete, or update rows.
In order to find an adapter responsible for a given table name, adapters need to be registered under the “shillelagh.adapter” entry point, eg:
# setup.cfg [options.entry_points] shillelagh.adapter = custom_adapter = shillelagh.adapters.api.custom:CustomAdapter
Adapters also need to implement the
supports
method. Given a table name, the method should return true if the table is supported by the adapter.- close() None [source]¶
Close the adapter.
Adapters should use this method to perform any pending changes when the connection is closed.
- delete_row(row_id: int) None [source]¶
Delete a row from the table.
This method is identical to
delete_data
, only here for symmetry.
- 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_cost(filtered_columns: List[Tuple[str, Operator]], order: List[Tuple[str, Literal[Order.ASCENDING] | Literal[Order.DESCENDING]]]) float [source]¶
Estimate the query cost.
The base adapter returns a fixed cost, and custom adapter can implement their own cost estimation.
- get_data(bounds: Dict[str, Filter], order: List[Tuple[str, Literal[Order.ASCENDING] | Literal[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 properdatetime.datetime
).Missing values (NULLs) may be omitted from the dictionary; they will be replaced by
None
by the backend.
- get_rows(bounds: Dict[str, Filter], order: List[Tuple[str, Literal[Order.ASCENDING] | Literal[Order.DESCENDING]]], **kwargs: Any) Iterator[Dict[str, Any]] [source]¶
Yield rows as native Python types.
- insert_data(row: Dict[str, Any]) int [source]¶
Insert a single row with adapter-specific types.
The rows will be formatted according to the adapter fields. Eg, if an adapter represents timestamps as ISO strings, and timestamp values will be ISO strings.
- insert_row(row: Dict[str, Any]) int [source]¶
Insert a single row with native Python types.
The row types will be converted to the native adapter types, and passed to
insert_data
.
- static parse_uri(uri: str) Tuple[Any, ...] [source]¶
Parse table name, and return arguments to instantiate adapter.
- safe = False¶
- 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 withfast=False
using only adapters that returnedNone
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.registry module¶
Registry for adapters.
Inspired by SQLAlchemy’s PluginLoader
.
- class shillelagh.adapters.registry.AdapterLoader[source]¶
Bases:
object
Adapter registry, allowing new adapters to be registered.
- load(name: str, safe: bool = False, warn: bool = False) Type[Adapter] [source]¶
Load a given entry point by its name.
- load_all(adapters: List[str] | None = None, safe: bool = False) Dict[str, Type[Adapter]] [source]¶
Load all the adapters given a list of names.
If
safe
is True all adapters must be safe and present in the list of names. Otherwise adapters can be unsafe, and if the list isNone
everything is returned.
- exception shillelagh.adapters.registry.UnsafeAdaptersError[source]¶
Bases:
InterfaceError
Raised when multiple adapters have the same name.