Categories
Articles

atoti v0.6.5: Make way for more intuitive programming

Comes with concise functional calls to improve your coding experience

I remember when I first learned to program, I didn’t have a clue about classes, functions and variables, etc (in the case of Java back then). Silly old me thought variables must be named alphabetically, ranging from a to z until I exhaust all of them. 😀 

Java code snippet from W3Schools

As with most sample code snippets, function names are usually just symbolic. Looking at the code snippet above, are we able to tell what the function myMethod does? What exactly is the variable Z with regards to the input parameter x and y?

Function names shouldn’t be random. It should be as informative as possible to the person reviewing the code, and also as intuitive to the person writing the code. For instance, IMHO mySum would be more informative than myMethod in this case. In like manner, is mySum or mySummation better? K.I.S.S.-Keep It Short, Stupid…

What gets deprecated in atoti v0.6.5?

What has the above got to do with the new atoti v0.6.5 recently released? In this article, we are going to zoom in on the Deprecated section in the changelog.

Deprecated modules from atoti changelog

To begin with, we see the verb “create” has been dropped from most deprecated functions and users are able to instantiate the classes directly. We went from a class and a function to create it to just a class, so the API is smaller and easier to learn. 

Deprecating atoti.create_session

This change affects all users of atoti. We can quickly instantiate an atoti session by invoking atoti.Session directly. K.I.S.S. Remember it’s Session with a capital letter S.

One benefit of this change is that now we can directly pass the configurations as input parameters to the constructor. Consequently, we will be able to use the “Tab” key to see the available parameters for the function. This is definitely more user-friendly than the previous JSON input for the configuration to create_session

Syntax comparison for instantiating session in atoti v0.6.4 and v0.6.5, using example from Burrito notebook.
Reference from the burritos notebook in atoti notebook gallery

Client-side encryption in atoti for Cloud connectivity

Similarly, in client-side encryption for Azure or AWS connection, we can now quickly instantiate the classes atoti_azure.AzureKeyPair or atoti_aws.AwsKeyPair as demonstrated below:

client_side_encryption_config = AwsKeyPair(
    region="eu-west-3",
    private_key="private_key",
    public_key="public_key",
)

Alternatively, if you are using KMS configuration for AWS:

from atoti_aws import AwsKmsConfig

client_side_encryption_config = (
    AwsKmsConfig(
        region="eu-west-3",
        key_id="key_id",
    ),
)

Predefined ordering for members of levels

When we query a cube, we can define the default order for the members of the level. In the previous versions, we had:

  • atoti.comparator.ASCENDING
  • atoti.comparator.DESCENDING
  • atoti.comparator.first_members()

The functions are now streamlined to the following:

So, to order a level in descending order:

h, l, m = cube.hierarchies, cube.levels, cube.measures

l["date"].order = tt.NaturalOrder(ascending=False)
Ordering in descending order in atoti v0.6.5, using example from Global Covid Data notebook.
Dates arranged in descending order (Refer to Global Covid Data notebook)

On the other hand, atoti.CustomOrder allows us to fix the order of the members to any predefined sequence:

l["Month"].order = tt.CustomOrder(
    first_elements=[
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
    ]
)
Custom ordering in atoti v0.6.5, using example from Bike Sales notebook.
Months sorted in predefined sequence (Refer to Bike Sales notebook)

Integrate atoti with Kafka for real-time messaging

For real-time messaging, atoti is able to integrate with Kafka as shown below. We can use the default JSON_DESERIALIZER to consume incoming messages.

trade_attributes.load_kafka(
    bootstrap_server="localhost:9092",
    topic="trades",
    group_id="atoti-trades-consumer",
    deserializer=atoti_kafka.JSON_DESERIALIZER,  
)

Check out our Real-time Risk notebook if you’re interested to learn more. 

Improving syntax for better user experience

If you’re unsure of the syntax, use the “Tab” key to auto-suggest the list of available functions. Use “Shift+tab” to display the function description.

We are constantly improving our library to provide a better experience for our users. For that reason, we have prepared a wide variety of examples across different topics in our atoti notebook gallery for your reference.

Finally, we love to hear from you. Reach out to us on the atoti GitHub discussions forum.