Skip to content

API Reference

biokb_ipni.import_data

Import all data in database.

Parameters:

Name Type Description Default
engine Optional[Engine]

SQLAlchemy engine. Defaults to None.

None
force_download bool

If True, will force download the data, even if files already exist. If False, it will skip the downloading part if files already exist locally. Defaults to False.

False
delete_files bool

If True, downloaded files are deleted after import. Defaults to False.

False

Returns:

Type Description
dict[str, int]

Dict[str, int]: table=key and number of inserted=value

Source code in biokb_ipni/db/manager.py
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
def import_data(
    engine: Optional[Engine] = None,
    force_download: bool = False,
    delete_files: bool = False,
) -> dict[str, int]:
    """Import all data in database.

    Args:
        engine (Optional[Engine]): SQLAlchemy engine. Defaults to None.
        force_download (bool, optional): If True, will force download the data, even if
            files already exist. If False, it will skip the downloading part if files
            already exist locally. Defaults to False.
        delete_files (bool, optional): If True, downloaded files are deleted after import.
            Defaults to False.

    Returns:
        Dict[str, int]: table=key and number of inserted=value
    """
    db_manager = DbManager(engine)
    return db_manager.import_data(
        force_download=force_download, delete_files=delete_files
    )

biokb_ipni.create_ttls

Create all turtle files.

If engine=None tries to get the settings from environment else uses the default engine.

If export_to_folder is provided, turtle files are exported to this folder. Otherwise, the default export folder (~/.biokb/ipni/data) is used.

Parameters:

Name Type Description Default
engine Engine | None

SQLAlchemy engine. Defaults to None.

None
export_to_folder str | None

Folder to export ttl files. Defaults to None.

None

Returns:

Name Type Description
str str

path zipped file with ttls.

Source code in biokb_ipni/rdf/turtle.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
def create_ttls(
    engine: Optional[Engine] = None,
    export_to_folder: Optional[str] = None,
) -> str:
    """Create all turtle files.

    If engine=None tries to get the settings from environment else uses the default engine.

    If export_to_folder is provided, turtle files are exported to this folder. Otherwise,
    the default export folder (~/.biokb/ipni/data) is used.

    Args:
        engine (Engine | None, optional): SQLAlchemy engine. Defaults to None.
        export_to_folder (str | None, optional): Folder to export ttl files.
            Defaults to None.

    Returns:
        str: path zipped file with ttls.
    """
    ttl_creator = TurtleCreator(engine=engine)
    if export_to_folder:
        ttl_creator._set_ttls_folder(export_to_folder)
    return ttl_creator.create_ttls()

biokb_ipni.import_ttls

Import data into Neo4J from zipped turtle files.

Parameters:

Name Type Description Default
neo4j_uri str | None

URI of the Neo4j database.

None
neo4j_user str | None

Username for Neo4j.

None
neo4j_pwd str | None

Password for Neo4j.

None
delete_existing_graph bool

delete existing graph before import.

True

Returns: bool: True if import is successful.

Source code in biokb_ipni/rdf/neo4j_importer.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def import_ttls(
    neo4j_uri: str | None = None,
    neo4j_user: str | None = None,
    neo4j_pwd: str | None = None,
    delete_existing_graph: bool = True,
) -> bool:
    """Import data into Neo4J from zipped turtle files.

    Args:
        neo4j_uri (str | None): URI of the Neo4j database.
        neo4j_user (str | None): Username for Neo4j.
        neo4j_pwd (str | None): Password for Neo4j.
        delete_existing_graph (bool): delete existing graph before import.
    Returns:
        bool: True if import is successful.
    """
    importer = Neo4jImporter(
        neo4j_uri=neo4j_uri, neo4j_user=neo4j_user, neo4j_pwd=neo4j_pwd
    )
    result: bool = importer.import_ttls(delete_existing_graph=delete_existing_graph)
    return result