Skip to main content

Knowledge Graph Parser

Python 3.10
MIT License
Project Status - Alpha
Code Style

Overview

kg-parser is a Python package and CLI application that extracts structured knowledge graph triples from unstructured text using large language models (LLMs). The package supports multiple backends (HuggingFace, OpenAI, and local Jan) and offers flexible output formats—either as arrays of strings or as dictionaries.

Features

  • Multi-backend Support: Use HuggingFace, OpenAI, or a local Jan server.
  • Batch Processing: Process multiple texts efficiently.
  • Flexible Output: Choose between list or dict representations for triples.
  • CLI & API: Easily run as a command-line tool or integrate into your Python projects.

Installation

Using Conda

Create and activate the conda environment with the provided configuration:

conda env create -f environment.yml
conda activate kg-parser

Using Pip

Install the package directly from PyPI:

pip install kg-parser

Install the minimal dependencies from requirements.txt:

pip install -r requirements.txt

Alternatively, install the package in editable mode:

pip install -e .

Usage

As a CLI Application

Run the CLI tool from the command line:

python -m kg_parser.cli \
  --model-type huggingface \
  --model-name-or-path "google/flan-t5-small" \
  --input-file test_input.json \
  --output-file output_kg.json \
  --triple-format list

Arguments:

  • --model-type: Choose from huggingface, openai, or jan_local.
  • --model-name-or-path: Specify the model name or path.
  • --input-file: Path to a JSON file containing an array of text strings.
  • --output-file: Path where the output JSON will be saved.
  • --triple-format: Output format for triples (list for arrays or dict for dictionaries).

As a Python Package

Import and use kg-parser in your own Python scripts:

from kg_parser.config import ModelConfig, ModelType
from kg_parser.core import KGParser

# Configure the model
model_config = ModelConfig(
    model_type=ModelType.HUGGINGFACE,
    model_name_or_path="google/flan-t5-small"
)
parser = KGParser(model_config)

# Process texts
texts = [
    "Mount Everest is the highest mountain in the world. It's located in Nepal."
]
results = parser.parse_batch(texts)

# Save results with triples as lists
parser.save_to_json(results, "output_kg.json", triple_format="list")

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Metadata

Release files for kg-parser 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kg-parser 0.1.1
File Size Uploaded Provenance Actions
kg_parser-0.1.1.tar.gz 11.1 kB Without provenance Details for kg_parser-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kg-parser 0.1.1
File Interpreter ABI Platform Actions
kg_parser-0.1.1-py3-none-any.whl Python 3 none any Details for kg_parser-0.1.1-py3-none-any.whl

Total release size: 22.5 kB

Release files / kg_parser-0.1.1.tar.gz

Download URL kg_parser-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1a178fbf5ac5febc00c24daf7e3625f5f725bce0475aadab9c24d7ed523db873
BLAKE2b-256 checksum
How to use checksums
3a46ee4fbdbcbe4afc694ee6b5408c6764d92a2ff99d6c445ea2903283793fe9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Release files / kg_parser-0.1.1-py3-none-any.whl

Download URL kg_parser-0.1.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
927584b40906718dc0abedb38ad29aa1d4d6d7aa9031506f263060706b13be7b
BLAKE2b-256 checksum
How to use checksums
83d55f882ee34e599811210fd1f8c87713e40c228655dd176d0d2726134042d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Security for kg-parser 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page