What are Liquibase Python modules?

Last updated: July 14, 2025

Liquibase provides an API you can call on in your Python Liquibase Pro Custom Policy Checks. The Liquibase Checks extension comes with several modules you can import in your scripts to access this API:

- liquibase_changesets - liquibase_constants - liquibase_database - liquibase_json - liquibase_utilities

This documentation page lists the callable methods and functions contained in these Python modules. You can use these to access necessary information about your changelog and database to run your Custom Policy Checks.

The Liquibase Python modules are a layer on top of the Liquibase API, which is written in Java (Javadocs). They contain functions that wrap many of the native Java methods Liquibase uses. This allows you to access Liquibase functions in a more Pythonic way to improve ease of use and interoperability. However, it is still possible to call directly on Java methods in your Python code.

For real-world Python scripts that access these modules, see Sample Custom Policy Check Scripts.

Python modules

The Python Standard Library is included when you download Python. Liquibase also natively supports the following Python modules:

These modules can provide additional functionality in your Custom Policy Checks, such as parsing complex SQL queries.

The built-in Liquibase virtual environment cannot support additional modules. If you want to use more, you must create your own virtual environment and configure Liquibase to run scripts using your custom executable instead.

In your custom virtual environment, you can install the Liquibase Python modules and natively supported Python modules in a package called liquibase-checks-python. For more information, see Create a Python Virtual Environment.

Import syntax

By default, you can import Liquibase modules using the following syntax:

import <module name>

If you use a custom virtual environment instead of the built-in virtual environment Liquibase provides, you must use the following syntax instead:

from liquibase-checks-python import <module name>

liquibase_changesets

These functions are available to you after importing liquibase_changesets.

Functions to pull information from the given changeset path. The changeset is always the input parameter for these attributes.

Property

Value

get_author(changeset)

Returns the changeset author

get_contexts(changeset)

Returns the changeset contexts

get_file_path(changeset)

Returns the changeset file path

get_id(changeset)

Returns the changeset ID

get_labels(changeset)

Returns the changeset labels

is_always_run(changeset)

Returns the value of runAlways for this changeset

is_run_on_change(changeset)

Returns the value of runOnChange for this changeset

liquibase_database

These functions are available to you after importing liquibase_database.

Methods to access, or return, database attributes. The database is always the input parameter for these attributes.

Function

Return

get_database_product_name(database)

Returns the database product name

get_database_product_version(database)

Returns the database product version

get_default_schema_name(database)

Returns the default schema for this database

get_short_name(database)

Returns the database short name

liquibase_json

These functions are available to you after importing liquibase_json.

Functions to access, or return, JSON attributes. These are functions to parse a JSON snapshot of your database and access, or return, dictionary objects.

Function

Input Parameter

Return

get_column

snapshot: the snapshot to parsetable_name: the name of the table to search forcolumn_name: the name of the column to search for

Returns the specified Column Dict object for a table

get_column_size

column: the Column Dict object

Returns the specified Column's size

get_column_type_name

column: the Column Dict object

Returns the specified Column's type name

get_columns

snapshot: the snapshot to parsetable_name: the name of the table to search for

Returns a list of Column Dict objects for a table such as a JSON serialized representation of the Liquibase internal DatabaseObject class.Example output:{'column': {'name': 'name', 'nullable': True, 'order': '1!{java.lang.Integer}', 'relation': 'liquibase.structure.core.Table#0eab104', 'snapshotId': '0eab105', 'type': {'characterOctetLength': '20!{java.lang.Integer}', 'columnSize': '20!{java.lang.Integer}', 'columnSizeUnit': 'BYTE!{liquibase.structure.core.DataType$ColumnSizeUnit}', 'dataTypeId': '1!{java.lang.Integer}', 'radix': '10!{java.lang.Integer}', 'typeName': 'bpchar'}}}

get_indexes

snapshot: the snapshot to parsetable_name: the name of the table to search for

Returns a List of Index Dict objects for a table

get_primary_key

snapshot: the snapshot to parsetable_name: the name of the table to search for

Returns a Primary Key Dict object for a table

get_table

snapshot: the snapshot to parsetable_name: the name of the table to search for

Returns the requested table object

get_tables

snapshot: the snapshot to parse

Returns a list of Table Dict objects

liquibase_utilities

These functions are available to you after importing liquibase_utilities.

Utilities are general script helpers that retrieve content frequently searched for.

Function

Input Parameter(s)

Return

generate_sql

change: the change to generate SQL from

Returns the SQL associated with this change that Liquibase would deploy to your database. The function returns any inline SQL (formatted SQL or sql Change Type) or SQL within referenced files (sqlFile) it finds. Otherwise, it generates SQL from any modeled Change Types (like createTable) it finds, similar to running the update-sql command. Does not include Liquibase-specific SQL, like updates to the DATABASECHANGELOG table.Example:changes = liquibase_utilities.get_changes()sql = liquibase_utilities.generate_sql(change[0])if "something bad" in sql:status.fired = Truesys.exit(1) # exit from the check

get_arg

name: the argument to find

Return the value of the script argument you specified while creating or customizing your check in the CLI. For example, if you specify MAX_SIZE=10 in the CLI, you can retrieve it in your code with a variable: max_size = int(liquibase_utilities.get_arg("MAX_SIZE")).

get_binding

key: the binding to access

Returns the binding object at the given key

get_cache

key: the look up keydefault_value: the value to put for the key if no value present

Returns the stored key/value pairs currently held by a dict object that are available between script executions. For example, you can count the number of times a check triggers by adding a counter that updates for each feature. If there is no current value, returns the default value.

get_changes

Returns the set of Liquibase change objects that the check is actively examining. Custom policy checks run against a single changeset at a time, so this refers to a list of Change Types within a single changeset.

get_changeset

Returns the changeset object Liquibase is actively examining

get_column_type

database_object: the database object to check

Returns the data type of the column of a database object. Examples include: varchar, integer, etc. If the database object is not a column, returns None.

get_database

Returns the Liquibase database object

get_database_object

Return the DatabaseObject that is being referenced in a database-scoped check

get_database_snapshot

Return the DatabaseSnapshot object as a string

get_dbutil

Return the db_util object used to check for object existence or to snapshot the DatabaseObject and return it

get_logger

Return the Liquibase logger

get_object_type_name

database_object: the database_object to return the type for

Return the object type of a given database object as a string

get_script_message

Return the message for the script. This is the message you specify in the CLI when you create a custom policy check.

get_script_path

Return the path of the script. This is the path you specify in the CLI when you create a custom policy check.

get_snapshot

Return the snapshot as a JSON object. If no snapshot is available, return None.

get_status

Return the Status object, which is used to set the check fired status and return a message. Required to tell Liquibase whether a check has triggered.

has

object_type: the object typeschema_name: the schema nameobject_name: the object name

Returns true if there is an object of this type and name in the schema, false otherwise

has_relation

object_type: the object typeobject_name: the object namerelation_type: the type of relation (Table or View)relation_schema_name: the schema of the relation objectrelation_name: the name of the relation

Returns true if there is an object of this type that has a relation object that matches the relation type, schema, and name. Returns false if no items match the provided criteria.

is_catalog

database_object: the database object to check

Returns true if the database object is a catalog, false otherwise

is_check_constraint

database_object: the database object to check

Return true if the database object is a check constraint, false otherwise

is_column

database_object: the database object to check

Return true if the database object is a column, false otherwise

is_database_package

database_object: the database object to check

Return true if the database object is a database package, false otherwise

is_database_package_body

database_object: the database object to check

Return true if the database object is a database package body, false otherwise

is_foreign_key

database_object: the database object to check

Return true if the database object is a foreign key, false otherwise

is_function

database_object: the database object to check

Return true if the database object is a function, false otherwise

is_index

database_object: the database object to check

Return true if the database object is an index, false otherwise

is_primary_key

database_object: the database object to check

Return true if the database object is a primary key, false otherwise

is_schema

database_object: the database object to check

Return true if the database object is a schema, false otherwise

is_sequence

database_object: the database object to check

Return true if the database object is a sequence, false otherwise

is_stored_database_logic

database_object: the database object to check

Return true if the database object is stored database logic, false otherwise

is_stored_procedure

database_object: the database object to check

Return true if the database object is a stored procedure, false otherwise

is_synonym

database_object: the database object to check

Return true if the database object is a synonym, false otherwise

is_table

database_object: the database object to check

Return true if the database object is a table, false otherwise

is_trigger

database_object: the database object to check

Return true if the database object is a trigger, false otherwise

is_unique_constraint

database_object: the database object to check

Return true if the database object is a unique constraint, false otherwise

is_view

database_object: the database object to check

Return true if the database object is a view, false otherwise

put_cache

key: the key to usevalue: the value to put in the cache

Places the stored key/value pairs held by a dict object that are available between script executions.

query_for_list

sql: the SQL to executesql_file: the SQL file to executeend_delimiter: the end delimiter to use

Executes a SQL statement or script. Returns the result of the SQL as a list

snapshot_object

object_type: the type of the object, like Tableobject_name: the objects namerelation_type: a type of relation that we need to snapshot to access the objectschema_name: the schema for the relationrelation_name: the name of the relation

Returns a Liquibase model object that represents the database object specified

split_sql

sql_string: the SQL to processstrip_comments_flag: set to true to strip out commentsend_delimiter: the end delimiter to use while processing the SQLchangeset: the change set associated with the SQL

Returns an array of SQL lines

split_statements

sql_string: the SQL string to split

Splits a string of SQL into individual statements. Returns the list of SQL strings

strip_comments

sql_string: the SQL to strip

Strips comments from a SQL string. Returns the SQL string with comments removed

tokenize

statement: the statement to tokenize

Tokenizes a statement which was created by the sqlparse Python module. Returns the tokenized statement as a list

liquibase_constants

These functions are available to you after importing liquibase_constants.

Constants are an unchangeable set of well-known constants that are used to access the script bindings. They are definitions of internal Python classes Liquibase uses to enable Custom Policy Checks via Python scripts.

Warning: You should be familiar with what a Python class is and how classes can have variables which are the equivalent of a constant. Most users will not need to use these unless you are debugging a complex custom policy check you have created.

Constant methods

  • __init__(self)

  • __setattr__(self, name, value)

Constant data descriptors

  • __dict__

  • __weakref__

ScriptConstant data descriptors

  • __dict__

  • __weakref__

ScriptConstant data and other attribute definitions

  • ARGS_SUFFIX = '_arg_binding'

  • CACHE_BINDING = 'cache_binding'

  • CHANGESET_BINDING = 'changeSet_binding'

  • CHANGES_BINDING = 'changes_binding'

  • DATABASE_BINDING = 'database_binding'

  • DATABASE_OBJECT_BINDING = 'databaseObject_binding'

  • DATABASE_SNAPSHOT_BINDING = 'databaseSnapshot_binding'

  • DBUTIL_BINDING = 'dbutil_binding'

  • LOGGER_BINDING = 'logger_binding'

  • SCRIPT_MESSAGE_BINDING = 'scriptMessage_binding'

  • SCRIPT_PATH_BINDING = 'script_path_binding'

  • STATUS_BINDING = 'status_binding'

What are Liquibase Python modules? - Liquibase