- Supports for
Python 3.9and higher. Poetryas the dependencies manager. See configuration inpyproject.tomlandsetup.cfg.- Automatic codestyle with
black,isortandpyupgrade. - Ready-to-use
pre-commithooks with code-formatting. - Type checks with
mypy; docstring checks withdarglint; security checks withsafetyandbandit - Testing with
pytest.
GitHubintegration: issue and pr templates.Github Actionswith predefined build workflow as the default CI/CD.- Everything is already set up for security checks, codestyle checks, code formatting, testing, linting, docker builds, etc with
Makefile. More details in makefile-usage. - Dockerfile for your package.
- Always up-to-date dependencies with
@dependabot. You will only enable it. - Automatic drafts of new releases with
Release Drafter. You may see the list of labels inrelease-drafter.yml. Works perfectly with Semantic Versions specification.
- Ready-to-use Pull Requests templates and several Issue templates.
- Files such as:
LICENSE,CONTRIBUTING.md,CODE_OF_CONDUCT.md, andSECURITY.mdare generated automatically. Stale botthat closes abandoned issues after a period of inactivity. (You will only need to setup free plan). Configuration is here.- Semantic Versions specification with
Release Drafter.
pip install git+https://github.com/process-intelligence-research/ChemEngKG_kgtoolThen you can run
kgtool --helpor with Poetry:
poetry run kgtool --helpImport the package to your python project with
from kgtool.interface import *and setup a connection to the ChemEngKG with
chemkg = ChemKG(url="api_url", graph="graph_name")where api_url is the url of the ChemEngKG GraphQL-API and graph_name is the name of the default graph you want to access.
You can also use
chemkg_dev = ChemKG.dev()for development purposes. This will connect to a local instance of the ChemEngKG, thus make sure to have the ChemEngKG running locally (see ChemEngKG_backend repository for further guidance).
The interface provides a set of funcitonalities which can be accessed via the ChemKG class.
Since the interface always interacts with the ChemEngKG via GraphQL the resonse is always a dictionary of the following form:
{
"data": {
"function_name": {
...
}
}
}or
{
"errors": [
...
]
}if an error occured in the backend.
FILL IN EXAMPLE
The following list gives an overview of the available functionalities:
getGraphs
chemkg.getGraphs()Retrieve the URI of all available graphs in the ChemEngKG.
Returns:
{"data": {
"getGraphs": {
"graphs":[...]
}
}
}The graphs field contains a list of strings which are the URIs of the available graphs.
Note:
URI is the unique resource identifier of a graph. It is not the same as the graph name which is used to define the interfaces graph (chemkg.graph).
getGraph
chemkg.getGraph()Retrieve the contents of a the graph defined in chemkg.graph as turtle string.
Returns:
{"data": {
"getGraph": {
"contents": ...
}
}
}The contents field contains a string which is the turtle representation of the graph in chemkg.graph.
runSparql
chemkg.runSparql(query)Runs a SPARQL query on the graph defined in chemkg.graph and returns the response.
Inputs:
query: SPARQL query string
Returns:
{"data": {
"runSparql": {
"response":
}
}
}The response field contains the response of the SPARQL query. Since it can look very different depending on the query here is a small example:
runSparql Example
For a query like
```sparql
SELECT ?s ?p ?o
WHERE {
?s ?p ?o
}
```
the respnse would look like this:
```json
{"data": {
"runSparql": {
"response": {
"head": {
"link": [],
"vars": ["s", "p", "o"]
},
"results": {
"distinct": False,
"ordered": True,
"bindings": [{
"s": {
"type": "uri",
"value": "http://www.openlinksw.com/virtrdf-data-formats#default-iid"
},
"p": {
"type": "uri",
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"o": {
"type": "uri",
"value": "http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat"
}
}]
}
}
}
}}
```
uploadFile
chemkg.uploadFile(file_path, URI)Uploads a file to the ChemEngKG. The file is attached to the object defined by URI.
Inputs:
file_path: path to the file to be uploadedURI: URI of the object in the graph to which the file should be attached.
Returns:
{"data": {
"uploadFile": {
"fileName": ...,
"subjectURI": ...,
"predicate": ...,
"fileURI": ...,
"hashURI": ...
}
}}fileName: name the uploaded file is stored under in the ChemEngKG filestorage. You can use this name to download the file sending a request to<filestorageURL>/uploads/<fileName>.subjectURI: URI of the object in the graph to which the file is attached.predicate: predicate of the triple which connects the object to the file. This should either befrbr:exemplarorfrbr:part.fileURI: URI of the file node in the graph.hashURI: URI of the hash node in the graph.
deleteFile
chemkg.deleteFile(fileURI)Deletes a file from the ChemEngKG filestorage and removes all afiliated triples in the graph. The file is identified by its URI.
Inputs:
fileURI: URI of the file to be deleted
Returns:
{"data": {
"deleteFile": {
"response": ...
}
}
}uploadTurtle
chemkg.uploadTurtle(turtle: str)Uploads a turtle file to the ChemEngKG.
Inputs:
turtle: file path to the turtle file to be uploaded
Returns:
{"data": {
"uploadTurtle": {
"response": ...
}
}
}Makefile contains a lot of functions for faster development.
1. Download and remove Poetry
To download and install Poetry run:
make poetry-downloadTo uninstall
make poetry-remove2. Install all dependencies and pre-commit hooks
Install requirements:
make installPre-commit hooks coulb be installed after git init via
make pre-commit-install3. Codestyle
Automatic formatting uses pyupgrade, isort and black.
make codestyle
# or use synonym
make formattingCodestyle checks only, without rewriting files:
make check-codestyleNote:
check-codestyleusesisort,blackanddarglintlibrary
Update all dev libraries to the latest version using one comand
make update-dev-deps4. Code security
make check-safetyThis command launches Poetry integrity checks as well as identifies security issues with Safety and Bandit.
make check-safety5. Type checks
Run mypy static type checker
make mypy6. Tests with coverage badges
Run pytest
make test7. All linters
Of course there is a command to rule run all linters in one:
make lintthe same as:
make test && make check-codestyle && make mypy && make check-safety8. Docker
make docker-buildwhich is equivalent to:
make docker-build VERSION=latestRemove docker image with
make docker-removeMore information about docker.
9. Cleanup
Delete pycache files
make pycache-removeRemove package build
make build-removeDelete .DS_STORE files
make dsstore-removeRemove .mypycache
make mypycache-removeOr to remove all above run:
make cleanupYou can see the list of available releases on the GitHub Releases page.
We follow Semantic Versions specification.
We use Release Drafter. As pull requests are merged, a draft release is kept up-to-date listing the changes, ready to publish when you’re ready. With the categories option, you can categorize pull requests in release notes using labels.
| Label | Title in Releases |
|---|---|
enhancement, feature |
🚀 Features |
bug, refactoring, bugfix, fix |
🔧 Fixes & Refactoring |
build, ci, testing |
📦 Build System & CI/CD |
breaking |
💥 Breaking Changes |
documentation |
📝 Documentation |
dependencies |
⬆️ Dependencies updates |
You can update it in release-drafter.yml.
GitHub creates the bug, enhancement, and documentation labels for you. Dependabot creates the dependencies label. Create the remaining labels on the Issues tab of your GitHub repository, when you need them.
This project is licensed under the terms of the MIT license. See LICENSE for more details.
@misc{kgtool,
author = {Kleinpaß, Marvin and Kondakov, Valentin and Gao, Qinghe and Schulze Balhorn, Lukas and Schweidtmann, Artur M.},
doi = {10.4121/83abb8a2-73f8-4f45-994c-a904268757ae.v1},
title = {KG-tool: Python package for accessing the Chemical Engineering Knowledge Graph (ChemEngKG)},
year = {2024},
publisher = {4TU.ResearchData},
keywords = {Artificial intelligence, chemical engineering, knowledge graph, flowsheet simulations, chemical process development},
copyright = {MIT},
url = {https://doi.org/10.4121/83abb8a2-73f8-4f45-994c-a904268757ae}
}