latch.registry package#
Subpackages#
Submodules#
latch.registry.project module#
- class latch.registry.project.Project(id: str)[source]#
Bases:
object
Registry project (folder containing
tables
).list_registry_projects()
is the typical way to get aProject
.- load() None [source]#
(Re-)populate this project instance’s cache.
Future calls to most getters will return immediately without making a network request.
Always makes a network request.
- get_display_name(*, load_if_missing: Literal[True] = 'True') str [source]#
- get_display_name(*, load_if_missing: bool) Optional[str]
Get the display name of this project.
This is an opaque string that can contain any valid Unicode data.
Display names are not unique and must never be used as identifiers. Use
id
instead.- Parameters
load_if_missing – If true,
load()
the display name if not in cache. If false, return None if not in cache.- Returns
Display name.
- list_tables(*, load_if_missing: Literal[True] = 'True') List[latch.registry.table.Table] [source]#
- list_tables(*, load_if_missing: bool) Optional[List[latch.registry.table.Table]]
List Registry tables contained in this project.
- Parameters
load_if_missing – If true,
load()
the table list if not in cache. If false, return None if not in cache.- Returns
Tables in this project.
- update(*, reload_on_commit: bool = True) Iterator[latch.registry.project.ProjectUpdate] [source]#
Start an update transaction.
The transaction will commit when the context manager closes unless an error occurs.
No changes will occur until the transaction commits.
The transaction can be cancelled by running
ProjectUpdate.clear()
before closing the context manager.- Parameters
reload_on_commit – If true,
load()
this project after the transaction commits.- Returns
Context manager for the new transaction.
- class latch.registry.project.ProjectUpdate(project: latch.registry.project.Project)[source]#
Bases:
object
- project: latch.registry.project.Project#
- upsert_table(display_name: str)[source]#
Creates a table.
Not idempotent. Two calls with the same args will create two tables.
- Parameters
display_name – The display name of the new table.
latch.registry.record module#
- exception latch.registry.record.NoSuchColumnError(key: str)[source]#
Bases:
KeyError
Unknown column referenced by Registry method.
Reloading the containing table might help.
- key#
The unknown column key.
- class latch.registry.record.Record(id: str)[source]#
Bases:
object
Registry record.
list_records()
is the typical way to get aRecord
.- load() None [source]#
(Re-)populate this record instance’s cache.
Future calls to most getters will return immediately without making a network request.
Always makes a network request.
- get_name(*, load_if_missing: Literal[True] = 'True') str [source]#
- get_name(*, load_if_missing: bool) Optional[str]
Get the name of this record.
Names are unique within a table. Names are not globally unique. Use
id
if a globally unique identifier is required.- Parameters
load_if_missing – If true,
load()
the name if not in cache. If false, return None if not in cache.- Returns
Name of this record.
- get_columns(*, load_if_missing: Literal[True] = 'True') Dict[str, Column] [source]#
- get_columns(*, load_if_missing: bool) Optional[Dict[str, Column]]
Get the columns of this record’s table.
- get_values(*, load_if_missing: Literal[True] = 'True') Dict[str, RecordValue] [source]#
- get_values(*, load_if_missing: bool) Optional[Dict[str, RecordValue]]
Get this record’s values.
The resulting dictionary is shared between all calls to
get_values()
. Make deep copies if independent mutation is desired.- Parameters
load_if_missing – If true,
load()
the values if not in cache. If false, return None if not in cache.- Returns
Mapping between column keys and the corresponding value.
latch.registry.table module#
- class latch.registry.table.Table(id: str)[source]#
Bases:
object
Registry table. Contains
records
.list_tables()
is the typical way to get aTable
.- load() None [source]#
(Re-)populate this table instance’s cache.
Future calls to most getters will return immediately without making a network request.
Always makes a network request.
- get_display_name(*, load_if_missing: Literal[True] = 'True') str [source]#
- get_display_name(*, load_if_missing: bool) Optional[str]
Get the display name of this table.
This is an opaque string that can contain any valid Unicode data.
Display names are not unique and must never be used as identifiers. Use
id
instead.- Parameters
load_if_missing – If true,
load()
the display name if not in cache. If false, return None if not in cache.- Returns
Display name.
- get_columns(*, load_if_missing: Literal[True] = 'True') Dict[str, latch.registry.types.Column] [source]#
- get_columns(*, load_if_missing: bool) Optional[Dict[str, latch.registry.types.Column]]
Get the columns of this table.
- list_records(*, page_size: int = 100) Iterator[Dict[str, latch.registry.record.Record]] [source]#
List Registry records contained in this table.
- Parameters
page_size – Maximum size of a page of records. The last page may be shorter than this value.
- Yields
Pages of records. Each page is a mapping between record IDs and
records
.
- update(*, reload_on_commit: bool = True) Iterator[latch.registry.table.TableUpdate] [source]#
Start an update transaction.
The transaction will commit when the context manager closes unless an error occurs.
No changes will occur until the transaction commits.
The transaction can be cancelled by running
TableUpdate.clear()
before closing the context manager.- Parameters
reload_on_commit – If true,
load()
this table after the transaction commits.- Returns
Context manager for the new transaction.
- exception latch.registry.table.InvalidColumnTypeError(key: str, invalid_type: Union[Type[object], Type[str], Type[int], Type[float], Type[datetime.date], Type[datetime.datetime], Type[bool], Type[latch.types.file.LatchFile], Type[latch.types.directory.LatchDir], Type[latch.registry.types.StrEnum], Type[latch.registry.types.RegistryEnumDefinition], Type[latch.registry.types.LinkedRecordType], Type[List[latch.types.file.LatchFile]], Type[List[latch.types.directory.LatchDir]], Type[List[latch.registry.types.LinkedRecordType]]], msg: str)[source]#
Bases:
ValueError
Failure to use an invalid column type.
- key#
Identifier of the invalid column.
- invalid_type#
Requested column type.
- class latch.registry.table.TableUpdate(table: latch.registry.table.Table)[source]#
Bases:
object
Ongoing
Table
update transaction.Groups requested updates to commit everything together in one network request.
Transactions are atomic. The entire transaction either commits or fails with an exception.
- table: latch.registry.table.Table#
- upsert_record_raw_unsafe(*, name: str, values: Dict[str, Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[DBValue], latch.registry.upstream_types.values.UnionValue]], latch.registry.upstream_types.values.UnionValue]]) None [source]#
DANGEROUSLY Update or create a record using raw
values
.Values are not checked against the existing columns.
A transport error will be thrown if non-existent columns are updated.
The update will succeed if values do not match column types and future reads will produce
invalid values
.- Unsafe:
The value dictionary is not validated in any way. It is possible to create completely invalid record values that are not a valid Registry value of any type. Future reads will fail catastrophically when trying to parse these values.
- Parameters
name – Target record name.
values – Column values that to set.
- upsert_record(name: str, **values: Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]]]) None [source]#
Update or create a record.
A transport error will be thrown if non-existent columns are updated.
It is possible that the column definitions changed since the table was last loaded and the update will be issued with values that do not match current column types. This will succeed with no error and future reads will produce
invalid values
.- Parameters
name – Target record name.
values – Column values to set.
- upsert_column(key: str, type: Union[Type[str], Type[int], Type[float], Type[datetime.date], Type[datetime.datetime], Type[bool], Type[latch.types.file.LatchFile], Type[latch.types.directory.LatchDir], Type[latch.registry.types.StrEnum], Type[latch.registry.types.RegistryEnumDefinition], Type[latch.registry.types.LinkedRecordType], Type[List[latch.types.file.LatchFile]], Type[List[latch.types.directory.LatchDir]], Type[List[latch.registry.types.LinkedRecordType]]], *, required: bool = False)[source]#
Create a column. Support for updating columns is planned.
- Parameters
key – Identifier of the new column.
type –
Type of the new column.
Only a limited set of Python types is currently supported and will be expanded over time.
latch.registry.types.RegistryPythonType
represents the currently supported types.required –
If true, records without a value for this column are considered invalid.
Note that an explicit None value is different from a missing/empty value. None is a valid value for an Optional (nullable) column marked as required.
latch.registry.types module#
- class latch.registry.types.InvalidValue(raw_value: str)[source]#
Bases:
object
Registry
Record
value that failed validation.
- class latch.registry.types.Column(key: str, type: Union[Type[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]]]], Type[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]], latch.registry.upstream_types.values.EmptyCell]]], upstream_type: latch.registry.upstream_types.types.DBType)[source]#
Bases:
object
Registry
Table
column definition.Table.get_columns()
is the typical way to get aColumn
.- type: Union[Type[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]]]], Type[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]], latch.registry.upstream_types.values.EmptyCell]]]#
Python equivalent of the stored column type.
- upstream_type: latch.registry.upstream_types.types.DBType#
Raw column type.
Used to convert between Python values and Registry values.
latch.registry.utils module#
- exception latch.registry.utils.RegistryTransformerException[source]#
Bases:
ValueError
- latch.registry.utils.to_python_type(registry_type: Union[latch.registry.upstream_types.types.PrimitiveTypeBasic, latch.registry.upstream_types.types.PrimitiveTypeLink, latch.registry.upstream_types.types.PrimitiveTypeEnum, latch.registry.upstream_types.types.UnionType, latch.registry.upstream_types.types.ArrayType]) Type[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[Union[str, datetime.datetime, datetime.date, int, float, latch.types.file.LatchFile, latch.types.directory.LatchDir, None, bool, latch.registry.record.Record, List[RegistryPythonValue]]]]] [source]#
- latch.registry.utils.to_python_literal(registry_literal: Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[DBValue], latch.registry.upstream_types.values.UnionValue]], latch.registry.upstream_types.values.UnionValue], registry_type: Union[latch.registry.upstream_types.types.PrimitiveTypeBasic, latch.registry.upstream_types.types.PrimitiveTypeLink, latch.registry.upstream_types.types.PrimitiveTypeEnum, latch.registry.upstream_types.types.UnionType, latch.registry.upstream_types.types.ArrayType])[source]#
- latch.registry.utils.to_registry_literal(python_literal, registry_type: Union[latch.registry.upstream_types.types.PrimitiveTypeBasic, latch.registry.upstream_types.types.PrimitiveTypeLink, latch.registry.upstream_types.types.PrimitiveTypeEnum, latch.registry.upstream_types.types.UnionType, latch.registry.upstream_types.types.ArrayType]) Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[Union[latch.registry.upstream_types.values.PrimitiveStringValueValid, latch.registry.upstream_types.values.InvalidValue, latch.registry.upstream_types.values.PrimitiveNumberValueValid, latch.registry.upstream_types.values.PrimitiveNullValueValid, latch.registry.upstream_types.values.PrimitiveBlobValueValid, latch.registry.upstream_types.values.PrimitiveLinkValueValid, latch.registry.upstream_types.values.PrimitiveEnumValueValid, latch.registry.upstream_types.values.PrimitiveBooleanValueValid, List[DBValue], latch.registry.upstream_types.values.UnionValue]], latch.registry.upstream_types.values.UnionValue] [source]#
- latch.registry.utils.get_blob_nodetype(registry_type: Union[latch.registry.upstream_types.types.PrimitiveTypeBasic, latch.registry.upstream_types.types.PrimitiveTypeLink, latch.registry.upstream_types.types.PrimitiveTypeEnum, latch.registry.upstream_types.types.UnionType, latch.registry.upstream_types.types.ArrayType]) Union[Type[latch.types.file.LatchFile], Type[latch.types.directory.LatchDir]] [source]#