Links
Comment on page

Creating a New Python App

If you haven't already, you'll first need to set up your development environment and ensure you have a Grainite server running (can be running locally in a Docker container).

1. Develop your Application

Create your Application Config File

Here you would configure your application in a YAML file. You may use App Configuration Options as a reference.
app.yaml template
app_name: food_app
# For python: Location of root python app directories relative to this config file.
python_dir: python_app
topics:
- topic_name: orders_topic
key_name: order_id
key_type: string
tables:
- table_name: orders_table
key_type: string
action_handlers:
# Supported types: java, python
- type: python
script_path: handlers/orders_handler.py
actions:
- action_name: handleOrders
# `method_name` is optional. Default method_name is the `action_name`
method_name: handle_orders
# `handles_multiple_actions` is optional. Default is `false`.
handles_multiple_actions: false
subscriptions:
- subscription_name: orderUpdates
topic_name: orders_topic
topic_key: order_id

Implement the Application Logic

Implement your action handlers, client programs, and any other parts of your app's functionality. You may use the API pages here or the Grainite Pydocs for reference.

2. Load the Application

Load the application onto the Grainite server from the app's main directory.
gx load

4. Run the load

Run your client program to send events to the application.
python3 Client.py

5. Observe the Application

  • Print all events in the topic: gx topic dump <topic name>
  • Print all grains in the table: gx table dump <table name>
Refer to the GX CLI document for more in-depth information about gx.