A secure Python execution environment for the Business Central Code Interpreter extension. This function enables data analysis on your Business Central data without exposing sensitive information outside your Azure subscription.
-
Deploy with Visual Studio Code
- Install VS Code and the Azure Functions extension
- Clone this repository and open in VS Code
- Use Azure Functions extension to deploy directly to Azure:
- Click the Azure icon in the sidebar
- Select "Deploy to Function App..."
- Choose "Create new Function App in Azure..."
- Select Python runtime (3.10+)
- Set HTTP trigger with "Function" authentication level
- Choose a name, region, and plan (Consumption or Premium)
-
Business Central API Access
- Skip this step if you already have BC API access configured
- Register app in Azure AD
- Add Business Central API permissions (API.ReadWrite.All)
- Create a client secret
-
Configure Environment Variables
- In the Azure Portal, navigate to your Function App
- Go to "Settings" > "Configuration"
- Add the following Application settings:
BC_TENANT_ID: Your Azure AD tenant IDBC_CLIENT_ID: Client ID of the app registrationBC_CLIENT_SECRET: Secret of the app registration
- Click "Save" when finished
Endpoint: POST /api/execute
Request:
{
"code": "# Your Python code here"
}Response Format:
{
"data": "Your data as text",
"chart_images": ["base64encoded_image1", "base64encoded_image2"]
}# Get data from Business Central
data = get_bc_data("v2.0/companies(123456)/salesInvoices", "sandbox")
# Create the output structure
output = {
"data": {
"total_invoices": len(data["value"]),
"total_amount": sum(item["totalAmountIncludingTax"] for item in data["value"])
},
"chart_images": []
}- Business Central Access:
get_bc_data(relative_url, environment) - Data Analysis: pandas, numpy, matplotlib, scikit-learn, statsmodels
- Visualization: Generate charts with matplotlib and return as base64-encoded images
- Sandboxed execution environment
- Restricted access to system resources
- Dangerous Python modules and functions are blocked
- All data processing happens within your Azure subscription
- Check Application Insights logs for detailed error messages
- Verify environment variables are correctly set
- For complex data, convert to simple types or strings before returning
For support, please contact dmitry@katson.com.
Part of the Code Interpreter extension for Microsoft Dynamics 365 Business Central