> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.fynapse.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.fynapse.app/_mcp/server.

# Built-In Python Functions and Types

> Overview of built-in Python functions and types available in Fynapse

## Overview

Below is a list of pre-defined functions that are available in the Python Script step. They allow you to access Reference Data, as well as Business and Fiscal Calendars.

## Function: `get_fiscal_periods_between_dates`

Returns all periods of a Fiscal Calendar between dates.

**Arguments**

| **Name**        | **Type**                    | **Description**                                                                                                                          |
| --------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `calendar_name` | `String`                    | Name of the Fiscal Calendar to get the Fiscal Periods from                                                                               |
| `start_date`    | `datetime.date` or `String` | The start date (inclusive) for which to get the Fiscal Period for If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |
| `end_date`      | `datetime.date` or `String` | The end date (inclusive) for which to get the Fiscal period for If `String` is provided then it needs to be in ISO format (yyyy-MM-dd)   |

**Returns**

A `list` of Fiscal `Period`s

## Function: `get_next_fiscal_period_after_date`

Gets the next Fiscal period for a given Fiscal Calendar after a given date.

| **Name**        | **Type**                    | **Description**                                                                                                   |
| --------------- | --------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `calendar_name` | `String`                    | Name of the Fiscal Calendar to get the next Fiscal period from                                                    |
| `date`          | `datetime.date` or `String` | The date to compute the next Fiscal period If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

Fiscal `Period`

## Function: `get_fiscal_period_by_date`

Gets the Fiscal period for a given Fiscal Calendar after a given date.

| **Name**        | **Type**                    | **Description**                                                                                              |
| --------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `calendar_name` | `String`                    | Name of the Fiscal Calendar to get the Fiscal period from                                                    |
| `date`          | `datetime.date` or `String` | The date to compute the fiscal period If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

Fiscal `Period`

## Function: `get_fiscal_period_by_fiscal_year_and_period_number`

Gets the Fiscal period from given Fiscal Calendar, year and period.

| **Name**        | **Type**        | **Description**                                           |
| --------------- | --------------- | --------------------------------------------------------- |
| `calendar_name` | `String`        | Name of the Fiscal Calendar to get the Fiscal period from |
| `fiscal_year`   | `int`or `long`  | Fiscal year                                               |
| `fiscal_period` | `int` or `long` | Fiscal period \[1-12]                                     |

**Returns**

Fiscal `Period`

## Function: `get_business_days_between_dates`

Gets the list of all business days between given dates.

| **Name**        | **Type**                  | **Description**               |
| --------------- | ------------------------- | ----------------------------- |
| `calendar_name` | `String`                  | Name of the Business Calendar |
| `start_date`    | `datetime.date or String` | Start date (inclusive)        |
| `end_date`      | `datetime.date or String` | End date (inclusive)          |

**Returns**

A `list` of `BusinesDay`s

## Function: `get_business_days_from_year`

Gets the list of all business days for a given year.

| **Name**        | **Type**        | **Description**                       |
| --------------- | --------------- | ------------------------------------- |
| `calendar_name` | `String`        | Name of the Business Calendar         |
| `year`          | `int` or `long` | Year to get the list of business days |

**Returns**

A `list` of `BusinesDay`s

## Function: `get_business_days_from_year_and_month`

Gets the list of all business days for a given year.

| **Name**        | **Type**        | **Description**                       |
| --------------- | --------------- | ------------------------------------- |
| `calendar_name` | `String`        | Name of the Business Calendar         |
| `year`          | `int` or `long` | Year to get the list of business days |
| `month`         | `int` or `long` | Month number \[1-12]                  |

**Returns**

A `list` of `BusinesDay`s

## Function: `get_business_day_from_year_and_month_and_day`

Gets information about business day of a given day.

| **Name**        | **Type**        | **Description**                       |
| --------------- | --------------- | ------------------------------------- |
| `calendar_name` | `String`        | Name of the Business Calendar         |
| `year`          | `int` or `long` | Year to get the list of business days |
| `month`         | `int` or `long` | Month number \[1-12]                  |
| `day`           | `int` or `long` | Day number \[1-31]                    |

**Returns**

A `BusinesDay`s

## Function: `get_next_working_business_day_from_date`

Gets the next working day after a given date.

| **Name**        | **Type**                    | **Description**                                                                                                           |
| --------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `calendar_name` | `String`                    | Name of the Business Calendar                                                                                             |
| `date`          | `datetime.date` or `String` | The date after which to get the next Business Date If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

A `BusinesDay`s

## Function: `get_nearest_working_business_day_from_date`

Gets the nearest working day for a supplied date. This can be the supplied date if it is a Business Date.

| **Name**        | **Type**                    | **Description**                                                               |
| --------------- | --------------------------- | ----------------------------------------------------------------------------- |
| `calendar_name` | `String`                    | Name of the Business Calendar                                                 |
| `date`          | `datetime.date` or `String` | A date If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

A `BusinesDay`s

## Function: `get_nth_business_day_before_reference_date`

Gets the nth working day after a given reference date.

| **Name**         | **Type**                    | **Description**                                                                         |
| ---------------- | --------------------------- | --------------------------------------------------------------------------------------- |
| `calendar_name`  | `String`                    | Name of the Business Calendar                                                           |
| `shift_days`     | `int` or `long`             | Numbers of days to shift the reference date                                             |
| `reference_date` | `datetime.date` or `String` | A reference date If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

A `BusinesDay`s

## Function: `lookup`

Performs the lookup a given Fynapse Reference Data Entity using the conditions provided.

> **Warning**
>
> There is a limit of 10k on the number of records that can be returned from a single lookup function call in Flow.

| **Name**              | **Type**                    | **Description**                                                                                                                                                                                                                 |
| --------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `namespace`           | `String`                    | Namespace of the entity to lookup. Most Reference Data Entities are defined in the `"fynapse"` namespace                                                                                                                        |
| `entity_name`         | `String`                    | Name of the Reference Data Entity to lookup. This name is provided in the **entities** section of the Configuration Data JSON file                                                                                              |
| `conditions`          | `condition[]`               | A list of conditions to perform the lookup. The conditions will be using a logical conjunction (AND) when there’s more than one provided. Possible conditions are: - `equal_condition`                                          |
| `single_match`        | `Boolean`                   | A boolean indicating if a first match is to be provided (`true`) or a list of all data matching the given condition (`false`). A reasonable default is to look for all matches (`false`)                                        |
| `effective_date_from` | `datetime.date` or `String` | (optional) The date for which the looked up reference data is effective. If not provided then the Effective Date will be assumed as Fynapse System Date. If `String` is provided then it needs to be in ISO format (yyyy-MM-dd) |

**Returns**

A list of Reference Data Entities that are matching the supplied conditions. The Reference Data Entities will have the properties as defined in the Configuration Data JSON file.

## Function: `equal_condition`

A condition that defines an EQ (=) condition between the properties of a Data Entity and the value provided.

| **Name** | **Type**   | **Description**                                                                                                                                                                                                                                |
| -------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path`   | `String[]` | A path to an Data Entity property. If a root property is referenced, the the list should have only a single element. E.g. to reference a **type** attribute in the Reference Data Entity, then the value of the argument should be: `["type"]` |
| `value`  | `Object`   | A value to be used to compare against the properties of the queried Data Entity                                                                                                                                                                |

## Function: `publish`

Creates a Flow variable and makes it available to a subsequent Flow step.

| **Name** | **Type** | **Description**                                                                                                                                                                                                                                                                   |
| -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`   | `String` | Name of the variable to publish the value for. The name needs to be registered as a Script flow step output, otherwise an error is raised. If there are multiple invocations of this function with the same output name, then only the last value that was used will be published |
| `value`  | `Object` | Value to publish                                                                                                                                                                                                                                                                  |

### Type: `Period`

Type that represents a Fiscal period. Each Period type has the following properties:

| **Name**            | **Type**        | **Description**                    |
| ------------------- | --------------- | ---------------------------------- |
| `period_start_date` | `datetime.date` | A fiscal period start date         |
| `period_end_date`   | `datetime.date` | A fiscal period end date           |
| `period_no`         | `long`          | Fiscal period number               |
| `period_year`       | `long`          | Fiscal period year                 |
| `period_half_year`  | `long`          | Fiscal period half year (1, 2)     |
| `period_quarter`    | `long`          | Fiscal period quarter (1, 2, 3, 4) |

### Type: `BusinessDay`

Type that returns information a given day returned from a Business Calendar.

| **Name**      | **Type**            | **Description**                           |
| ------------- | ------------------- | ----------------------------------------- |
| `date`        | `datetime.date`     | Day                                       |
| `working_day` | `Boolean`           | Is a given day a working day              |
| `info`        | `BusinessDayInfo[]` | An optional information about a given day |

### Type: `BusinessDayInfo`

Type that represents information about a Business Day.

| **Name**   | **Type** | **Description**                                                                        |
| ---------- | -------- | -------------------------------------------------------------------------------------- |
| `name`     | `String` | A name (if any) of a Business Day                                                      |
| `nwd_type` | `String` | Non Working Day Type (if any), can be: - `"CUSTOM"` - `"WEEKEND"` - `"PUBLIC_HOLIDAY"` |

## Function: `ingestion_id`

Returns the Ingestion ID of the input record that was the source of data used in the Flow.

## Function: `get_current_business_date`

Returns current Business Date, i.e. Fynapse system date adjusted for the specified Subledger Node Configurations timezone.

| **Name**      | **Type**     | **Description**                                                                                                                                                        |
| ------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `parameter 1` | `Dictionary` | Set of attributes of the Subledger Node we want to get the current Business date for, i.e. Subledger Node Field Name and value defined in the Journal Line Definition. |
| `parameter 2` | `String`     | The Accounting Base from the Subledger Node/Accounting Base combination we want to call.                                                                               |

## Function: `get_current_system_date`

Returns current System Date, i.e. the actual date and time of the machine you are using to work with Fynapse.

## Function: `logger`

Logs defined messages to the Error Management.

> **Info**
>
> We recommend you carefully plan what messages you want to implement, as having too many messages may cause an information overload that will not be easy to analyze.

> **Note**
>
> All three types of messages have a 4,000 character limit.

| **Name**         | **Type** | **Description**                                                                      |
| ---------------- | -------- | ------------------------------------------------------------------------------------ |
| `logger.info`    | `String` | Allows to define an information type message. E.g. “Lookup utilized successfully”    |
| `logger.warning` | `String` | Allows to define a warning type message. E.g. “The John Doe username is not unique.“ |
| `logger.error`   | `String` | Allows to define an error type message. E.g. “Cannot process data.“                  |

> **Tip**
>
> The configured messages will be logged in the Errors with:\
> Category: Flow\
> Subcategory: Log\
> Severity: Information/Warning/Error based on the type of the configured message.