timelink.api package
for structure of this directory see https://fastapi.tiangolo.com/tutorial/sql-databases/
Subpackages
- timelink.api.models package
- Submodules
- timelink.api.models.act module
- timelink.api.models.attribute module
- timelink.api.models.base module
- timelink.api.models.base_class module
- timelink.api.models.base_mappings module
- timelink.api.models.entity module
EntityEntity.containsEntity.get_entity()Entity.get_orm_entities_classes()Entity.get_orm_for_pom_class()Entity.get_orm_for_table()Entity.get_som_mapper_ids()Entity.get_som_mapper_to_orm_as_dict()Entity.get_subclasses()Entity.get_tables_to_orm_as_dict()Entity.groupnameEntity.idEntity.indexedEntity.insideEntity.the_levelEntity.the_lineEntity.the_orderEntity.updated
- timelink.api.models.object module
- timelink.api.models.person module
- timelink.api.models.pom_som_mapper module
PomClassAttributesPomSomMapperPomSomMapper.containsPomSomMapper.element_class_to_column()PomSomMapper.ensure_all_mappings()PomSomMapper.ensure_mapping()PomSomMapper.get_pom_class()PomSomMapper.get_pom_class_from_group()PomSomMapper.get_pom_class_ids()PomSomMapper.get_pom_classes()PomSomMapper.groupnamePomSomMapper.idPomSomMapper.indexedPomSomMapper.insidePomSomMapper.kgroup_to_entity()PomSomMapper.store_KGroup()PomSomMapper.the_levelPomSomMapper.the_linePomSomMapper.the_orderPomSomMapper.updated
- timelink.api.models.relation module
- timelink.api.models.source module
- timelink.api.models.system module
KleioImportedFileKleioImportedFileSchemaKleioImportedFileSchema.error_rptKleioImportedFileSchema.importedKleioImportedFileSchema.model_computed_fieldsKleioImportedFileSchema.model_configKleioImportedFileSchema.model_fieldsKleioImportedFileSchema.nameKleioImportedFileSchema.nerrorsKleioImportedFileSchema.nwarningsKleioImportedFileSchema.pathKleioImportedFileSchema.structureKleioImportedFileSchema.translation_dateKleioImportedFileSchema.translatorKleioImportedFileSchema.warning_rpt
LogLevelParTypeSchemaSysLogSysLogCreateSchemaSysLogSchemaSysParSysParSchema
Submodules
timelink.api.crud module
CRUD operations for the timelink API.
- timelink.api.crud.get(db: Session, id: str) EntityAttrRelSchema[source]
Get entity by id :param db: database session :param id: entity id
- Returns:
Entity object
- timelink.api.crud.get_syslog(db: Session, nlogs: int) list[SysLog][source]
Get last n system logs last one first :param db: database session :param nlogs: sequence number
- Returns:
List of SysLog objects
- timelink.api.crud.get_syslog_by_time(db: Session, start_time: datetime, end_time: datetime) list[SysLog][source]
Get system logs between start_time and end_time :param db: database session :param start_time: start time :param end_time: end time
- Returns:
List of SysLog objects
- timelink.api.crud.get_syspar(db: Session, q: list[str] | None = None)[source]
Get system parameters :param db: database session :param q: parameter name(s); if empty, return all parameters
- Returns:
SysPar object
- timelink.api.crud.set_syslog(db: Session, log: SysLogCreateSchema) SysLog[source]
Set system log :param db: database session :param log: SysLogCreateSchema object with level, origin and message
- Returns:
SysLog object
- timelink.api.crud.set_syspar(db: Session, syspar: SysParSchema)[source]
Set system parameters :param db: database session :param syspar: SysPar object
- Returns:
SysPar object
timelink.api.database module
timelink.api.main module
timelink.api.schemas module
Schemas for the Timelink API
In the FastAPi tutorial this file is used for the pydantic models for the API, including for the classes that are used for database access. Another file, called models.py, is used in the tutorial for the SQLAlchemy models.
We use a module called “models” for the SQLAlchemy models
Here we put the pydantic models that are not related to database models like search requests and search results.
- class timelink.api.schemas.AttributeSchema(*, entity: str, the_type: str, the_value: str, the_date: str, obs: str | None, groupname: str = None)[source]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'entity': FieldInfo(annotation=str, required=True), 'groupname': FieldInfo(annotation=str, required=False), 'obs': FieldInfo(annotation=Union[str, NoneType], required=True), 'the_date': FieldInfo(annotation=str, required=True), 'the_type': FieldInfo(annotation=str, required=True), 'the_value': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.EntityAttrRelSchema(*, id: str, pom_class: str, inside: str | None, the_order: int | None, the_level: int | None, the_line: int | None, groupname: str | None, updated: datetime | None, indexed: datetime | None, attributes: List[AttributeSchema] | None, rels_in: List[RelationInSchema] | None, rels_out: List[RelationOutSchema] | None, contains: List[EntityBriefSchema] | None)[source]
Pydantic Schema for Entity with attributes and relations
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'attributes': FieldInfo(annotation=Union[List[AttributeSchema], NoneType], required=True), 'contains': FieldInfo(annotation=Union[List[EntityBriefSchema], NoneType], required=True), 'groupname': FieldInfo(annotation=Union[str, NoneType], required=True), 'id': FieldInfo(annotation=str, required=True), 'indexed': FieldInfo(annotation=Union[datetime, NoneType], required=True), 'inside': FieldInfo(annotation=Union[str, NoneType], required=True), 'pom_class': FieldInfo(annotation=str, required=True), 'rels_in': FieldInfo(annotation=Union[List[RelationInSchema], NoneType], required=True), 'rels_out': FieldInfo(annotation=Union[List[RelationOutSchema], NoneType], required=True), 'the_level': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_line': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_order': FieldInfo(annotation=Union[int, NoneType], required=True), 'updated': FieldInfo(annotation=Union[datetime, NoneType], required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.EntityBriefSchema(*, id: str, pom_class: str, inside: str | None, the_order: int | None, the_level: int | None, the_line: int | None, groupname: str | None, updated: datetime | None, indexed: datetime | None)[source]
Pydantic Schema for Entity brief
No links to other entities
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'groupname': FieldInfo(annotation=Union[str, NoneType], required=True), 'id': FieldInfo(annotation=str, required=True), 'indexed': FieldInfo(annotation=Union[datetime, NoneType], required=True), 'inside': FieldInfo(annotation=Union[str, NoneType], required=True), 'pom_class': FieldInfo(annotation=str, required=True), 'the_level': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_line': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_order': FieldInfo(annotation=Union[int, NoneType], required=True), 'updated': FieldInfo(annotation=Union[datetime, NoneType], required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.EntitySchema(*, id: str, pom_class: str, inside: str | None, the_order: int | None, the_level: int | None, the_line: int | None, groupname: str | None, updated: datetime | None, indexed: datetime | None, contains: List[EntitySchema] | None)[source]
Pydantic Schema for Entity
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'contains': FieldInfo(annotation=Union[List[EntitySchema], NoneType], required=True), 'groupname': FieldInfo(annotation=Union[str, NoneType], required=True), 'id': FieldInfo(annotation=str, required=True), 'indexed': FieldInfo(annotation=Union[datetime, NoneType], required=True), 'inside': FieldInfo(annotation=Union[str, NoneType], required=True), 'pom_class': FieldInfo(annotation=str, required=True), 'the_level': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_line': FieldInfo(annotation=Union[int, NoneType], required=True), 'the_order': FieldInfo(annotation=Union[int, NoneType], required=True), 'updated': FieldInfo(annotation=Union[datetime, NoneType], required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.ImportStats(*, datetime: date, machine: str, database: str, file: str, import_time_seconds: float, entities_processed: int, entity_rate: float, person_rate: float, nerrors: int, errors: List[str])[source]
Import statistics
- Fields:
datetime: date and time of import machine: machine where import was done database: specific database where import was done file: file that was imported import_time_seconds: time in seconds that import took entities_processed: number of entities processed entity_rate: number of entities processed per second person_rate: number of persons processed per second nerrors: number of errors errors: list of errors
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'database': FieldInfo(annotation=str, required=True), 'datetime': FieldInfo(annotation=date, required=True), 'entities_processed': FieldInfo(annotation=int, required=True), 'entity_rate': FieldInfo(annotation=float, required=True), 'errors': FieldInfo(annotation=List[str], required=True), 'file': FieldInfo(annotation=str, required=True), 'import_time_seconds': FieldInfo(annotation=float, required=True), 'machine': FieldInfo(annotation=str, required=True), 'nerrors': FieldInfo(annotation=int, required=True), 'person_rate': FieldInfo(annotation=float, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.RelationInSchema(*, id: str, origin: str, destination: str, the_type: str, the_value: str, the_date: str, obs: str | None, org_name: str | None)[source]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'destination': FieldInfo(annotation=str, required=True), 'id': FieldInfo(annotation=str, required=True), 'obs': FieldInfo(annotation=Union[str, NoneType], required=True), 'org_name': FieldInfo(annotation=Union[str, NoneType], required=True), 'origin': FieldInfo(annotation=str, required=True), 'the_date': FieldInfo(annotation=str, required=True), 'the_type': FieldInfo(annotation=str, required=True), 'the_value': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.RelationOutSchema(*, id: str, origin: str, destination: str, the_type: str, the_value: str, the_date: str, obs: str | None, dest_name: str | None)[source]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'dest_name': FieldInfo(annotation=Union[str, NoneType], required=True), 'destination': FieldInfo(annotation=str, required=True), 'id': FieldInfo(annotation=str, required=True), 'obs': FieldInfo(annotation=Union[str, NoneType], required=True), 'origin': FieldInfo(annotation=str, required=True), 'the_date': FieldInfo(annotation=str, required=True), 'the_type': FieldInfo(annotation=str, required=True), 'the_value': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.RelationSchema(*, id: str, origin: str, destination: str, the_type: str, the_value: str, the_date: str, obs: str | None)[source]
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'from_attributes': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'destination': FieldInfo(annotation=str, required=True), 'id': FieldInfo(annotation=str, required=True), 'obs': FieldInfo(annotation=Union[str, NoneType], required=True), 'origin': FieldInfo(annotation=str, required=True), 'the_date': FieldInfo(annotation=str, required=True), 'the_type': FieldInfo(annotation=str, required=True), 'the_value': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.SearchRequest(*, q: str, after: date | None = None, until: date | None = None, skip: int | None = 0, limit: int | None = 100)[source]
Search request
- Fields:
q: search query after: date after which to search, possibly None until: date until which to search, possibly None skip: number of items to skip, default 0 limit: number of items to return, default 100
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'after': FieldInfo(annotation=Union[date, NoneType], required=False), 'limit': FieldInfo(annotation=Union[int, NoneType], required=False, default=100), 'q': FieldInfo(annotation=str, required=True), 'skip': FieldInfo(annotation=Union[int, NoneType], required=False, default=0), 'until': FieldInfo(annotation=Union[date, NoneType], required=False)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class timelink.api.schemas.SearchResults(*, id: str, the_class: str, description: str, start_date: date, end_date: date)[source]
Search results
- Fields:
results: list of search results
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'description': FieldInfo(annotation=str, required=True), 'end_date': FieldInfo(annotation=date, required=True), 'id': FieldInfo(annotation=str, required=True), 'start_date': FieldInfo(annotation=date, required=True), 'the_class': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
timelink.api.views module
- timelink.api.views.view(name, metadata, selectable)[source]
Create a view with the given name from the given selectable. The view is created when the metadata is first bound to an engine.
Example
stuff_view = view( “stuff_view”, metadata, sa.select(
stuff.c.id.label(“id”), stuff.c.data.label(“data”), more_stuff.c.data.label(“moredata”),
) .select_from(stuff.join(more_stuff)) .where(stuff.c.data.like((“%orange%”))), )
- with engine.connect() as conn:
- conn.execute(
sa.select(stuff_view.c.data, stuff_view.c.moredata) ).all()