Discover all of the brand-new features and improvements to existing capabilities in the Dataiku 11.3 updateLET'S GO

Identify API endpoint generation from within python function

Solved!
Helm
Level 1
Identify API endpoint generation from within python function

I have created and deployed end points in the API deployer which use custom python functions.

Within these functions I have built functionality which outputs various information to SQL server.

This all works fine but I would like to save the generation of the end point (e.g. v45) in my logging each time it is called - so my question is how do I find out the generation of the end point from within my code? Is there e.g. an environmental variable or something?

Really I need to create a clear audit trail of the version of the code used to generate a particular record and am using generation as a tag in git to achieve this linkage.

0 Kudos
1 Solution
ZachM
Dataiker

Hi @Helm,

You can get the current generation of an API service by checking the DKU_CURRENT_APISERVICE_GENERATION environment variable.

Here's an example Python endpoint that returns the current generation:

 

import os


def api_py_function():
    generation = os.environ["DKU_CURRENT_APISERVICE_GENERATION"]
    return generation

 

 

Thanks,

Zach

View solution in original post

0 Kudos
2 Replies
ZachM
Dataiker

Hi @Helm,

You can get the current generation of an API service by checking the DKU_CURRENT_APISERVICE_GENERATION environment variable.

Here's an example Python endpoint that returns the current generation:

 

import os


def api_py_function():
    generation = os.environ["DKU_CURRENT_APISERVICE_GENERATION"]
    return generation

 

 

Thanks,

Zach

0 Kudos
Helm
Level 1
Author

Works perfectly, many thanks

0 Kudos