Skip to main content

Troy Playground

A Python debugging tool that executes functions and extracts their local variables for inspection. Originally designed for analyzing test functions, it allows you to turn any function into a playground where you can access and examine internal variables after execution.

Installation

pip install troy-playground

Usage

Basic Example

from troy_playground import extract_locals, run_function_playground

# Example with a test function
from tests.test_module import TestClass

test_obj = TestClass()
vars_dict = extract_locals(
    test_obj.test_method,
    ['result', 'data', 'processed'],  # variables to extract
    test_obj  # instance for bound methods
)

# Access the extracted variables
print(vars_dict['result'])
print(vars_dict['data'])

Using with Module Path

# Extract variables from a test method
vars_dict = run_function_playground(
    'tests.test_module',
    'TestClass',
    'test_method', 
    ['result', 'response', 'mock_data']
)

# Also works with regular functions
vars_dict = run_function_playground(
    'my_module',
    None,  # No class for module-level functions
    'process_data',
    ['output', 'transformed']
)

Passing Arguments

# You can pass arguments to the function
vars_dict = extract_locals(
    obj.method_with_params,
    ['result'],
    obj,  # instance
    'arg1', 'arg2',  # positional args
    param1='value1',  # keyword args
    param2='value2'
)

API Reference

extract_locals(func, var_names, instance=None, *args, **kwargs)

Execute a function and extract specified local variables.

  • func: The function to execute
  • var_names: List of variable names to extract
  • instance: Optional instance for bound methods
  • *args, **kwargs: Arguments to pass to the function

Returns a dictionary with extracted variables. If an error occurs, the dict will contain an __error__ key.

run_function_playground(module_path, class_name, func_name, var_names, *args, **kwargs)

Import and run a function by module path.

  • module_path: Import path to module
  • class_name: Class name (None for module-level functions)
  • func_name: Function/method name
  • var_names: List of variable names to extract
  • *args, **kwargs: Arguments to pass to the function

Use Cases

  • Test Debugging: Extract intermediate values from test functions to understand failures
  • Function Analysis: Inspect internal state without modifying source code
  • Interactive Development: Turn any function into a REPL-like playground

License

MIT

Metadata

Release files for troy-playground 0.1.0

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

Source distribution (sdist)

Source distribution for troy-playground 0.1.0
File Size Uploaded Provenance Actions
troy_playground-0.1.0.tar.gz 4.5 kB Without provenance Details for troy_playground-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for troy-playground 0.1.0
File Interpreter ABI Platform Actions
troy_playground-0.1.0-py3-none-any.whl Python 3 none any Details for troy_playground-0.1.0-py3-none-any.whl

Total release size: 9.7 kB

Release files / troy_playground-0.1.0.tar.gz

Download URL troy_playground-0.1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1af9885753e85525fbb705b7215db6fe9232dee6e3e8c2829c98aff945894567
BLAKE2b-256 checksum
How to use checksums
9465ee848c7245f351842feedc38f542448c41b079c7df1c26251c6830c8948d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / troy_playground-0.1.0-py3-none-any.whl

Download URL troy_playground-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a6a3a71d460817c46f178751c66b8ad70bbf531e531730a8dbde16822cd0669
BLAKE2b-256 checksum
How to use checksums
2667e69ad2b0a1056f766cfc1c79c95135f2c04885740c5af394870e20e83353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Security for troy-playground 0.1.0

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.0 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