Hansken Hansken Python API

hansken.py is a Python module that facilitates use of the Hansken REST API from Python scripts. hansken.py is tested for Python 3.8 through 3.11.

Installation files

Installation files for hansken.py are available below. These can be installed by running the following command:

hansken.py for Python 3.8 and up

$ pip install hansken-2024.3.29-py3-none-any.whl

The distribution defines a number of extras, which enable additional functionality for hansken.py. Extras can be installed by adding [extra-name] to the installation of hansken.py through pip, e.g.

$ pip install hansken-2024.3.29-py3-none-any.whl[all]

The following extras are defined:

shell

Enables the use of the shell command by installing the package ipython.

kerberos

Enables Kerberos authentication by installing the package requests-kerberos.

report

Enables the report recipe by installing the packages jinja2 and weasyprint.

mount

Enables the use of the mount command by installing the package fusepy.

all

Enables all of the above by installing every optional package required for all of the extras.

Hello, world!

Here is a simple “hello, world”-style script to print some details about files in a project with id deadbeef-c0de-c0de-c0de-badbadc0ffee:

from hansken.remote import ProjectContext

# create a object that allows us to interact with Hansken in the context
# of a particular project
with ProjectContext('https://hansken.example.nl/gatekeeper',
                    'deadbeef-c0de-c0de-c0de-badbadc0ffee') as context:
    # find all traces of type file
    results = context.search('type:file')
    for trace in results:
        # print a number of properties for each trace to stdout
        print(trace.id, trace.name, trace.file.modified_on)

It’s that simple! Note that this example does not use authentication; a real endpoint likely requires us to identify ourselves. Additionally, scripts will typically use hansken.tool.run as a starting point, making any script you’ll write usable for other people. If this is your first hansken.py rodeo, see getting started for more info.

Documentation

Contributions and feedback

Todo

  • Link to hansken community scripts / forge / gist / …

  • Spot an error, something ambiguous or something unexpectedly brilliant, let us know!

  • Come across behavior that seems wrong / run into a bug, let us know!

  • Find yourself doing the same thing over and over, submit a feature request to have it turned into a recipe?


Recent changes

Release

Change type

Description

2024.03.29

Feature

Add hansken.remote.ProjectContext.delete_clean_data to delete cleaned data from the cache, and the reclean param to hansken.remote.ProjectContext.queue_cleaning to delete clean data before cleaning

2024.03.20

Feature

Maintain blocking behaviour of hansken.remote.Connection.delete_project and hansken.remote.Connection.unlink_image for latest Hansken release

2024.02.14

Feature

Add argument engine to hansken.remote.Connection.extract to (optionally) allow the selection of a different extraction engine

2024.02.05

Feature

Expose SearchResult.num_results_quality, TraceletSearchResult.num_results_quality, ValueSearchResult.num_results_quality and FacetResult.count_error

2024.01.11.1

Feature

Add arguments include_image_data and image_id to export to enable portable case

See full changelog.


Index