Skip to main content

CxBlueprint

Programmatic Amazon Connect contact flow generation using Python. Allows for Ai models to generate contact flows based on human languages way easier than writing JSON as majority of the time it will fail to generate a valid contact flow from scratch.

Simple Example

from cxblueprint import Flow

flow = Flow.build("Burger Order")

welcome = flow.play_prompt("Welcome to Burger Palace!")
menu = flow.get_input("Press 1 for Classic Burger or 2 for Veggie Burger", timeout=10)
welcome.then(menu)

classic = flow.play_prompt("You selected Classic Burger. Your order is confirmed!")
veggie = flow.play_prompt("You selected Veggie Burger. Your order is confirmed!")
error_msg = flow.play_prompt("Invalid selection. Goodbye.")

disconnect = flow.disconnect()

# Chain menu options with error handling
menu.when("1", classic) \
    .when("2", veggie) \
    .otherwise(error_msg) \
    .on_error("InputTimeLimitExceeded", error_msg) \
    .on_error("NoMatchingCondition", error_msg) \
    .on_error("NoMatchingError", error_msg)

# Or without chaining:
# menu.when("1", classic)
# menu.when("2", veggie)
# menu.otherwise(error_msg)
# menu.on_error("InputTimeLimitExceeded", error_msg)
# menu.on_error("NoMatchingCondition", error_msg)
# menu.on_error("NoMatchingError", error_msg)

classic.then(disconnect)
veggie.then(disconnect)
error_msg.then(disconnect)

flow.compile_to_file("burger_order.json")

Terraform Template Example

Use placeholders for dynamic resource ARNs:

from cxblueprint import Flow

flow = Flow.build("Counter Flow")

welcome = flow.play_prompt("Thank you for calling!")
invoke_counter = flow.invoke_lambda(
    function_arn="${COUNTER_LAMBDA_ARN}",  # Resolved by Terraform
    timeout_seconds="8"
)
welcome.then(invoke_counter)

say_count = flow.play_prompt("You are caller number $.External.count")
invoke_counter.then(say_count)

disconnect = flow.disconnect()
say_count.then(disconnect)
invoke_counter.on_error("NoMatchingError", disconnect)

flow.compile_to_file("counter_flow.json")

Generated Flow Examples

Here's what the generated flows look like in the Amazon Connect console:

Example Generated Flow

Example Generated Flow 2

Features

  • Fluent Python API for building flows
  • Naive block positioning for AWS Connect visual canvas
  • Automatic UUID generation for blocks
  • Error/Conditional handling support
  • Integration with AWS Lambda and lexv2 bots
  • Template placeholder support for Terraform/IaC
  • Decompile existing flows to Python
  • Majority of Amazon Connect block types supported
  • Shell scripts to download, validate, and test flows against Connect

Possible Future Uses/Ideas:

  • Compliance Checking, check flow structures for best practices, encryption, etc.
  • Optimization Suggestions, analyze flows for efficiency improvements.
  • Output to diagram formats for other visualization tools.
  • Template library of common flow patterns.

Quick Start

# See Terraform example
cd terraform_example
python flow_generator.py

# Deploy with Terraform
cd terraform
terraform init
terraform apply

Project Structure

src/
  flow_builder.py       # Main builder API
  decompiler.py         # JSON to Python
  blocks/               # All Connect block types
    contact_actions/    # Actions like CreateTask
      readme.md         # Contains progress on supported blocks
     flow_control_actions/ # Flow control blocks
      readme.md         # Contains progress on supported blocks
     interactions/      # Interaction blocks
      readme.md         # Contains progress on supported blocks
     participant_actions/  # Participant blocks
      readme.md         # Contains progress on supported blocks
examples/               # Sample flows
terraform_example/      # Complete deployment example
docs/                   # API reference

Documentation

Requirements

  • Python 3.11+
  • AWS credentials (for deployment)
  • Terraform (optional, for infrastructure)

Release files for cxblueprint 0.0.post33

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cxblueprint 0.0.post33
File Size Uploaded
cxblueprint-0.0.post33.tar.gz 438.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cxblueprint 0.0.post33
File Interpreter ABI Platform
cxblueprint-0.0.post33-py3-none-any.whl Python 3 none any Details

Total release size: 502.8 kB

Release files / cxblueprint-0.0.post33.tar.gz

Download URL cxblueprint-0.0.post33.tar.gz
Size 438.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a4e6e530cdddc11dc68a61bef85a641041afafd0903e8347698ade62285851e9
BLAKE2b-256 checksum
How to use checksums
c4ea29efab39b7c8a0d144f491b82310d61bb86e4a78ba5cd595054480728785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / cxblueprint-0.0.post33-py3-none-any.whl

Download URL cxblueprint-0.0.post33-py3-none-any.whl
Size 64.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03e4d3c0bdc71dade068d72b89179802fbc971029277823794ef9e48738b459f
BLAKE2b-256 checksum
How to use checksums
c13220af2c1e4a89c7aa2e07cb2348b014c341d9a1040d5f43579c5887ed0799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page