Skip to main content

taipy-utils

Code Style: Black Python codecov Tests

Utility decorators for cleaner Taipy GUI applications.

Installation

pip install taipy-utils
# or
uv add taipy-utils

The Initial Problem

Taipy callbacks often become messy when mixing framework code with business logic. The following code comes from a personal project that uses Taipy, before adding the decorator:

def make_qr_code(state):
    with state as s:
        message = s.qr_code_input
        if len(message) > 1500:
            notify(s, "e", "Text too long")  # Framework-specific error handling
            return
        # ... 20 more lines of business logic mixed with state management

Issues:

  • Long, hard-to-read functions
  • Business logic tightly coupled to Taipy
  • Can't reuse logic outside Taipy
  • Difficult to test

The Solution

Separate concerns with decorators:

from taipy_utils import taipy_callback

def generate_qr_code(message: str, add_logo: bool, ...) -> str:
    if len(message) > 1500:
        raise ValueError("Text too long")  # Standard Python error handling
    # ... Rest of code
    return file_path

@taipy_callback
def make_qr_code(state):
    state.image_path = generate_qr_code(
        message=state.qr_code_input,
        add_logo=state.add_logo,
        ...
    )

Benefits:

  • Separation of concerns: The UI stuff in one side, the business logic in another.
  • Pythonic error handling (standard exceptions using ValueError)
  • Reusable logic across frameworks
  • Easy to test
  • Automatic user notifications if a function raises an exception

Why This Package?

After creating @taipy_callback, I built @hold_control_during_execution for convenience. With several Taipy projects, making a package made sense:

  1. Version control separate from individual projects
  2. Share code across projects without copy-paste (DRY principle)
  3. Might help others in the Taipy community

Features

@taipy_callback

Automatically translates Python exceptions into Taipy notifications:

from taipy_utils import taipy_callback

@taipy_callback
def on_submit(state):
    if state.age < 18:
        raise ValueError("Must be 18 or older")  # Shows warning notification
    process_data(state.data)  # Any other exception shows error notification
  • ValueError → Warning notification (doesn't stop execution)
  • Other exceptions → Error notification (re-raised for debugging)

@hold_control_during_execution

This decorator triggers the hold_control() function before a callback execution, and the resume_control() at the end.

from taipy_utils import hold_control_during_execution

@hold_control_during_execution("Loading data...")
def on_load_data(state):
    # calls hold_control()
    data = fetch_from_api()
    state.data = data
    # calls resume_control()

Combine Decorators

You can combine decorators if you wish:

@taipy_callback
@hold_control_during_execution("Processing...")
def on_process(state):
    if not state.file:
        raise ValueError("Please select a file")
    result = process_file(state.file)
    state.result = result

License

MIT.

Contributing

Issues welcome at github.com/enarroied/taipy_utils.

Metadata

Release files for taipy-utils 0.1.1

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

Source distribution (sdist)

Source distribution for taipy-utils 0.1.1
File Size Uploaded Provenance Actions
taipy_utils-0.1.1.tar.gz 129.3 kB Without provenance Details for taipy_utils-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for taipy-utils 0.1.1
File Interpreter ABI Platform Actions
taipy_utils-0.1.1-py3-none-any.whl Python 3 none any Details for taipy_utils-0.1.1-py3-none-any.whl

Total release size: 134.5 kB

Release files / taipy_utils-0.1.1.tar.gz

Download URL taipy_utils-0.1.1.tar.gz
Size 129.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ae61d9156eb2458faacc5c2584710c4403398bf1c77254673941743d41783a31
BLAKE2b-256 checksum
How to use checksums
cc56980001316c21d256628394b3a24789f8cf0a156a61a7de31c9d36babe716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.13

Release files / taipy_utils-0.1.1-py3-none-any.whl

Download URL taipy_utils-0.1.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cedeec9e13d0be9d5b29b0083b4c937649c21d19a2cd98a2468a60c1ff2ac648
BLAKE2b-256 checksum
How to use checksums
cce668aa6ee38101c10ddba00260bff7f4f4da45291f54e9e8f3259a05ffc53b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.13

Security for taipy-utils 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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