Metadata-Version: 2.4
Name: kif-lib
Version: 0.13.0
Summary: A knowledge integration framework based on Wikidata
Home-page: https://github.com/IBM/kif
Author: IBM
Author-email: Guilherme.Lima@ibm.com
License: Apache-2.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx
Requires-Dist: lark
Requires-Dist: more_itertools
Requires-Dist: networkx
Requires-Dist: rdflib
Requires-Dist: types-networkx
Requires-Dist: typing-extensions
Provides-Extra: all
Requires-Dist: mkdocs; extra == "all"
Requires-Dist: flake8; extra == "all"
Requires-Dist: isort; extra == "all"
Requires-Dist: mypy; extra == "all"
Requires-Dist: pylint; extra == "all"
Requires-Dist: pyright; extra == "all"
Requires-Dist: pytest; extra == "all"
Requires-Dist: pytest-asyncio; extra == "all"
Requires-Dist: pytest-cov; extra == "all"
Requires-Dist: pytest-mypy; extra == "all"
Requires-Dist: pyupgrade; extra == "all"
Requires-Dist: setuptools; extra == "all"
Requires-Dist: tox; extra == "all"
Requires-Dist: click; extra == "all"
Requires-Dist: rich; extra == "all"
Requires-Dist: ddgs; extra == "all"
Requires-Dist: graphviz; extra == "all"
Requires-Dist: jpype1; extra == "all"
Requires-Dist: pandas; extra == "all"
Requires-Dist: pandas-stubs; extra == "all"
Requires-Dist: psutil; extra == "all"
Requires-Dist: types-click; extra == "all"
Requires-Dist: types-psutil; extra == "all"
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: mkdocs; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pylint; extra == "dev"
Requires-Dist: pyright; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-mypy; extra == "dev"
Requires-Dist: pyupgrade; extra == "dev"
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: tox; extra == "dev"
Requires-Dist: click; extra == "dev"
Requires-Dist: rich; extra == "dev"
Requires-Dist: ddgs; extra == "dev"
Requires-Dist: graphviz; extra == "dev"
Requires-Dist: jpype1; extra == "dev"
Requires-Dist: pandas; extra == "dev"
Requires-Dist: pandas-stubs; extra == "dev"
Requires-Dist: psutil; extra == "dev"
Requires-Dist: types-click; extra == "dev"
Requires-Dist: types-psutil; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs; extra == "docs"
Provides-Extra: tests
Requires-Dist: flake8; extra == "tests"
Requires-Dist: isort; extra == "tests"
Requires-Dist: mypy; extra == "tests"
Requires-Dist: pylint; extra == "tests"
Requires-Dist: pyright; extra == "tests"
Requires-Dist: pytest; extra == "tests"
Requires-Dist: pytest-asyncio; extra == "tests"
Requires-Dist: pytest-cov; extra == "tests"
Requires-Dist: pytest-mypy; extra == "tests"
Requires-Dist: pyupgrade; extra == "tests"
Requires-Dist: setuptools; extra == "tests"
Requires-Dist: tox; extra == "tests"
Provides-Extra: cli
Requires-Dist: click; extra == "cli"
Requires-Dist: rich; extra == "cli"
Provides-Extra: extra
Requires-Dist: ddgs; extra == "extra"
Requires-Dist: graphviz; extra == "extra"
Requires-Dist: jpype1; extra == "extra"
Requires-Dist: pandas; extra == "extra"
Requires-Dist: pandas-stubs; extra == "extra"
Requires-Dist: psutil; extra == "extra"
Requires-Dist: types-click; extra == "extra"
Requires-Dist: types-psutil; extra == "extra"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

![KIF](docs/img/kif-b.svg#gh-light-mode-only)
![KIF](docs/img/kif-w.svg#gh-dark-mode-only)

---

# Knowledge Integration Framework

KIF is a Python framework for knowledge integration from [IBM Research](https://research.ibm.com/).

It is based on [Wikidata](https://www.wikidata.org/) and licensed under the open-source
[Apache-2.0
license](https://raw.githubusercontent.com/IBM/kif/refs/heads/main/LICENSE).

First time here? Check out the [tutorial](https://ibm.github.io/kif/tutorial/).

Looking for the sources? See the [GitHub repository](https://github.com/IBM/kif).

[![Supported Python Versions](https://img.shields.io/pypi/pyversions/kif_lib)](https://pypi.org/project/kif_lib/) [![PyPI version](https://badge.fury.io/py/kif_lib.svg)](https://badge.fury.io/py/kif_lib) [![Downloads](https://pepy.tech/badge/kif_lib/month)](https://pepy.tech/project/kif_lib)

---

## Hello world!

Install KIF using pip:

```shell
$ pip install kif-lib
```

Use KIF to query [Wikidata](https://www.wikidata.org/):

```pycon
>>> from kif_lib import Store
>>> from kif_lib.vocabulary import wd
>>> kb = Store('wikidata')
>>> next(kb.filter(subject=wd.Alan_Turing, property=wd.doctoral_advisor))
Statement(Item(IRI('http://www.wikidata.org/entity/Q7251')), ValueSnak(...))
```

Or, via KIF CLI (the command-line interface):

```shell
$ pip install kif-lib[cli]    # KIF CLI is an optional dependency
$ kif filter --subject=wd.Alan_Turing --property=wd.doctoral_advisor
```

> (**Statement** (**Item** [Alan Turing](http://www.wikidata.org/entity/Q7251)) (**ValueSnak** (**Property** [doctoral advisor](http://www.wikidata.org/entity/P184)) (**Item** [Alonzo Church](http://www.wikidata.org/entity/Q92741))))

KIF can also be used query other knowledge sources.  Here is a similar query over [DBpedia](https://www.dbpedia.org/) (notice the `-s dbpedia` switch):

```shell
$ kif filter -s dbpedia --subject=db.Alan_Turing --property=wd.doctoral_advisor
```

> (**Statement** (**Item** [dbr:Alan_Turing](http://dbpedia.org/resource/Alan_Turing)) (**ValueSnak** (**Property** [dbo:doctoralAdvisor](http://dbpedia.org/ontology/doctoralAdvisor)) (**Item** [dbr:Alonzo_Church](http://dbpedia.org/resource/Alonzo_Church))))

The result is a stream of Wikidata-like statements containing DBpedia entities.

## KIF in a nutshell

KIF is a knowledge integration framework based on [Wikidata](https://www.wikidata.org/).  The idea behind it is to use Wikidata to standardize the syntax and (whenever possible) the vocabulary of the integrated knowledge sources.  Users can then query the sources through filter patterns described in terms of the [Wikidata data model](https://www.wikidata.org/wiki/Wikidata:Data_model).

The integration done by KIF is *virtual* in the sense that syntax and vocabulary translations happen dynamically (at query time) and are guided by user-provided mappings.  KIF comes with built-in mappings for [Wikidata](https://www.wikidata.org/), [DBpedia](https://www.dbpedia.org/), [FactGrid](https://database.factgrid.de/), [PubChem](https://pubchem.ncbi.nlm.nih.gov/), and [UniProt](https://www.uniprot.org/), among others.  New mappings can be added programmatically.

### Highlights

* KIF allows one to query knowledge sources as if they were Wikidata.

* KIF queries are written as simple, high-level filters using entities of the [Wikidata data model](https://www.wikidata.org/wiki/Wikidata:Data_model), such as items, properties, quantities, snaks, statements, etc.

* KIF can be used to query Wikidata itself or other knowledge sources, provided proper mappings are given.

* KIF can run queries over local RDF data using [RDFLib](https://rdflib.readthedocs.io/en/stable/), [Apache Jena](https://jena.apache.org/), [QLever](https://qlever.dev/), or [RDFox](https://www.oxfordsemantic.tech/rdfox).

* KIF has full support for Python's [asyncio](https://docs.python.org/3/library/asyncio.html).  KIF async API can be used run queries asynchronously, without blocking waiting on their results.


## Installation

To install KIF, use:

```shell
$ pip install kif-lib
```

To include KIF CLI, use:

```shell
$ pip install kif-lib[cli]
```

To include all extras, use:

```shell
$ pip install kif-lib[extra]
```

## Documentation

KIF documentation is available at [https://ibm.github.io/kif/](https://ibm.github.io/kif/).

For a primer on KIF, see the [tutorial](https://ibm.github.io/kif/tutorial/).

## Dependencies

Required:

* [httpx](https://www.python-httpx.org/) - HTTP support.
* [lark](https://lark-parser.readthedocs.io/en/stable/) - Parsing.
* [more_itertools](https://more-itertools.readthedocs.io/en/stable/index.html) - Extra itertools.
* [networkx](https://networkx.org/) - Graph algorithms.
* [rdflib](https://rdflib.readthedocs.io/en/stable/) - RDF support.
* [typing-extensions](https://typing-extensions.readthedocs.io/en/latest/) - Typing backports.

KIF CLI (optional):

* [click](https://click.palletsprojects.com/en/stable/) - Option parsing. *(Optional, with `kif-lib[cli]`)*
* [rich](https://rich.readthedocs.io/en/latest/introduction.html) - Rich terminal support.  *(Optional, with `kif-lib[cli]`)*

Extra (optional):

* [graphviz](https://graphviz.readthedocs.io/en/stable/manual.html) - Graph drawing. *(Optional, with `kif-lib[extra]`)*
* [jpype1](https://jpype.readthedocs.io/en/latest/) - Java support. *(Optional, with `kif-lib[extra]`)*
* [pandas](https://pandas.pydata.org/) - CSV/DataFrame support. *(Optional, with `kif-lib[extra]`)*
* [psutil](https://psutil.readthedocs.io/en/latest/) - Process information. *(Optional, with `kif-lib[extra]`)*

## Citation

Guilherme Lima, João M. B. Rodrigues, Marcelo Machado, Elton Soares, Sandro R. Fiorini, Raphael Thiago, Leonardo G. Azevedo, Viviane T. da Silva, Renato Cerqueira.  2024.  ["KIF: A Wikidata-Based Framework for Integrating Heterogeneous Knowledge Sources"](https://arxiv.org/abs/2403.10304), arXiv:2403.10304, 2024.
