Usage Guide 0.7.4

This section walks you through connecting Atoti Limits to an Atoti Server with the python API using the Atoti Limits Python plugin.

Usage

1. Start the Limits server

Start the Atoti Limits server using the installation instructions in the Atoti Limits documentation and wait for a connection request.

2. Start the Python API

Create a session using the Python API, create a cube and wait for the Python API to connect to the running Limits server. By default, the atoti-limits plugin will attempt to connect to Limits using the following properties:

Property Default
limits.rest.url http://localhost:3090/limits/rest/v2/
limits.auth YWRtaW46YWRtaW4=
ap.auth YWRtaW46YWRtaW4=
content.server.auth YWRtaW46YWRtaW4=

note

Registering the LookUpPostProcessor as in previous Atoti Limits versions, is no longer required.

Example code to create the session and cube would look as follows:


import atoti as tt
from atoti import Session

# Create the session

# JWT config parameters used by the Atoti Python API. These should be the same as the keys in jwt.properties
jwt_config = tt.JwtConfig(
    key_pair=tt.KeyPair(
        public_key="{publicKey}",
        private_key="{privateKey}"
    )
)

session = tt.Session(
    name="atoti",
    port=6060,
    jwt=jwt_config,
    same_site="none",
    authentication=tt.BasicAuthenticationConfig()
)

# Add an authenticated user. This is required in order for Limits to send REST requests to the server. Note that the ACTIVITI Roles must be added.
user_service_client = UserServiceClient.from_session(session)

role_activiti_user = user_service_client.create_role("ROLE_ACTIVITI_USER", restrictions={})
role_activiti_admin = user_service_client.create_role("ROLE_ACTIVITI_ADMIN", restrictions={})
role_managers = user_service_client.create_role("ROLE_MANAGERS", restrictions={})
role_limits = user_service_client.create_role("ROLE_LIMITS", restrictions={})

admin = user_service_client.basic.create_user("admin", password="admin")
user_service_client.individual_roles[admin.username].add(role_activiti_user.name)
user_service_client.individual_roles[admin.username].add(role_activiti_admin.name)
user_service_client.individual_roles[admin.username].add(role_managers.name)
user_service_client.individual_roles[admin.username].add(role_limits.name)

user1 = user_service_client.basic.create_user("user1", password="user1")
user_service_client.individual_roles[user1.username].add(role_activiti_user.name)
user_service_client.individual_roles[user1.username].add(role_limits.name)
user_service_client.individual_roles[user1.username].add("ROLE_USER")

manager1 = user_service_client.basic.create_user("manager1", password="manager1")
user_service_client.individual_roles[manager1.username].add(role_activiti_user.name)
user_service_client.individual_roles[manager1.username].add(role_limits.name)
user_service_client.individual_roles[manager1.username].add("ROLE_USER")
user_service_client.individual_roles[manager1.username].add(role_managers.name)

# At this point the Atoti session will attempt to connect to the module. However, as the cube
# has not yet been created the connection request will not be sent.

# So let's create the cube:
# 1. Create the data table
session.create_table(
    "Cars",
    types={
        "CarName": tt.type.STRING,
        "Price": tt.type.FLOAT,
        "Date": tt.type.LOCAL_DATE,
    },
    keys=["CarName", "Date"]
)

# Note that we need to supply a slicing "Date" hierarchy. This is required by the LookUpPostProcessor
# to evaluate the Limit.

# 2. Load some data into the table
cars_table.load_csv("cars.csv")

# 3. Create the cube from the table
cube = session.create_cube(
    base_table=cars_table,
    name="Cars_Cube",
)

# 4. Set the date hierarchy as slicing, as per above
cube.hierarchies["Date"].slicing = True

At this point the Atoti session will send a connection request to the running Limits server and Atoti Limits will connect to the cube.

Atoti Limits is Connected!

Now your Atoti Python instance is ready to use Atoti Limits.

You will be able to use the Atoti Python UI - by default located at http://localhost:6060 - to view limit KPIs in the cube. To use the Atoti Limits UI, the user will have to set up their UI as per the UI Activation page. Note that the default server name for the Atoti Python cube is atoti.