thoth.storages.graph package

Submodules

thoth.storages.graph.cache module

A graph database cache implementation to speed up queries.

The implementation uses actually two caches - one in-memory for LRU based on method calls and another one which is build on top of SQLite3.

class thoth.storages.graph.cache.GraphCache(engine: sqlalchemy.engine.base.Engine = None, session=None, sqlite_cache_stats: dict = NOTHING, *, cache: str = None)[source]

Bases: thoth.storages.graph.sql_base.SQLBase

A Dgraph database cache to speed up resolution of popular packages and packages with overlapping dependencies.

DEFAULT_CACHE_PATH = ':memory:'
ENV_CACHE_PATH = 'THOTH_STORAGES_GRAPH_CACHE'
add_depends_on(package_name: str, package_version: str, index_url: str, *, os_name: str, os_version: str, python_version: str, dependency_name: Optional[str], dependency_version: Optional[str]) → None[source]

Add a new entry of depends on for a Python package.

clear_in_memory_cache() → None[source]

Clear in-memory cache.

connect()[source]

Connect to the database.

get_depends_on(package_name: str, package_version: str, index_url: str, *, os_name: str = None, os_version: str = None, python_version: str = None) → Optional[List[Tuple[str, str]]][source]

Retrieve dependencies for the given packages.

get_python_package_version_records(package_name: str, package_version: str, index_url: Optional[str], os_name: Optional[str], os_version: Optional[str], python_version: Optional[str]) → Optional[List[dict]][source]

Get records for Python packages matching the given criteria for environment.

initialize_schema()[source]

Initialize schema of database.

static is_enabled()[source]

Check if this cache is enabled.

static is_inserts_enabled()[source]

Check if inserts to this cache are enabled.

classmethod load(cache: str = None) → thoth.storages.graph.cache.GraphCache[source]

Prepare graph cache by loading an already existing one or a new one.

stats() → dict[source]

Get statistics for the graph cache.

thoth.storages.graph.models module

Models for SQL based database.

class thoth.storages.graph.models.Advised(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation stating advised software stack.

adviser_run
adviser_run_id
id
python_software_stack
python_software_stack_id
class thoth.storages.graph.models.AdviserRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single adviser run.

additional_stack_info
advised_configuration_changes
advised_software_stacks
adviser_document_id
adviser_error
adviser_name
adviser_version
count
datetime
debug
duration
external_build_software_environment
external_build_software_environment_id
external_hardware_information
external_hardware_information_id
external_run_software_environment
external_run_software_environment_id
id
limit
limit_latest_versions
origin
recommendation_type
requirements_format
user_software_stack
user_software_stack_id
class thoth.storages.graph.models.CVE(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Information about a CVE.

advisory
cve_id
cve_name
id
python_package_versions
version_range
class thoth.storages.graph.models.DebDependency(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A Debian dependency.

deb_package_versions_depends
deb_package_versions_pre_depends
deb_package_versions_replaces
id
package_name
class thoth.storages.graph.models.DebDepends(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Depending relation of a deb package.

deb_dependency
deb_dependency_id
deb_package_version
deb_package_version_id
id
version_range
class thoth.storages.graph.models.DebPackageVersion(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Debian-specific package version.

arch
depends
epoch
id
package_extract_runs
package_name
package_version
pre_depends
replaces
class thoth.storages.graph.models.DebPreDepends(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Pre-depending relation of a deb package.

deb_dependency
deb_dependency_id
deb_package_version
deb_package_version_id
id
version_range
class thoth.storages.graph.models.DebReplaces(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation of a deb package capturing package replacement..

deb_dependency
deb_dependency_id
deb_package_version
deb_package_version_id
id
version_range
class thoth.storages.graph.models.DependencyMonkeyRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single dependency-monkey run.

build_hardware_information
build_hardware_information_id
build_software_environment
build_software_environment_id
count
datetime
debug
decision
dependency_monkey_document_id
dependency_monkey_error
dependency_monkey_name
dependency_monkey_version
duration
id
inspection_runs
limit_latest_versions
python_package_requirements
run_hardware_information
run_hardware_information_id
run_software_environment
run_software_environment_id
seed
class thoth.storages.graph.models.DependsOn(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Dependency of a Python package version.

entity
entity_id
extra
id
marker
marker_evaluation_result
version
version_id
version_range
class thoth.storages.graph.models.DetectedSymbol(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation stating a package extract run detected a symbol.

id
package_extract_run
package_extract_run_id
versioned_symbol
versioned_symbol_id
class thoth.storages.graph.models.EcosystemSolver(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Record for an ecosystem solver.

ecosystem
id
os_name
os_version
python_version
solver_name
solver_version
versions
class thoth.storages.graph.models.ExternalHardwareInformation(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

External Hardware information base class to derive for specific HW environments.

adviser_runs
cpu_cores
cpu_family
cpu_model
cpu_model_name
cpu_physical_cpus
cpu_vendor
gpu_cores
gpu_memory_size
gpu_model_name
gpu_vendor
id
ram_size
class thoth.storages.graph.models.ExternalPythonRequirementsLock(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

An External pinned down requirements for an application.

id
python_package_version_entity
python_package_version_entity_id
python_software_stack
python_software_stack_id
class thoth.storages.graph.models.ExternalSoftwareEnvironment(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A base class for environment types.

adviser_inputs_build
adviser_inputs_run
cuda_version
environment_name
environment_type
external_package_extract_runs
id
image_name
image_sha
os_name
os_version
python_version
versioned_symbols
class thoth.storages.graph.models.FoundDeb(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

State a package extract run found a Debian package.

deb_package_version
deb_package_version_id
id
package_extract_run
package_extract_run_id
class thoth.storages.graph.models.FoundPythonFile(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

State a package extract run found a Python file.

file
id
package_extract_run
package_extract_run_id
python_file_digest
python_file_digest_id
class thoth.storages.graph.models.FoundRPM(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

State a package extract run found an RPM package.

id
package_extract_run
package_extract_run_id
rpm_package_version
rpm_package_version_id
class thoth.storages.graph.models.HardwareInformation(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Hardware information base class to derive for specific HW environments.

cpu_cores
cpu_family
cpu_model
cpu_model_name
cpu_physical_cpus
cpu_vendor
dependency_monkey_runs_build
dependency_monkey_runs_run
gpu_cores
gpu_memory_size
gpu_model_name
gpu_vendor
id
inspection_runs_build
inspection_runs_run
ram_size
class thoth.storages.graph.models.HasArtifact(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

The given package has the given artifact.

id
python_artifact
python_artifact_id
python_package_version_entity
python_package_version_entity_id
class thoth.storages.graph.models.HasSymbol(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation stating a software environment has a symbol.

external_software_environment
external_software_environment_id
id
software_environment
software_environment_id
versioned_symbol
versioned_symbol_id
class thoth.storages.graph.models.HasVulnerability(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

The given package version has a vulnerability.

cve
cve_id
id
python_package_version_entity
python_package_version_entity_id
class thoth.storages.graph.models.Identified(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation representing a Python package version identified by a package-extract run.

id
package_extract_run
package_extract_run_id
python_package_version_entity
python_package_version_entity_id
class thoth.storages.graph.models.IncludedFile(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation representing file found in the given artifact.

file
id
python_artifact
python_artifact_id
python_file_digest
python_file_digest_id
class thoth.storages.graph.models.InspectionRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single inspection.

amun_version
build_hardware_information
build_hardware_information_id
build_requests_cpu
build_requests_memory
build_software_environment
build_software_environment_id
conv1d_perf_indicators
conv2d_perf_indicators
datetime
dependency_monkey_run
dependency_monkey_run_id
id
inspection_document_id
inspection_software_stack
inspection_software_stack_id
inspection_sync_state
matmul_perf_indicators
run_hardware_information
run_hardware_information_id
run_requests_cpu
run_requests_memory
run_software_environment
run_software_environment_id
class thoth.storages.graph.models.Investigated(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A record about investigated Python artifact by a package analyzer.

id
package_analyzer_run
package_analyzer_run_id
python_artifact
python_artifact_id
class thoth.storages.graph.models.InvestigatedFile(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A record about found file by package analyzer.

id
package_analyzer_run
package_analyzer_run_id
python_file_digest
python_file_digest_id
class thoth.storages.graph.models.PackageAnalyzerRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single package-analyzer (package analysis) run.

datetime
debug
duration
id
input_python_package_version_entity
input_python_package_version_entity_id
package_analysis_document_id
package_analyzer_error
package_analyzer_name
package_analyzer_version
python_artifacts
python_files
class thoth.storages.graph.models.PackageExtractRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single package-extract (image analysis) run.

analysis_document_id
datetime
debug
duration
environment_type
external_software_environment
external_software_environment_id
found_debs
found_python_files
found_rpms
id
image_tag
origin
os_id
os_name
os_version_id
package_extract_error
package_extract_name
package_extract_version
python_package_version_entities
software_environment
software_environment_id
versioned_symbols
class thoth.storages.graph.models.ProvenanceCheckerRun(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single provenance-checker run.

datetime
debug
duration
id
origin
provenance_checker_document_id
provenance_checker_error
provenance_checker_name
provenance_checker_version
user_software_stack
user_software_stack_id
class thoth.storages.graph.models.PythonArtifact(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

An artifact for a python package in a specific version.

artifact_hash_sha256
artifact_name
id
package_analyzer_runs
python_files
python_package_version_entities
versioned_symbols
class thoth.storages.graph.models.PythonDependencyMonkeyRequirements(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Requirements for a software stack as run on Dependency Monkey.

dependency_monkey_run
dependency_monkey_run_id
id
python_package_requirement
python_package_requirement_id
class thoth.storages.graph.models.PythonFileDigest(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A class representing a single file digests.

id
package_analyzer_runs
package_extract_runs
python_artifacts
sha256
class thoth.storages.graph.models.PythonPackageIndex(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Representation of a Python package Index.

enabled
id
python_package_requirements
python_package_version_entities
python_package_versions
url
verify_ssl
warehouse_api_url
class thoth.storages.graph.models.PythonPackageRequirement(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A requirement as stated by a software stack.

dependency_monkey_runs
develop
id
index
name
python_package_index_id
python_software_stacks
version_range
class thoth.storages.graph.models.PythonPackageVersion(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Representation of a Python package version running on a specific software environment.

dependencies
entity
entity_id
id
index
os_name
os_version
package_name
package_version
python_package_index_id
python_software_stacks
python_version
solvers
class thoth.storages.graph.models.PythonPackageVersionEntity(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Representation of a Python package not running in any environment.

cves
id
index
package_analyzer_runs
package_extract_runs
package_name
package_version
python_artifacts
python_package_index_id
python_package_versions
python_software_stacks
versions
class thoth.storages.graph.models.PythonRequirements(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Requirements for a software stack.

id
python_package_requirement
python_package_requirement_id
python_software_stack
python_software_stack_id
class thoth.storages.graph.models.PythonRequirementsLock(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A pinned down requirements for an application.

id
python_package_version
python_package_version_id
python_software_stack
python_software_stack_id
class thoth.storages.graph.models.PythonSoftwareStack(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A Python software stack definition.

advised_by
adviser_runs
id
inspection_runs
overall_score
performance_score
provenance_checker_runs
python_package_requirements
python_package_versions
python_package_versions_entities
software_stack_type
class thoth.storages.graph.models.RPMPackageVersion(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

RPM-specific package version.

arch
epoch
id
package_extract_runs
package_identifier
package_name
package_version
release
rpm_requirements
src
class thoth.storages.graph.models.RPMRequirement(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Requirement of an RPM as stated in a spec file.

id
rpm_package_versions
rpm_requirement_name
class thoth.storages.graph.models.RPMRequires(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

RPM requirement mapping.

id
rpm_package_version
rpm_package_version_id
rpm_requirement
rpm_requirement_id
class thoth.storages.graph.models.RequiresSymbol(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A relation stating a software environment requires a symbol.

id
python_artifact
python_artifact_id
versioned_symbol
versioned_symbol_id
class thoth.storages.graph.models.SoftwareEnvironment(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A base class for environment types.

cuda_version
dependency_monkey_runs_build
dependency_monkey_runs_run
environment_name
environment_type
id
image_name
image_sha
inspection_runs_build
inspection_runs_run
os_name
os_version
package_extract_runs
python_version
versioned_symbols
class thoth.storages.graph.models.Solved(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A solver solved a package-version.

datetime
document_id
duration
ecosystem_solver
ecosystem_solver_id
error
error_unparseable
error_unsolvable
id
is_provided
version
version_id
class thoth.storages.graph.models.VersionedSymbol(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A system symbol.

id
library_name
package_extract_runs
python_artifacts
software_environments
symbol

thoth.storages.graph.models_base module

A base and utilities for implementing SQLAlchemy based models.

class thoth.storages.graph.models_base.BaseExtension[source]

Bases: object

Extend base class with additional functionality.

classmethod attribute_names()[source]

Get names of attributes for the given model declaration.

classmethod get_or_create(session, **kwargs)[source]

Query for the given entity, create if it does not exist yet.

to_dict(without_id: bool = True) → dict[source]

Convert model to a dictionary representation keeping just rows as attributes.

thoth.storages.graph.models_base.get_python_package_version_index_combinations(*, index_as_property: bool = True) → List[sqlalchemy.sql.schema.Index][source]

Create index for all possible combinations which we can query.

thoth.storages.graph.models_cache module

Models for cache.

class thoth.storages.graph.models_cache.DependsOn(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

Dependency relationship capturing.

entity
entity_id
version
version_id
version_range
class thoth.storages.graph.models_cache.PythonPackageVersion(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A Python package version in the given environment.

entities
id
index_url
os_name
os_version
package_name
package_version
python_version
class thoth.storages.graph.models_cache.PythonPackageVersionEntity(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension

A Python package version entity.

id
package_name
package_version
versions

thoth.storages.graph.models_performance module

Performance indicators (models) used in Thoth with their schemas.

class thoth.storages.graph.models_performance.PerformanceIndicatorBase[source]

Bases: object

A base class for implementing performance indicators.

classmethod create_from_report(session: sqlalchemy.orm.session.Session, inspection_document: dict, inspection_run_id: int) → thoth.storages.graph.models_performance.PerformanceIndicatorBase[source]

Create performance indicator record together with related observed performance edge based on inspection.

exit_code = Column(None, Integer(), table=None, nullable=False)
framework = Column(None, String(length=256), table=None)
classmethod from_report(inspection_document: dict, partial_model: type) → thoth.storages.graph.models_performance.PerformanceIndicatorBase[source]

Create model from the inspection report respecting parameters and result reported by the indicator.

origin = Column(None, String(length=256), table=None)
overall_score = Column(None, Float(), table=None)
ru_idrss = Column(None, Integer(), table=None, nullable=False)
ru_inblock = Column(None, Integer(), table=None, nullable=False)
ru_isrss = Column(None, Integer(), table=None, nullable=False)
ru_ixrss = Column(None, Integer(), table=None, nullable=False)
ru_majflt = Column(None, Integer(), table=None, nullable=False)
ru_maxrss = Column(None, Integer(), table=None, nullable=False)
ru_minflt = Column(None, Integer(), table=None, nullable=False)
ru_msgrcv = Column(None, Integer(), table=None, nullable=False)
ru_msgsnd = Column(None, Integer(), table=None, nullable=False)
ru_nivcsw = Column(None, Integer(), table=None, nullable=False)
ru_nsignals = Column(None, Integer(), table=None, nullable=False)
ru_nswap = Column(None, Integer(), table=None, nullable=False)
ru_nvcsw = Column(None, Integer(), table=None, nullable=False)
ru_oublock = Column(None, Integer(), table=None, nullable=False)
ru_stime = Column(None, Float(), table=None, nullable=False)
ru_utime = Column(None, Float(), table=None, nullable=False)
version = Column(None, String(length=256), table=None, nullable=False)
class thoth.storages.graph.models_performance.PiConv1D(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension, thoth.storages.graph.models_performance.PerformanceIndicatorBase

A class for representing a conv1D micro-performance test.

batch
data_format
device
dtype
elapsed
exit_code
filter_width
framework
id
input_channels
input_width
inspection_run
inspection_run_id
origin
output_channels
overall_score
padding
rate
reps
ru_idrss
ru_inblock
ru_isrss
ru_ixrss
ru_majflt
ru_maxrss
ru_minflt
ru_msgrcv
ru_msgsnd
ru_nivcsw
ru_nsignals
ru_nswap
ru_nvcsw
ru_oublock
ru_stime
ru_utime
strides
version
class thoth.storages.graph.models_performance.PiConv2D(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension, thoth.storages.graph.models_performance.PerformanceIndicatorBase

A class for representing a conv2D micro-performance test.

batch
data_format
device
dtype
elapsed
exit_code
filter_height
filter_width
framework
id
input_channels
input_height
input_width
inspection_run
inspection_run_id
origin
output_channels
overall_score
padding
rate
reps
ru_idrss
ru_inblock
ru_isrss
ru_ixrss
ru_majflt
ru_maxrss
ru_minflt
ru_msgrcv
ru_msgsnd
ru_nivcsw
ru_nsignals
ru_nswap
ru_nvcsw
ru_oublock
ru_stime
ru_utime
strides
version
class thoth.storages.graph.models_performance.PiMatmul(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, thoth.storages.graph.models_base.BaseExtension, thoth.storages.graph.models_performance.PerformanceIndicatorBase

A class for representing a matrix multiplication micro-performance test.

device
dtype
elapsed
exit_code
framework
id
inspection_run
inspection_run_id
matrix_size
origin
overall_score
rate
reps
ru_idrss
ru_inblock
ru_isrss
ru_ixrss
ru_majflt
ru_maxrss
ru_minflt
ru_msgrcv
ru_msgsnd
ru_nivcsw
ru_nsignals
ru_nswap
ru_nvcsw
ru_oublock
ru_stime
ru_utime
version

thoth.storages.graph.postgres module

An SQL database for storing Thoth data.

class thoth.storages.graph.postgres.GraphDatabase(engine: sqlalchemy.engine.base.Engine = None, session=None, cache: thoth.storages.graph.cache.GraphCache = NOTHING)[source]

Bases: thoth.storages.graph.sql_base.SQLBase

A SQL database adapter providing graph-like operations on top of SQL queries.

adviser_document_id_exist(adviser_document_id: str) → bool[source]

Check if there is a adviser document record with the given id.

analysis_document_id_exist(analysis_document_id: str) → bool[source]

Check if there is an analysis document record with the given id.

analysis_records_exist(analysis_document: dict) → bool[source]

Check whether the given analysis document records exist in the graph database.

build_software_environment_analyses_listing(build_software_environment_name: str, start_offset: int = 0, count: int = 100, convert_datetime: bool = True, is_external_run: bool = False) → List[dict][source]

Get listing of analyses available for the given software environment for build.

build_software_environment_listing(start_offset: int = 0, count: int = 100) → list[source]

Get listing of software environments available for build.

property cache

Get cache for this instance.

connect()[source]

Connect to the database.

static construct_connection_string() → str[source]

Construct a connection string needed to connect to database.

create_python_cve_record(package_name: str, package_version: str, index_url: str, *, record_id: str, version_range: str, advisory: str, cve: str = None) → Tuple[thoth.storages.graph.models.CVE, bool][source]

Store information about a CVE in the graph database for the given Python package.

create_python_package_version_entity(package_name: str, package_version: str = None, index_url: str = None, only_if_package_seen: bool = False) → Optional[Tuple[thoth.storages.graph.models.PythonPackageVersionEntity, bool]][source]

Create a Python package version entity record in the system.

By creating this entity, the system will record and track the given package.

dependency_monkey_document_id_exist(dependency_monkey_document_id: str) → bool[source]

Check if the given dependency monkey report record exists in the graph database.

drop_all()[source]

Drop all content stored in the database.

get_all_pi_count() → dict[source]

Retrieve dictionary mapping framework to performance indicator count (regardless of pi type).

get_all_pi_per_framework_count(framework: str) → dict[source]

Retrieve dictionary with number of Performance Indicators per ML Framework in the graph database.

get_all_python_package_version_hashes_sha256(package_name: str, package_version: str) → List[str][source]

Get hashes for a Python package per index.

get_analysis_metadata(analysis_document_id: str) → dict[source]

Get metadata stored for the given analysis document.

get_analyzer_documents_count() → int[source]

Get number of image analysis documents synced into graph.

get_depends_on = <methodtools._LruCacheWire object>
get_error_solved_python_package_versions(*, unsolvable: bool = False, unparseable: bool = False, start_offset: int = 0, count: int = 100, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, str, str]][source]

Retrieve solved with error Python package versions in Thoth Database.

if unsolvable=True -> get_unsolvable_python_package_versions if unparseable=True -> get_unparseable_python_package_versions

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions() [(‘regex’, ‘2018.11.7’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘1.11.0’, ‘https://pypi.org/simple’)]

get_error_solved_python_package_versions_count_all(*, unsolvable: bool = False, unparseable: bool = False, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve solved with error Python package versions number in Thoth Database.

if unsolvable=True -> get_unsolvable_python_package_versions_count_all if unparseable=True -> get_unparseable_python_package_versions_count_all

get_number_main_tables_records() → Dict[str, int][source]

Retrieve dictionary mapping main tables to records count.

get_number_performance_tables_records() → Dict[str, int][source]

Retrieve dictionary mapping performance tables to records count.

get_number_relation_tables_records() → Dict[str, int][source]

Retrieve dictionary mapping relation tables to records count.

get_python_cve_records(package_name: str, package_version: str) → List[dict][source]

Get known vulnerabilities for the given package-version.

get_python_package_index_urls(enabled: bool = None) → set[source]

Retrieve all the URLs of registered Python package indexes.

get_python_package_version_entities(*, start_offset: int = 0, count: int = 100, python_version: str = None, distinct: bool = False) → List[Tuple[str, str, str]][source]

Retrieve listing of all Python package versions entity with known index to graph database instance.

get_python_package_version_entities_count_all(*, start_offset: int = 0, count: int = 100, python_version: str = None, distinct: bool = False) → int[source]

Retrieve listing of all Python package versions entity with known index to graph database instance.

get_python_package_version_hashes_sha256(package_name: str, package_version: str, index_url: str = None) → List[str][source]

Get hashes for a Python package in a specified version.

get_python_package_version_records = <methodtools._LruCacheWire object>
get_python_package_versions(*, start_offset: int = 0, count: int = 100, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, str, str]][source]

Retrieve Python package versions in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions() [(‘regex’, ‘2018.11.7’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘1.11.0’, ‘https://pypi.org/simple’)]

get_python_package_versions_count(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[Tuple[str, str, str], int][source]

Retrieve number of versions per Python package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions_count() {(‘absl-py’, ‘0.1.10’, ‘https://pypi.org/simple’): 1, (‘absl-py’, ‘0.2.1’, ‘https://pypi.org/simple’): 1}

get_python_package_versions_count_all(*, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve Python package versions number in Thoth Database.

get_python_package_versions_count_per_index(index_url: str, *, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, Dict[Tuple[str, str], int]][source]

Retrieve number of Python package versions per index url in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions_count_per_index(index_url=’https://pypi.org/simple’) {‘https://pypi.org/simple’: {(‘absl-py’, ‘0.1.10’): 1, (‘absl-py’, ‘0.2.1’): 1}}

get_python_package_versions_count_per_version(package_name: str, *, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, Dict[str, int]][source]

Retrieve number of Python package versions per index url in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions_count_per_version(package_name=’tensorflow’) {‘1.14.0rc0’: {‘https://pypi.org/simple’: 1}, ‘1.13.0rc2’: {‘https://pypi.org/simple’: 1}}

get_python_packages_all(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, str]][source]

Retrieve Python packages with index in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_packages_all() [(‘regex’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘https://pypi.org/simple’)]

get_python_packages_all_versions(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, List[Tuple[str, str]]][source]

Retrieve Python package versions per package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_packages_all_versions() {‘absl-py’: [(‘0.1.10’, ‘https://pypi.org/simple’), (‘0.2.1’, ‘https://pypi.org/simple’)]}

get_python_packages_count_all(*, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve number of versions per Python package in Thoth Database.

get_python_packages_per_index(index_url: str, distinct: bool = False) → Dict[str, List[str]][source]

Retrieve listing of Python packages (solved) known to graph database instance for the given index.

get_solved_python_package_versions(*, start_offset: int = 0, count: int = 100, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, str, str]][source]

Retrieve solved Python package versions in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions() [(‘regex’, ‘2018.11.7’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘1.11.0’, ‘https://pypi.org/simple’)]

get_solved_python_package_versions_count(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[Tuple[str, str, str], int][source]

Retrieve number of solved versions per Python package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_solved_python_package_versions_count() {(‘absl-py’, ‘0.1.10’, ‘https://pypi.org/simple’): 1, (‘absl-py’, ‘0.2.1’, ‘https://pypi.org/simple’): 1}

get_solved_python_package_versions_count_all(*, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve solved Python package versions number in Thoth Database.

get_solved_python_package_versions_count_per_index(index_url: str, *, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, Dict[Tuple[str, str], int]][source]

Retrieve number of solved Python package versions per index url in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_solved_python_package_versions_count_per_index(index_url=’https://pypi.org/simple’) {‘https://pypi.org/simple’: {(‘absl-py’, ‘0.1.10’): 1, (‘absl-py’, ‘0.2.1’): 1}}

get_solved_python_package_versions_count_per_version(package_name: str, *, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, Dict[str, int]][source]

Retrieve number of solved Python package versions per package version in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions_count_per_version(package_name=’tensorflow’) {‘1.14.0rc0’: {‘https://pypi.org/simple’: 1}, ‘1.13.0rc2’: {‘https://pypi.org/simple’: 1}}

get_solved_python_packages_all(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, str]][source]

Retrieve solved Python package with index in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_solved_python_packages_all() [(‘regex’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘https://pypi.org/simple’)]

get_solved_python_packages_all_versions(*, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, List[Tuple[str, str]]][source]

Retrieve solved Python package versions per package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_solved_python_packages_all_versions() {‘absl-py’: [(‘0.1.10’, ‘https://pypi.org/simple’), (‘0.2.1’, ‘https://pypi.org/simple’)]}

get_solved_python_packages_count_all(*, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve number of solved Python package versions in Thoth Database.

get_solver_documents_count() → int[source]

Get number of solver documents synced into graph.

get_unsolved_python_package_versions(*, start_offset: int = 0, count: int = 100, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → List[Tuple[str, Optional[str], Optional[str]]][source]

Retrieve unsolved Python package versions in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions() [(‘regex’, ‘2018.11.7’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘1.11.0’, ‘https://pypi.org/simple’)]

get_unsolved_python_package_versions_count(*, os_name: str = None, os_version: str = None, python_version: str = None, start_offset: int = 0, count: int = 100, distinct: bool = False) → Dict[Tuple[str, str, str], int][source]

Retrieve number of unsolved versions per Python package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_unsolved_python_package_versions_count() {(‘absl-py’, ‘0.1.10’, ‘https://pypi.org/simple’): 1, (‘absl-py’, ‘0.2.1’, ‘https://pypi.org/simple’): 1}

get_unsolved_python_package_versions_count_all(*, package_name: str = None, package_version: str = None, index_url: str = None, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve unsolved Python package versions number in Thoth Database.

get_unsolved_python_package_versions_count_per_index(index_url: str, *, os_name: str = None, os_version: str = None, python_version: str = None, start_offset: int = 0, count: int = 100, distinct: bool = False) → Dict[str, Dict[Tuple[str, str], int]][source]

Retrieve number of unsolved Python package versions per index url in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_unsolved_python_package_versions_count_per_index(index_url=’https://pypi.org/simple’) {‘https://pypi.org/simple’: {(‘absl-py’, ‘0.1.10’): 1, (‘absl-py’, ‘0.2.1’): 1}}

get_unsolved_python_package_versions_count_per_version(package_name: str, *, start_offset: int = 0, count: int = 100, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → Dict[str, Dict[str, int]][source]

Retrieve number of unsolved Python package versions per package version in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_python_package_versions_count_per_version(package_name=’tensorflow’) {‘1.14.0rc0’: {‘https://pypi.org/simple’: 1}, ‘1.13.0rc2’: {‘https://pypi.org/simple’: 1}}

get_unsolved_python_packages_all(*, os_name: str = None, os_version: str = None, python_version: str = None, start_offset: int = 0, count: int = 100, distinct: bool = False) → List[Tuple[str, str]][source]

Retrieve unsolved Python package with index in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_unsolved_python_packages_all() [(‘regex’, ‘https://pypi.org/simple’), (‘tensorflow’, ‘https://pypi.org/simple’)]

get_unsolved_python_packages_all_versions(*, os_name: str = None, os_version: str = None, python_version: str = None, start_offset: int = 0, count: int = 100, distinct: bool = False) → Dict[str, List[Tuple[str, str]]][source]

Retrieve unsolved Python package versions per package in Thoth Database.

Examples: >>> from thoth.storages import GraphDatabase >>> graph = GraphDatabase() >>> graph.get_unsolved_python_packages_all_versions() {‘absl-py’: [(‘0.1.10’, ‘https://pypi.org/simple’), (‘0.2.1’, ‘https://pypi.org/simple’)]}

get_unsolved_python_packages_count_all(*, os_name: str = None, os_version: str = None, python_version: str = None, distinct: bool = False) → int[source]

Retrieve number of unsolved Python package versions in Thoth Database.

has_python_solver_error(package_name: str, package_version: str, index_url: str, *, os_name: Optional[str], os_version: Optional[str], python_version: Optional[str]) → bool[source]

Retrieve information whether the given package has any solver error.

initialize_schema()[source]

Initialize schema of database.

inspection_document_id_exist(inspection_document_id: str) → bool[source]

Check if there is an inspection document record with the given id.

is_python_package_index_enabled(url: str) → bool[source]

Check if the given Python package index is enabled.

is_schema_up2date() → bool[source]

Check if the current schema is up2date with the one configured on database side.

static normalize_python_package_name(package_name: str) → str[source]

Normalize Python package name based on PEP-0503.

static normalize_python_package_version(package_version: str) → str[source]

Normalize Python package name based on PEP-440.

package_analysis_document_id_exist(package_analysis_document_id: str) → bool[source]

Check if there is a package analysis document record with the given id.

static parse_python_solver_name(solver_name: str) → dict[source]

Parse os and Python identifiers encoded into solver name.

provenance_checker_document_id_exist(provenance_checker_document_id: str) → bool[source]

Check if there is a provenance-checker document record with the given id.

python_package_exists(package_name: str) → bool[source]

Check if the given Python package exists regardless of version.

python_package_index_listing(enabled: bool = None) → list[source]

Get listing of Python package indexes registered in the graph database.

python_package_version_exists(package_name: str, package_version: str, index_url: str = None, solver_name: str = None) → bool[source]

Check if the given Python package version exists in the graph database.

If optional solver_name parameter is set, the call answers if the given package was solved by the given solver. Otherwise, any solver run is taken into account.

python_software_stack_count(software_stack_type: str, unique: bool = False) → List[str][source]

Get number of Python software stacks available filtered by type.

register_python_package_index(url: str, warehouse_api_url: str = None, verify_ssl: bool = True, enabled: bool = False) → bool[source]

Register the given Python package index in the graph database.

retrieve_dependent_packages(package_name: str, package_version: str = None) → dict[source]

Get mapping package name to package version of packages that depend on the given package.

retrieve_transitive_dependencies_python(package_name: str, package_version: str, index_url: str, *, os_name: str = None, os_version: str = None, python_version: str = None, without_cache: bool = False) → List[Tuple[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str], Optional[Tuple[str, str, str]], Optional[Tuple[str, str, str]]]][source]

Get all transitive dependencies for the given package by traversing dependency graph.

It’s much faster to retrieve just dependency ids for the transitive dependencies as most of the time is otherwise spent in serialization and deserialization of query results. The ids are obtained later on (kept in ids map, see bellow).

The ids map represents a map to optimize number of retrievals - not to perform duplicate queries into graph instance.

retrieve_transitive_dependencies_python_multi(*package_tuples, os_name: str = None, os_version: str = None, python_version: str = None, without_cache: bool = False) → Dict[Tuple[str, str, str], Set[Tuple[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str], Optional[Tuple[str, str, str]], Optional[Tuple[str, str, str]]]]][source]

Get all transitive dependencies for a given set of packages by traversing the dependency graph.

retrieve_unanalyzed_python_package_versions(start_offset: int = 0, count: int = 100) → List[dict][source]

Retrieve a list of package names, versions and index urls that were not analyzed yet by package-analyzer.

run_software_environment_analyses_listing(run_software_environment_name: str, start_offset: int = 0, count: int = 100, convert_datetime: bool = True, is_external_run: bool = False) → List[dict][source]

Get listing of analyses available for the given software environment for run.

run_software_environment_listing(start_offset: int = 0, count: int = 100, is_external_run: bool = False) → list[source]

Get listing of software environments available for run.

set_python_package_index_state(url: str, *, enabled: bool) → None[source]

Enable or disable Python package index.

solver_document_id_exist(solver_document_id: str) → bool[source]

Check if there is a solver document record with the given id.

solver_records_exist(solver_document: dict) → bool[source]

Check if the given solver document record exists.

stats() → dict[source]

Get statistics for this adapter.

sync_adviser_result(document: dict) → None[source]

Sync adviser result into graph database.

sync_analysis_result(document: dict) → None[source]

Sync the given analysis result to the graph database.

sync_dependency_monkey_result(document: dict) → None[source]

Sync reports of dependency monkey runs.

sync_inspection_result(document) → None[source]

Sync the given inspection document into the graph database.

sync_package_analysis_result(document: dict) → None[source]

Sync the given package analysis result to the graph database.

sync_provenance_checker_result(document: dict) → None[source]

Sync provenance checker results into graph database.

sync_solver_result(document: dict) → None[source]

Sync the given solver result to the graph database.

thoth.storages.graph.sql_base module

A base class for implementing SQL based databases.

class thoth.storages.graph.sql_base.SQLBase(engine: sqlalchemy.engine.base.Engine = None, session=None)[source]

Bases: object

A base class for implementing SQL based databases using SQLAlchemy.

abstract connect()[source]

Connect to the database.

disconnect()[source]

Disconnect from the connected database.

drop_all() → None[source]

Drop all content stored in the database.

abstract initialize_schema() → None[source]

Initialize schema in the database.

is_connected()[source]

Check if the database is connected.

Module contents

A graph database adapter for communicating with dgraph via gRPC.