lynguine.access

The access module provides functionality for accessing data from various sources, including local files, web resources, and databases.

IO Module

Access-stage I/O for lynguine.

Flow-level readers (read_data, write_data, directory globs) confine configured paths with extract_full_filename / confine_configured_path before calling into file helpers (CIP-000A).

The filename helpers below (read_yaml_file, read_json_file, and the other *_file functions) are trusted-caller primitives: they open() the path they are given and do not apply allowed_roots. Untrusted or config-supplied names must be confined at the flow boundary first, not passed in raw from HTTP or interface YAML. CodeQL py/path-injection on those open() sites is a trusted-caller primitive, not a missing jail (CIP-000D cluster A).

lynguine.access.io.gzip_codec_from_name(filename)[source]

Return gzip if filename declares compression by suffix.

Parameters:

filename (str)

Return type:

str | None

lynguine.access.io.resolve_text_codec(filename, compress=None)[source]

Declare gzip from suffix and/or compress: gzip (CIP-0015).

A .yml name is never treated as gzip. compress: gzip with a non-.gz filename is an error.

Parameters:

filename (str)

Return type:

str | None

lynguine.access.io.open_text_store(filename, mode, compress=None, compress_level=6)[source]

Open a YAML/JSON store as text, optionally gzip-wrapped.

exception lynguine.access.io.PyArrowMissingError[source]

Bases: ImportError

Raised when parquet IO is requested but pyarrow is not installed.

add_note()

Exception.add_note(note) – add a note to the exception

args
msg

exception message

name

module name

path

module path

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

lynguine.access.io.parquet_codec_from_file(filename)[source]

Column codec from parquet metadata without loading the table.

Parameters:

filename (str)

Return type:

str | None

lynguine.access.io.multiline_str_representer(dumper, data)[source]
class lynguine.access.io.LynguineSafeDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]

Bases: SafeDumper

choose_scalar_style()[source]

Override to force block scalar style for multiline strings.

ANCHOR_TEMPLATE = 'id%03d'
DEFAULT_MAPPING_TAG = 'tag:yaml.org,2002:map'
DEFAULT_SCALAR_TAG = 'tag:yaml.org,2002:str'
DEFAULT_SEQUENCE_TAG = 'tag:yaml.org,2002:seq'
DEFAULT_TAG_PREFIXES = {'!': '!', 'tag:yaml.org,2002:': '!!'}
ESCAPE_REPLACEMENTS = {'\x00': '0', '\x07': 'a', '\x08': 'b', '\t': 't', '\n': 'n', '\x0b': 'v', '\x0c': 'f', '\r': 'r', '\x1b': 'e', '"': '"', '\\': '\\', '\x85': 'N', '\xa0': '_', '\u2028': 'L', '\u2029': 'P'}
classmethod add_implicit_resolver(tag, regexp, first)
classmethod add_multi_representer(data_type, representer)
classmethod add_path_resolver(tag, path, kind=None)
classmethod add_representer(data_type, representer)
analyze_scalar(scalar)
anchor_node(node)
ascend_resolver()
check_empty_document()
check_empty_mapping()
check_empty_sequence()
check_resolver_prefix(depth, path, kind, current_node, current_index)
check_simple_key()
close()
descend_resolver(current_node, current_index)
determine_block_hints(text)
dispose()
emit(event)
expect_alias()
expect_block_mapping()
expect_block_mapping_key(first=False)
expect_block_mapping_simple_value()
expect_block_mapping_value()
expect_block_sequence()
expect_block_sequence_item(first=False)
expect_document_end()
expect_document_root()
expect_document_start(first=False)
expect_first_block_mapping_key()
expect_first_block_sequence_item()
expect_first_document_start()
expect_first_flow_mapping_key()
expect_first_flow_sequence_item()
expect_flow_mapping()
expect_flow_mapping_key()
expect_flow_mapping_simple_value()
expect_flow_mapping_value()
expect_flow_sequence()
expect_flow_sequence_item()
expect_node(root=False, sequence=False, mapping=False, simple_key=False)
expect_nothing()
expect_scalar()
expect_stream_start()
flush_stream()
generate_anchor(node)
ignore_aliases(data)
increase_indent(flow=False, indentless=False)
inf_value = inf
need_events(count)
need_more_events()
open()
prepare_anchor(anchor)
prepare_tag(tag)
prepare_tag_handle(handle)
prepare_tag_prefix(prefix)
prepare_version(version)
process_anchor(indicator)
process_scalar()
process_tag()
represent(data)
represent_binary(data)
represent_bool(data)
represent_data(data)
represent_date(data)
represent_datetime(data)
represent_dict(data)
represent_float(data)
represent_int(data)
represent_list(data)
represent_mapping(tag, mapping, flow_style=None)
represent_none(data)
represent_scalar(tag, value, style=None)
represent_sequence(tag, sequence, flow_style=None)
represent_set(data)
represent_str(data)
represent_undefined(data)
represent_yaml_object(tag, data, cls, flow_style=None)
resolve(kind, value, implicit)
serialize(node)
serialize_node(node, parent, index)
write_double_quoted(text, split=True)
write_folded(text)
write_indent()
write_indicator(indicator, need_whitespace, whitespace=False, indention=False)
write_line_break(data=None)
write_literal(text)
write_plain(text, split=True)
write_single_quoted(text, split=True)
write_stream_end()
write_stream_start()
write_tag_directive(handle_text, prefix_text)
write_version_directive(version_text)
yaml_implicit_resolvers = {'': [('tag:yaml.org,2002:null', re.compile('^(?: ~\n                    |null|Null|NULL\n                    | )$', re.VERBOSE))], '!': [('tag:yaml.org,2002:yaml', re.compile('^(?:!|&|\\*)$'))], '&': [('tag:yaml.org,2002:yaml', re.compile('^(?:!|&|\\*)$'))], '*': [('tag:yaml.org,2002:yaml', re.compile('^(?:!|&|\\*)$'))], '+': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE))], '-': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE))], '.': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE))], '0': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '1': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '2': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '3': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '4': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '5': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '6': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '7': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '8': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '9': [('tag:yaml.org,2002:float', re.compile('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?\n                    |\\.[0-9][0-9_]*(?:[eE][-+][0-9]+)?\n                    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*\n                   , re.VERBOSE)), ('tag:yaml.org,2002:int', re.compile('^(?:[-+]?0b[0-1_]+\n                    |[-+]?0[0-7_]+\n                    |[-+]?(?:0|[1-9][0-9_]*)\n                    |[-+]?0x[0-9a-fA-F_]+\n                    |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9]), re.VERBOSE)), ('tag:yaml.org,2002:timestamp', re.compile('^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\n                    |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?\n                     (?:[Tt]|[ \\t]+)[0-9][0-9]?\n                     :[0-9][0-9], re.VERBOSE))], '<': [('tag:yaml.org,2002:merge', re.compile('^(?:<<)$'))], '=': [('tag:yaml.org,2002:value', re.compile('^(?:=)$'))], 'F': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'N': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE)), ('tag:yaml.org,2002:null', re.compile('^(?: ~\n                    |null|Null|NULL\n                    | )$', re.VERBOSE))], 'O': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'T': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'Y': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'f': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'n': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE)), ('tag:yaml.org,2002:null', re.compile('^(?: ~\n                    |null|Null|NULL\n                    | )$', re.VERBOSE))], 'o': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 't': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], 'y': [('tag:yaml.org,2002:bool', re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE))], '~': [('tag:yaml.org,2002:null', re.compile('^(?: ~\n                    |null|Null|NULL\n                    | )$', re.VERBOSE))]}
yaml_multi_representers = {}
yaml_path_resolvers = {}
yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function multiline_str_representer>, <class 'tuple'>: <function SafeRepresenter.represent_list>, None: <function SafeRepresenter.represent_undefined>}
lynguine.access.io.str_type()[source]
lynguine.access.io.bool_type()[source]
lynguine.access.io.int_type()[source]
lynguine.access.io.float_type()[source]
lynguine.access.io.extract_dtypes(details)[source]

Extract dtypes from directory.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The dtypes.

Return type:

dict

lynguine.access.io.extract_sheet(details, gsheet=True)[source]

Extract the sheet name from details

Parameters:
  • details (dict) – The details of the file to be read.

  • gsheet (bool) – Whether to use gspread_pandas.

lynguine.access.io.read_json(details)[source]

Read data from a json file.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.write_json(df, details)[source]

Write data to a json file.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.read_yaml(details)[source]

Read data from a yaml file.

A top-level YAML mapping is always treated as a single-row table (constants / parameters). All-scalar maps keep an explicit index (default value). Maps with nested dict/list values become one row with those values as cell objects, matching read_markdown.

Optional fields projects the document before the row is formed (top-level keys, dotted paths, or field + path / liquid).

A YAML sequence of mappings remains a multi-row table.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

Raises:

ValueError – If the document is neither a mapping nor a sequence.

lynguine.access.io.read_markdown(details)[source]

Read data from a markdown file.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.write_markdown(df, details)[source]

Write data to a markdown file.

Parameters:
  • df (pandas.DataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.write_yaml(df, details)[source]

Write data to a yaml file.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.read_bibtex(details)[source]

Read data from a bibtex file.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.write_bibtex(df, details)[source]

Write data to a bibtex file.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.read_directory(details, filereader=None, filereader_args={}, default_glob='*', source=None)[source]

Read data from a directory of files.

Opt-in recursive: true on a source entry (or on details) enables glob.glob(..., recursive=True) so patterns such as **/*.yml walk nested trees. Default is non-recursive; ** is only meaningful when recursive is true (CIP-000F).

Opt-in fields on a source entry (or on details) projects each mapping-valued file to the listed top-level keys before normalize (CIP-000F). Absent fields keeps full-document behaviour.

include_start_directory (source entry or details, default True) controls whether matches whose immediate parent is the source directory itself are kept. Set False for descendants-only discovery (e.g. nested **/_referia.yml without the file in .).

Opt-in exclude (source entry or details, list of glob strings) drops matches whose path relative to the source directory matches any pattern after glob / regexp / include_start_directory (CIP-0018). today/** omits that directory and everything under it. Absent or empty exclude keeps today’s match set.

Parameters:
  • details (dict) – The details of the directory to be read.

  • filereader (function) – The function to be used to read the file.

  • filereader_args (dict) – The arguments to be passed to the filereader.

  • default_glob (str) – The default glob to be used if none is specified.

  • source (dict) – The source information for the data.

Raises:

ValueError – if the same filename is specified multiple times.

lynguine.access.io.read_list(filelist)[source]

Read from a list of files.

Trusted-caller API: entries in filelist are not confined here. Directory-glob flow paths confine before calling read_files.

Parameters:

filelist (list) – The list of files to be read.

Returns:

The data read from the files.

Return type:

pandas.DataFrame

lynguine.access.io.read_files(filelist, store_fields=None, filereader=None, filereader_args=None, fields=None, source_directory=None)[source]

Read files from a given list.

Trusted-caller API: this function does not apply allowed_roots. Callers that have configuration or request-derived names must confine each path first (CIP-000A).

When fields is set, each mapping-valued payload is reduced to those top-level keys before path store_fields are appended (CIP-000F).

Parameters:
  • filelist (list) – The list of files to be read.

  • store_fields (dict) – The fields to be stored in the data.

  • filereader (function) – The function to be used to read the file.

  • filereader_args (dict) – The arguments to be passed to the filereader.

  • fields (list or None) – Optional list of top-level keys to keep from each mapping.

  • source_directory (str or None) – Glob root used to compute sourceDirectory relative to the catalog, not cwd (CIP-0018).

Returns:

The data read from the files.

Return type:

pandas.DataFrame

lynguine.access.io.write_directory(df, details, filewriter=None, filewriter_args={})[source]

Write scoring data to a directory of files.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

  • filewriter (function) – The function to be used to write the file.

  • filewriter_args (dict) – The arguments to be passed to the filewriter.

Raises:

ValueError – if the same filename is specified multiple times.

lynguine.access.io.read_json_file(filename, compress=None)[source]

Read a json file and return a python dictionary.

Trusted-caller I/O: does not confine filename. Configured or untrusted names must go through extract_full_filename first (CIP-000A).

Parameters:
  • filename (str) – The filename of the json file.

  • compress – Optional gzip; suffix .json.gz also selects gzip.

Returns:

The data read from the file.

Return type:

dict

lynguine.access.io.write_json_file(data, filename, compress=None, compress_level=6)[source]

Write a json file from a python dictionary.

Trusted-caller I/O: does not confine filename (CIP-000A).

lynguine.access.io.read_txt_file(filename)[source]

Read a text file and return a dictionary with the content.

Trusted-caller I/O: does not confine filename (CIP-000A).

lynguine.access.io.default_file_reader(typ)[source]

Return the default file reader for a given type.

Parameters:

typ (str) – The type of file to be read.

Returns:

The default file reader.

Return type:

function

Raises:

ValueError – if the type is not recognised.

lynguine.access.io.default_file_writer(typ)[source]

Return the default file writer for a given type.

Parameters:

typ (str) – The type of file to be written.

Returns:

The default file writer.

Return type:

function

Raises:

ValueError – if the type is not recognised.

lynguine.access.io.read_file(filename)[source]

“Attempt to read the file given the extention.

lynguine.access.io.is_markdown_yaml_path(filename)[source]

True when filename is a markdown file used as a YAML store.

lynguine.access.io.read_yaml_file(filename, compress=None)[source]

Read a yaml file and return a python dictionary.

Trusted-caller I/O: does not confine filename. Configured or untrusted names must go through extract_full_filename first (CIP-000A). .yml.gz is gzip YAML (CIP-0015); a .yml file whose bytes are gzip is an error (no magic-byte decode).

A .md / .markdown path is YAML frontmatter plus a body. The body is stored as content so the file is a YAML mapping with one extra field, not a second document that safe_load would drop.

lynguine.access.io.read_bibtex_file(filename)[source]

Read a bibtex file and return a python dictionary.

Trusted-caller I/O: does not confine filename (CIP-000A).

Parameters:

filename (str) – The filename of the bibtex file.

Returns:

The data read from the file.

Return type:

dict

lynguine.access.io.yaml_prep(data)[source]

Prepare any fields for writing in yaml

Parameters:

data (dict) – The data to be prepared.

Returns:

The prepared data.

Return type:

dict

lynguine.access.io.write_bibtex_file(data, filename)[source]

Write a bibtex file from a python dictionary.

Trusted-caller I/O: does not confine filename (CIP-000A).

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the bibtex file.

lynguine.access.io.write_yaml_file(data, filename, compress=None, compress_level=6)[source]

Write a yaml file from a python dictionary.

Trusted-caller I/O: does not confine filename (CIP-000A). .yml.gz writes gzip YAML (CIP-0015).

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the yaml file.

lynguine.access.io.read_yaml_meta_file(filename)[source]

Read meta information associated with a file as a yaml and return a python dictionary if it exists.

Parameters:

filename (str) – The filename of the file.

Returns:

The meta information.

Return type:

dict

lynguine.access.io.write_yaml_meta_file(data, filename)[source]

Write meta information associated with a file to a yaml.

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the file.

lynguine.access.io.read_markdown_file(filename, include_content=True)[source]

Read a markdown file and return a python dictionary.

Trusted-caller I/O: does not confine filename (CIP-000A).

Parameters:
  • filename (str) – The filename of the markdown file.

  • include_content (bool) – Whether to include the content in the data.

Returns:

The data read from the file.

Return type:

dict

lynguine.access.io.read_docx_file(filename, include_content=True)[source]

Read information from a docx file.

Parameters:
  • filename (str) – The filename of the docx file.

  • include_content (bool) – Whether to include the content in the data.

Returns:

The data read from the file.

Return type:

dict

lynguine.access.io.read_talk_file(filename, include_content=True)[source]

Read a markdown talk file.

Parameters:
  • filename (str) – The filename of the talk file.

  • include_content (bool) – Whether to include the content in the data.

Returns:

The data read from the file.

lynguine.access.io.read_talk_include_file(filename, include_content=True)[source]

Read a markdown talk include file.

Parameters:
  • filename (str) – The filename of the talk include file.

  • include_content (bool) – Whether to include the content in the data.

Returns:

The data read from the file.

lynguine.access.io.write_url_file(data, filename, content, include_content=True)[source]

Write a url to a file

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the url file.

  • content (str) – The content of the url file.

  • include_content (bool) – Whether to include the content in the data.

lynguine.access.io.write_markdown_file(data, filename, content=None, include_content=True)[source]

Write a markdown file from a python dictionary

Trusted-caller I/O: does not confine filename (CIP-000A).

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the markdown file.

  • content (str) – The content of the markdown file.

  • include_content (bool) – Whether to include the content in the data.

lynguine.access.io.create_document_content(**kwargs)[source]

Create a document content from the arguments. :param content: The content of the document. :type content: str :param filename: The filename of the document. :type filename: str :param directory: The directory of the document. :type directory: str :return: The data, filename and content of the document. :rtype: tuple

lynguine.access.io.create_letter(**kwargs)[source]

Create a markdown letter. :param content: The content of the letter. :type content: str :param filename: The filename of the letter. :type filename: str :param directory: The directory of the letter. :type directory: str :return: The data, filename and content of the letter. :rtype: tuple

lynguine.access.io.write_letter_file(data, filename, content, include_content=True)[source]

Write a letter file from a python dictionary

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the letter.

  • content (str) – The content of the letter.

  • include_content (bool) – Whether to include the content in the data.

Write a url to prepopulate a Google form

lynguine.access.io.write_docx_file(data, filename, content, include_content=True)[source]

Write a docx file from a python dictionary.

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the docx file.

  • content (str) – The content of the docx file.

  • include_content (bool) – Whether to include the content in the data.

lynguine.access.io.write_tex_file(data, filename, content, include_content=True)[source]

Write a docx file from a python dictionary.

Parameters:
  • data (dict) – The data to be written.

  • filename (str) – The filename of the docx file.

  • content (str) – The content of the docx file.

  • include_content (bool) – Whether to include the content in the data.

lynguine.access.io.read_csv(details)[source]

Read data from a csv file.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.read_parquet(details)[source]

Read a parquet table (CIP-0015 phase 2). Requires lynguine[parquet].

lynguine.access.io.read_excel(details)[source]

Read data from an excel spreadsheet.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.read_fake(details)[source]

Read data from an artificially generated source.

When index names a generated column, later duplicate values in that column are disambiguated so the frame keeps nrows after from_flow sets the index.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read from the source.

Return type:

pandas.DataFrame

lynguine.access.io.read_local(details)[source]

Read data directly from details file.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read from the settings file..

Return type:

pandas.DataFrame

Raises:

ValueError – If the ‘details’ is not a dictionary or is missing required keys.

lynguine.access.io.read_gsheet(details)[source]

Read data from a Google sheet using secure credential management.

Parameters:

details (dict) – The details of the file to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

Raises:

ValueError – If credentials cannot be retrieved

lynguine.access.io.write_excel(df, details)[source]

Write data to an excel spreadsheet.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.write_csv(df, details)[source]

Write data to an csv spreadsheet.

The path is confined via extract_full_filename (CIP-000A). The following open() is still a trusted-caller primitive as far as CodeQL is concerned (CIP-000D cluster A).

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

lynguine.access.io.write_parquet(df, details)[source]

Write a parquet table with list<float32> numeric list columns.

Requires lynguine[parquet]. Default codec is snappy; set compress: zstd (or gzip/brotli/lz4/none) to override.

lynguine.access.io.write_gsheet(df, details)[source]

Write data to a Google sheet using secure credential management.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the file to be written.

Raises:

ValueError – If credentials cannot be retrieved

lynguine.access.io.gdrf_(default_glob, filereader, name='', docstr='')[source]

Function generator for different directory readers.

Parameters:
  • default_glob (str) – The default glob to be used for the directory reader.

  • filereader (function) – The function to be used to read the files.

  • name (str) – The name of the function to be created.

  • docstr (str) – The docstring for the function to be created.

Returns:

The function to be created.

Return type:

function

lynguine.access.io.update_store_fields(details)[source]

Add default store fields values

Parameters:

details (dict) – The details to update with.

Returns:

The updated details.

Return type:

dict

lynguine.access.io.gdwf_(filewriter, name='', docstr='')[source]

Function generator for different directory writers.

Parameters:
  • filewriter (function) – The function to be used to write the files.

  • name (str) – The name of the function to be created.

  • docstr (str) – The docstring for the function to be created.

Returns:

The function to be created.

Return type:

function

lynguine.access.io.populate_directory_readers(readers)[source]

Populate the directory readers automatically creates functions for reading directories.

Parameters:

readers (list) – The readers to be created.

lynguine.access.io.populate_directory_writers(writers)[source]

This function automatically create functions for writing directories.

Parameters:

writers (list) – The writers to be created.

lynguine.access.io.finalize_data(df, interface)[source]

Finalize the data frame by augmenting with any columns.

Parameters:
Returns:

The finalized data frame.

Return type:

pandas.DataFrame or lynguine.data.CustomDataFrame

lynguine.access.io.read_hstack(details)[source]

Read data from a horizontal stack of data sources.

Sources join left to right. Two-way overlaps keep the left column and suffix the right (default _right). A later source that would recreate an existing suffixed name is dropped: earlier columns win.

Optional per-right-specification normalize: casefold joins on Unicode-casefolded keys while preserving left-side orthography (CIP-001C). Omit the key for case-sensitive (pandas-compatible) joins.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.read_stack(details)[source]

Read data from a horizontal stack of data series, where each source is a single-row DataFrame. Returns a single-row DataFrame combining all sources.

Parameters:

details (dict) – The details of the data series to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.read_vstack(details)[source]

Read data from a vertical stack of data sources.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read from the file.

Return type:

pandas.DataFrame

lynguine.access.io.read_series(details)[source]

Read in the series data from the details given in configuration. A series type is a data frame where the indices aren’t unique. If read in as a series, then each entry in each column of data frame is converted to a list, where the number of elements of the list are the number of non-unique elements from the index.

Parameters:

details (dict) – The details of the series data to be read.

Returns:

The data read in.

Return type:

pandas.DataFrame

lynguine.access.io.compose_wide_column_name(key, field, *, separator='_', order='index_then_field')[source]

Build a wide column name from index key and field (CIP-0010).

Parameters:
Return type:

str

lynguine.access.io.parse_wide_column_name(name, *, separator='_', order='index_then_field', keys, fields=None)[source]

Parse a wide column name into (key, field) (CIP-0010 Pattern A).

keys are the authoritative index labels (e.g. from flattenKeys). Matching prefers longer key strings so one key is not a prefix of another. When fields is given, names must match an exact key/field composition; otherwise the remainder after the key+separator is the field name.

Returns:

(key, field) where key is the object from keys.

Parameters:
lynguine.access.io.wide_flatten_dataframe(df, *, separator='_', order='index_then_field', columns=None, keys_field='flattenKeys')[source]

Reshape many rows into one row with index-augmented column names (CIP-0010).

Turns an N × M DataFrame with a unique index into a 1 × (N×M) frame whose column names are {index}{separator}{field} (or {field}{separator}{index} when order is field_then_index).

When keys_field is set (default flattenKeys), the wide row also carries an ordered list of former index labels for Liquid/view loops. Pass keys_field=None to omit that column.

Empty input (no rows) yields a single empty row (plus empty keys_field list when enabled). Optional columns selects value fields to widen; other columns are dropped (not kept as globals).

v1 policy: separator must not appear in str(index) labels so names stay unambiguously splittable.

Parameters:
  • df (DataFrame) – Source frame; the current index labels identify each former row.

  • separator (str) – Joiner between index and field in output names.

  • order (str) – index_then_field or field_then_index.

  • columns (list | None) – Optional subset of value columns to widen.

  • keys_field (str | None) – Column name for the ordered key list, or None to omit.

Returns:

Single-row DataFrame with flat string column names.

Raises:

ValueError – On invalid order, non-unique index, unknown columns, keys field collision, or separator in an index label.

Return type:

DataFrame

lynguine.access.io.wide_unflatten_dataframe(wide, *, separator='_', order='index_then_field', keys_field='flattenKeys', fields=None)[source]

Inverse of materialized wide_flatten_dataframe() (CIP-0010 Pattern B).

Rebuilds a tall frame from a single wide row. Uses keys_field (default flattenKeys) for index labels when present; otherwise keys must be recoverable from column names via fields or parse rules.

Not the default Save path for catalogs — prefer Pattern A virtual views.

Parameters:
  • wide (DataFrame)

  • separator (str)

  • order (str)

  • keys_field (str | None)

  • fields (list | None)

Return type:

DataFrame

lynguine.access.io.wide_view_get(data, wide_name, *, separator='_', order='index_then_field', keys=None, fields=None)[source]

Get a tall-store cell via a wide column name (CIP-0010 Pattern A).

Does not reshape data. For CustomDataFrame uses focus set_index / set_column / get_value; for a plain DataFrame uses label-based .at.

Parameters:
  • wide_name (str)

  • separator (str)

  • order (str)

lynguine.access.io.wide_view_set(data, wide_name, value, *, separator='_', order='index_then_field', keys=None, fields=None)[source]

Set a tall-store cell via a wide column name (CIP-0010 Pattern A).

Does not reshape data. Shape (nrows, ncols) is unchanged.

Parameters:
  • wide_name (str)

  • separator (str)

  • order (str)

lynguine.access.io.read_wide_flatten(details)[source]

Read a nested data source then wide-flatten to one row (CIP-0010).

Loads specifications via read_data (so nested compute runs through finalize_data), promotes a nested tall index when needed, then applies wide_flatten_dataframe(). The outer finalize_data in read_data() may then run compute on the wide row.

This is a materialized snapshot (Pattern B). For editable catalogs, prefer tall store + wide_view_get() / wide_view_set() (Pattern A).

Parameters:

details (dict) – Must include type: wide_flatten and specifications. Optional: separator (default _), order (default index_then_field), columns, index (label of the singleton wide row — same role as wrapping index on stack / local; omit for legacy 0), keys_field (default flattenKeys; set false/null to omit). Tall identity before flatten comes from nested specifications.index (column promoted via set_index) or from the nested frame’s existing index.

Returns:

Single-row DataFrame with index-augmented column names.

Return type:

pandas.DataFrame

lynguine.access.io.read_data(details)[source]

Read in the data from the details given in configuration.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read in.

Return type:

pandas.DataFrame

lynguine.access.io.read_auto(details)[source]

Read in the data from the details given in configuration. Use the file extension to determine the type of data to read.

Parameters:

details (dict) – The details of the data to be read.

Returns:

The data read in.

Return type:

pandas.DataFrame

lynguine.access.io.convert_data(read_details, write_details)[source]

Convert a data set from one form to another.

Parameters:
  • read_details (dict) – The details of the data to be read.

  • write_details (dict) – The details of the data to be written.

lynguine.access.io.data_exists(details)[source]

Check if a particular data structure exists or needs to be created.

Parameters:

details (dict) – The details of the data to be checked.

Returns:

Whether the data exists or not.

Return type:

bool

lynguine.access.io.load_or_create_df(details, index)[source]

Load in a data frame or create it if it doesn’t exist yet.

Parameters:
  • details (dict) – The details of the data to be loaded or created.

  • index (pandas.Index) – The index to be used if the data frame needs to be created.

Returns:

The data frame.

lynguine.access.io.globals_data(details, index=None)[source]

Load in the globals data to a data frame.

Parameters:

details (dict) – The details of the data to be loaded.

lynguine.access.io.cache(details, index=None)[source]

Load in the cache data to a data frame.

Parameters:

details (dict) – The details of the data to be loaded.

lynguine.access.io.scores(details, index=None)[source]

Load in the score data to data frames.

Parameters:

details (dict) – The details of the data to be loaded.

lynguine.access.io.series(details, index=None)[source]

Load in a series to data frame

Parameters:

details (dict) – The details of the data to be loaded.

lynguine.access.io.explode_list_field(df, field, inherit=None, index=None)[source]

Expand a list-of-mappings column into one row per item (CIP-0014).

Parent columns listed in inherit are copied onto every child row. The list field itself is not kept. Child mapping keys become columns.

Return type:

DataFrame

lynguine.access.io.pack_dataframe(df, columns, index_value='corpus', index_name='Name', drop_incomplete=False, incomplete_field='embedding')[source]

Stack selected columns into one row of aligned array cells (CIP-0014).

Return type:

DataFrame

lynguine.access.io.omit_nested_keys_frame(df, details)[source]

Copy list-of-dict cells without bulky nested keys (CIP-0014 write).

omit_nested_keys maps a column name to keys to strip, e.g. extraction_phrases: [embedding]. The source frame is not mutated, so in-memory embeddings remain available for pack on the same Save.

lynguine.access.io.omit_columns_frame(df, details)[source]

Drop write-only-ignored columns (e.g. embedding) without mutating source.

lynguine.access.io.reshape_for_write(df, details)[source]

Apply CIP-0014 explode / pack declared on a store, then write.

Return type:

DataFrame

lynguine.access.io.store_stat(details)[source]

File facts for a named store without loading the table (CIP-0015).

Return type:

dict

lynguine.access.io.write_data(df, details)[source]

Write the data using the details given in configuration.

Parameters:
  • df (pandas.DataFrame or lynguine.data.CustomDataFrame) – The data to be written.

  • details (dict) – The details of the data to be written.

lynguine.access.io.read_bibtex_directory(details)

Read a directory of bibtex files.

lynguine.access.io.read_docx_directory(details)

Read a directory of word files.

lynguine.access.io.read_json_directory(details)

Read a directory of json files.

lynguine.access.io.read_markdown_directory(details)

Read a directory of markdown files.

lynguine.access.io.read_meta_directory(details)

Read a directory of yaml meta files.

lynguine.access.io.read_plain_directory(details)

Read a directory of files.

lynguine.access.io.read_yaml_directory(details)

Read a directory of yaml files.

lynguine.access.io.write_json_directory(df, details)

Write a directory of json files.

lynguine.access.io.write_markdown_directory(df, details)

Write a directory of markdown files.

lynguine.access.io.write_meta_directory(df, details)

Write a directory of yaml meta files.

lynguine.access.io.write_yaml_directory(df, details)

Write a directory of yaml files.

IO Types (CIP-0019)

Tabular IO type registry (CIP-0019).

Builtin type: values stay in read_data / write_data. Packages outside lynguine register extra names with register_io_type. This is the table-store sibling of CIP-0013 register_strategy (documents).

Do not import this module for its side effects from import lynguine. Entry points in group lynguine.io_types load only when a matching type: is requested and is not already registered.

exception lynguine.access.io_types.ReservedIOTypeError[source]

Bases: ValueError

Raised when a plugin tries to register a builtin type: name.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lynguine.access.io_types.ReadOnlyIOTypeError[source]

Bases: ValueError

Raised when write_data is asked to write a read-only type.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lynguine.access.io_types.UnknownIOTypeError[source]

Bases: ValueError

Raised when get_io_type is asked for an unregistered name.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lynguine.access.io_types.PluginImportError[source]

Bases: ValueError

Raised when a plugins: module or entry point fails to load.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception lynguine.access.io_types.MissingIOCredentialError[source]

Bases: ValueError

Raised when a plugin type needs credential: and the item omitted it.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class lynguine.access.io_types.IOType(name, read, write=None, credential_type=None)[source]

Bases: object

Registered tabular reader, and optional writer, for one type:.

Parameters:
name: str
read: Callable[[dict], DataFrame]
write: Callable[[DataFrame, dict], None] | None = None
credential_type: str | None = None
lynguine.access.io_types.is_reserved_io_type(name)[source]

Return True if name is a lynguine builtin type:.

Parameters:

name (str)

Return type:

bool

lynguine.access.io_types.register_io_type(name, *, read, write=None, credential_type=None)[source]

Register a tabular IO type.

Replaces any prior plugin entry with the same name. Builtin names in RESERVED_IO_TYPES cannot be registered.

credential_type is a CIP-0005 validator kind (for example google_oauth or trello_api). When set, lynguine fetches the secret named by the item’s credential: key and passes the payload to the plugin as details["credential_value"]. The plugin does not call CredentialManager itself.

Parameters:
  • name (str)

  • credential_type (str | None)

Return type:

IOType

lynguine.access.io_types.get_io_type(name)[source]

Return the registered spec for name, or raise UnknownIOTypeError.

Parameters:

name (str)

Return type:

IOType

lynguine.access.io_types.list_io_types()[source]

Return registered plugin type names, sorted.

Return type:

list[str]

lynguine.access.io_types.plugins_from_mapping(mapping)[source]

Extract plugins: module names from a details dict or Interface.

Return type:

list[str]

lynguine.access.io_types.load_plugins(names, *, needed_type=None)[source]

Import listed plugin modules so they can call register_io_type.

Failed imports name the module. Other exceptions from the module propagate unchanged.

Parameters:

needed_type (str | None)

Return type:

None

lynguine.access.io_types.unknown_io_type_message(kind, ftype)[source]

Error text for an unknown type:; includes registered plugin names.

Parameters:
Return type:

str

lynguine.access.io_types.resolve_registered_io_type(name)[source]

Return a plugin spec for name, loading a matching entry point if needed.

Builtin reserved names are never resolved here, even if an entry point claims them.

Parameters:

name (str)

Return type:

IOType | None

lynguine.access.io_types.bind_plugin_credentials(details, spec, *, operation)[source]

Resolve CIP-0005 secrets for a plugin that declared credential_type.

YAML credential: names the stored key. The registered credential_type is the validator kind. Returns a shallow copy of details with credential_value set to the stored payload (the value field when present). Types with no credential_type are returned unchanged.

Parameters:
Return type:

dict

lynguine.access.io_types.try_read_registered_type(details, ftype)[source]

Read via a plugin if ftype is registered. None means use builtins.

Parameters:

ftype (str)

Return type:

DataFrame | None

lynguine.access.io_types.try_write_registered_type(df, details, ftype)[source]

Write via a plugin if ftype is registered. False means use builtins.

A registered type never falls through to a file writer. Write still requires both a registered write callable and write: true on the item.

Parameters:
  • df (DataFrame)

  • ftype (str)

Return type:

bool

Download Module

lynguine.access.download.load_data_resources_catalogue(catalogue_path, item=None)[source]

Load a pods-style data-resources catalogue from a local JSON path.

Accepts either a dict keyed by dataset name (data_resources.json) or a mapping with a top-level datasets list of entries that each include name.

lynguine.access.download.materialise_data_resources(item, remote, interface=None, prompt=None)[source]

Expand a named pods catalogue entry into cached files (ods CIP-0003).

lynguine.access.download.authorize_remote(remote, interface=None, *, label='remote', prompt=None)[source]

Prompt for licence acknowledgement before a remote materialise.

Honours overide_manual_authorize on the interface for non-interactive runs (CIP-0009).

lynguine.access.download.download_url_to(url, save_path, *, suffix='')[source]

HTTP(S) GET url and write the body to save_path.

lynguine.access.download.clone_or_pull_repo(git_url, repo_path)[source]

Clone git_url into repo_path, or pull if a .git dir exists.

lynguine.access.download.materialise(item, interface=None, prompt=None)[source]

Materialise a remote: artefact before the local type: read.

When item has no remote key, returns None (no-op), unless source is a legacy remote mapping (type: url|github), which raises a migration error pointing at remote:.

Parameters:
  • item – Access-stage data item (may be a list of items).

  • interface – Optional Interface for authorize overrides.

  • prompt – Optional yes/no prompt callable.

Returns:

Local path materialised or confirmed, a list of paths for list items, or None when there is nothing to materialise.

class lynguine.access.download.FileDownloader(interface, data_resources, data_name)[source]

Bases: object

A class for downloading data files from a url.

Initialize the FileDownloader class. :param data_resources: The data resources dictionary. :param data_name: The name of the data to download.

property interface

Return the interface object. :return: The interface object.

property data_name

Return the name of the data to download. :return: The name of the data to download.

property data_resources

Return the data resources dictionary. :return: The data resources dictionary.

download_data(prompt=<function prompt_stdin>)[source]

Check with the user that they are happy with terms and conditions for the data, then download it. :param prompt: A function that takes a string and returns a boolean. :return: None :raises: ValueError if the data is not found.

class lynguine.access.download.GitDownloader(interface, data_resources, data_name, git_url)[source]

Bases: FileDownloader

Initialize the FileDownloader class. :param data_resources: The data resources dictionary. :param data_name: The name of the data to download.

property data_name

Return the name of the data to download. :return: The name of the data to download.

property data_resources

Return the data resources dictionary. :return: The data resources dictionary.

download_data(prompt=<function prompt_stdin>)

Check with the user that they are happy with terms and conditions for the data, then download it. :param prompt: A function that takes a string and returns a boolean. :return: None :raises: ValueError if the data is not found.

property interface

Return the interface object. :return: The interface object.