The best way to get started with the Knowledge Mapper is by exploring the examples in this folder. Each example demonstrates a specific feature or pattern with detailed comments in the code.
| Example | Description |
|---|---|
| 01-basic.py | A minimal knowledge base with a simple answer knowledge interaction |
| 02-binding_models.py | Demonstrates using Pydantic-style binding models for type-safe bindings |
| 03-ask_interaction.py | Shows how to handle ASK knowledge interactions |
| 04-post_measurement.py | Demonstrates POST interactions for ingesting measurements or data |
| 05-custom-settings/ | Shows how to use custom settings to configure your knowledge mapper |
| 06-dependency_injection.py | Uses dependency injection to inject resources like configs or database connections |
| 07-testing/ | Demonstrates how to write tests for your knowledge base using the fake client |
| 08-async_handlers.py | Demonstrates async REACT handlers and how they differ from sync handlers |
| 09-sparql-store/ | Connecting a SPARQL store as a knowledge base |
| 10-cli.py | Start a KB via the knowledge-mapper run CLI — no asyncio.run boilerplate |
Before running the examples, you need to have a Knowledge Engine instance running. The examples expect it to be available at http://localhost:8280/rest.
Use the provided Docker Compose file to start a Knowledge Engine instance:
docker-compose up -dThis starts the Knowledge Engine and related services in the background. To stop them:
docker-compose downFirst, install the knowledge mapper in your Python environment:
pip install knowledge_mapperOr, if you're developing locally, install it in editable mode from the project root:
pip install -e .To run an example, navigate to the examples folder and execute the Python script:
cd examples
python 01-basic.pyMost examples will start the knowledge mapper and connect to the Knowledge Engine. Press Ctrl+C to stop.
Example 10-cli.py is started through the knowledge-mapper CLI instead of python:
cd examples
knowledge-mapper run 10-cli.py:kbThe CLI handles connect, register, the handling loop, and graceful shutdown on Ctrl+C.
The 07-testing/ example includes test examples. Run them with:
python -m pytest 07-testing/- Start with 01-basic.py to understand the minimal setup
- Explore 02-binding_models.py to learn about type-safe bindings
- Look at 03-ask_interaction.py and 04-post_measurement.py to see different KI types
- Check 05-custom-settings/ for configuration patterns
- Study 06-dependency_injection.py to see how to manage dependencies
- Review 07-testing/ to learn testing strategies
- Run 08-async_handlers.py to compare async and sync REACT handler behavior
- Explore 09-sparql-store/ to see how to connect a SPARQL store
- Each example has inline comments explaining the code
- The
shared.pymodule contains utilities used by examples (like logging setup) - To see detailed logs, check the output when running examples
- The examples use
http://localhost:8280/restas the default Knowledge Engine endpoint