{"id":19287788,"url":"https://github.com/deeppavlov/custom_kg_svc","last_synced_at":"2026-01-24T02:36:36.950Z","repository":{"id":63045615,"uuid":"498744647","full_name":"deeppavlov/custom_kg_svc","owner":"deeppavlov","description":"API to work with knowledge bases at runtime","archived":false,"fork":false,"pushed_at":"2024-08-26T18:37:25.000Z","size":5573,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-26T21:50:02.433Z","etag":null,"topics":["chatbot","graph-database","neo4j","terminusdb"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deeppavlov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-01T13:19:49.000Z","updated_at":"2022-11-15T08:54:24.000Z","dependencies_parsed_at":"2024-06-13T10:21:06.212Z","dependency_job_id":null,"html_url":"https://github.com/deeppavlov/custom_kg_svc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeppavlov%2Fcustom_kg_svc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeppavlov%2Fcustom_kg_svc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeppavlov%2Fcustom_kg_svc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deeppavlov%2Fcustom_kg_svc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deeppavlov","download_url":"https://codeload.github.com/deeppavlov/custom_kg_svc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888420,"owners_count":17220083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","graph-database","neo4j","terminusdb"],"created_at":"2024-11-09T22:07:13.613Z","updated_at":"2026-01-24T02:36:31.930Z","avatar_url":"https://github.com/deeppavlov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Knowledge graph API is designed to provide an easy interface to CRUD data to databases like TerminusDB and Neo4j in the runtime.\n# Installation\n\nHere is a step by step guide to install Custom KG. It will get you to a point of having \na database up and running *in one of three ways* and the API ready to deal with it.\n\nClone the repository somewhere on your disk and enter the repository:\n```\ngit clone https://github.com/deeppavlov/custom_kg_svc.git\ncd custom_kg_svc\n```\n\nInstall the dependencies using *pip*:\n```\npip install -e .\n```\n\n## Way 1: For using Neo4j as a database:\n\nRun the docker container inside custom_kg_svc to deploy neo4j database:\n\n```\ndocker-compose up\n```\nNow as the neo4j database is up and running on http://localhost:7474/ you can connect to it using the API:\n\n```python\nNEO4J_BOLT_URL = \"bolt://neo4j:neo4j@localhost:7687\"\nONTOLOGY_KINDS_HIERARCHY_PATH = \"deeppavlov_kg/database/ontology_kinds_hierarchy.pickle\"\nONTOLOGY_DATA_MODEL_PATH = \"deeppavlov_kg/database/ontology_data_model.json\"\nDB_IDS_FILE_PATH = \"deeppavlov_kg/database/db_ids.txt\"\n\nneo_kg = Neo4jKnowledgeGraph(\n        neo4j_bolt_url=NEO4J_BOLT_URL,\n        ontology_kinds_hierarchy_path=ONTOLOGY_KINDS_HIERARCHY_PATH,\n        ontology_data_model_path=ONTOLOGY_DATA_MODEL_PATH,\n        db_ids_file_path=DB_IDS_FILE_PATH,\n    )\n```\n\n## Way 2: For using local TerminusDB database:\n\n[Clone the TerminusDB bootstrap repository](https://terminusdb.com/docs/get-started/install/install-as-docker-container#clone-the-terminusdb-bootstrap) and run the docker *terminusdb-container* inside. Now, your local database is ready on http://localhost:6363/ you can enter the dashboard using default username and password *(admin, root)*, respectively. To connect to it using the API you do:\n\n```python\nDB = \"example_db\"\nTEAM =\"admin\"\nterminus_kg = TerminusdbKnowledgeGraph(team=TEAM, db_name=DB, local=True)\n```\n## Way 3: For using cloud TerminusDB database:\n\n[Create an account on TerminusX cloud](https://dashboard.terminusdb.com/), select a team, and generate a personal access token in your profile page and save it somewhere on your disk. Then, export the token in *bash* as environment variable:\n\n```\nexport TERMINUSDB_ACCESS_TOKEN=\"YOUR_TOKEN\"\n```\nNow, connect to the database on the cloud like so:\n\n```python\nterminus_kg = TerminusdbKnowledgeGraph(team=TEAM_FROM_CLOUD, db_name=DB)\n```\n## Mocks and tests\nRun mocking test to populate neo4j ontology and knowledge graph\n```\ndocker-compose up\npython deeppavlov_kg/mocks/mock_base.py --neo4j\n```\n\nRun mocking test to populate neo4j ontology and knowledge graph\n* Run local terminusdb docker first\n* Run\n    ```\n    python deeppavlov_kg/mocks/mock_base.py --terminusdb\n    ```\nUse *--neo4j* and *--terminusdb* together to populate both in one run.\n\nOr import mocks directly in your code\n\n```python\nfrom deeppavlov_kg import Neo4jKnowledgeGraph, TerminusdbKnowledgeGraph, mocks\n\nneo4j_graph = Neo4jKnowledgeGraph(\n    \"bolt://neo4j:neo4j@localhost:7687\",\n    ontology_kinds_hierarchy_path=\"deeppavlov_kg/database/ontology_kinds_hierarchy.pickle\",\n    ontology_data_model_path=\"deeppavlov_kg/database/ontology_data_model.json\",\n    db_ids_file_path=\"deeppavlov_kg/database/db_ids.txt\"\n)\nterminusdb_graph = TerminusdbKnowledgeGraph(team=\"admin\", db_name=\"example_db\", local=True)\n\n# run all mocks\nmocks.populate_neo4j(neo4j_graph)\nmocks.populate_terminusdb(terminusdb_graph)\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeppavlov%2Fcustom_kg_svc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeeppavlov%2Fcustom_kg_svc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeppavlov%2Fcustom_kg_svc/lists"}