Getting started with Kodexa using the Event Model Cookie Cutter
The cookie-cutter-kodexa-event-model
is a project template that helps you quickly set up a new Kodexa event model with the right structure and dependencies. Event models in Kodexa allow you to handle and respond to specific events that occur within the Kodexa platform, providing a way to build custom event-driven functionality.
This documentation will guide you through:
Before using this cookiecutter template, ensure you have the following installed:
You can install the required tools using pip:
Once you have the prerequisites installed, you can create a new project from the template by running:
You’ll be prompted to provide several configuration values defined in the cookiecutter.json file:
These values will be used to customize your project. Here’s what each prompt means:
After running the cookiecutter command, a new directory with your project_slug name will be created with the following structure:
model.py
This is the main file where you’ll implement your event handler. It comes with a basic implementation of the handle_event
function that receives events from the Kodexa platform:
You’ll need to modify this function to handle specific event types and implement your business logic.
model.yml
This file defines how your model will be deployed to the Kodexa platform, including:
Note the eventAware: true
property, which indicates that this model can handle events.
pyproject.toml
This file contains your project’s metadata and dependencies managed by Poetry, including:
makefile
The makefile includes several useful commands:
make format
: Format code using isort and blackmake lint
: Lint code using flake8 and mypymake test
: Run formatting and lintingmake clean
: Clean up build artifactsmake deploy
: Deploy the model to Kodexa platformmake undeploy
: Undeploy the model from Kodexa platformTo set up your new project in Visual Studio Code:
Open VS Code
Choose “File > Open Folder” and select your newly created project directory
Open a terminal in VS Code (Terminal > New Terminal)
Install dependencies using Poetry:
Activate the Poetry virtual environment:
For the best development experience, install these VS Code extensions:
In Kodexa, event models are used to handle specific events that occur within the platform. Events can be related to documents, users, projects, and more. Event models allow you to build custom logic that responds to these events.
While you’ll need to refer to the Kodexa documentation for a complete list of available events, here are some common event types:
The main entry point for your event model is the handle_event
function in model.py
. This function receives a BaseEvent
object that contains information about the event, including:
event.type
: The type of eventThere are several types of events that you can handle, including:
ContentEvent
: A document has been created, updated, or deleted (this means the content of the document has changed)DocumentFamilyEvent
: A document family has been created, updated, or deletedTaskEvent
: A task has been created, updated, or deletedDataObjectEvent
: A data object has been created, updated, or deletedAssistantEvent
: An assistant has been created, updated, or deletedChannelEvent
: A channel has been created, updated, or deletedWorkspaceEvent
: A workspace has been created, updated, or deletedDataFormEvent
: A data form has been created, updated, or deletedOrchestrationEvent
: An orchestration has been created, updated, or deletedScheduledEvent
: A scheduled event has been triggeredYour task is to implement the logic that should run when specific events are received.
Here’s how to implement an event handler for document changes:
When your event model is ready, you can deploy it to the Kodexa platform:
This will use the Kodexa CLI to deploy your model according to the configuration in model.yml.
Let’s implement a more complete example of an event model that sends notifications when documents are processed:
If you encounter module import errors, make sure:
poetry shell
)poetry install
)If your model fails to deploy:
If your event handler isn’t being triggered:
Getting started with Kodexa using the Event Model Cookie Cutter
The cookie-cutter-kodexa-event-model
is a project template that helps you quickly set up a new Kodexa event model with the right structure and dependencies. Event models in Kodexa allow you to handle and respond to specific events that occur within the Kodexa platform, providing a way to build custom event-driven functionality.
This documentation will guide you through:
Before using this cookiecutter template, ensure you have the following installed:
You can install the required tools using pip:
Once you have the prerequisites installed, you can create a new project from the template by running:
You’ll be prompted to provide several configuration values defined in the cookiecutter.json file:
These values will be used to customize your project. Here’s what each prompt means:
After running the cookiecutter command, a new directory with your project_slug name will be created with the following structure:
model.py
This is the main file where you’ll implement your event handler. It comes with a basic implementation of the handle_event
function that receives events from the Kodexa platform:
You’ll need to modify this function to handle specific event types and implement your business logic.
model.yml
This file defines how your model will be deployed to the Kodexa platform, including:
Note the eventAware: true
property, which indicates that this model can handle events.
pyproject.toml
This file contains your project’s metadata and dependencies managed by Poetry, including:
makefile
The makefile includes several useful commands:
make format
: Format code using isort and blackmake lint
: Lint code using flake8 and mypymake test
: Run formatting and lintingmake clean
: Clean up build artifactsmake deploy
: Deploy the model to Kodexa platformmake undeploy
: Undeploy the model from Kodexa platformTo set up your new project in Visual Studio Code:
Open VS Code
Choose “File > Open Folder” and select your newly created project directory
Open a terminal in VS Code (Terminal > New Terminal)
Install dependencies using Poetry:
Activate the Poetry virtual environment:
For the best development experience, install these VS Code extensions:
In Kodexa, event models are used to handle specific events that occur within the platform. Events can be related to documents, users, projects, and more. Event models allow you to build custom logic that responds to these events.
While you’ll need to refer to the Kodexa documentation for a complete list of available events, here are some common event types:
The main entry point for your event model is the handle_event
function in model.py
. This function receives a BaseEvent
object that contains information about the event, including:
event.type
: The type of eventThere are several types of events that you can handle, including:
ContentEvent
: A document has been created, updated, or deleted (this means the content of the document has changed)DocumentFamilyEvent
: A document family has been created, updated, or deletedTaskEvent
: A task has been created, updated, or deletedDataObjectEvent
: A data object has been created, updated, or deletedAssistantEvent
: An assistant has been created, updated, or deletedChannelEvent
: A channel has been created, updated, or deletedWorkspaceEvent
: A workspace has been created, updated, or deletedDataFormEvent
: A data form has been created, updated, or deletedOrchestrationEvent
: An orchestration has been created, updated, or deletedScheduledEvent
: A scheduled event has been triggeredYour task is to implement the logic that should run when specific events are received.
Here’s how to implement an event handler for document changes:
When your event model is ready, you can deploy it to the Kodexa platform:
This will use the Kodexa CLI to deploy your model according to the configuration in model.yml.
Let’s implement a more complete example of an event model that sends notifications when documents are processed:
If you encounter module import errors, make sure:
poetry shell
)poetry install
)If your model fails to deploy:
If your event handler isn’t being triggered: