Skip to main content

Self-sufficient debugging REPL for running Python programs

Project description

devliverepl

Self-sufficient debugging REPL for running Python programs

PyPI Python License

devliverepl provides an always-on ptpython REPL server accessible via telnet, enabling live inspection and debugging of running Python applications without interrupting execution.

Features

  • ๐Ÿ”„ Live inspection โ€” Connect to running programs and inspect state
  • ๐Ÿ“ฆ Context capture โ€” Automatic capture of locals/globals from call site
  • ๐ŸŽฏ Explicit exposure โ€” @expose decorator to mark important objects
  • ๐Ÿ” Debugger integration โ€” Built-in support for pdb, pudb, ipdb, pdbpp, patdb, webpdb
  • ๐ŸŽจ Rich terminal โ€” ptpython with syntax highlighting and auto-completion
  • ๐Ÿ›ก๏ธ Thread-safe โ€” Daemon thread doesn't block your application
  • ๐Ÿšฆ Graceful shutdown โ€” Clean connection handling with atexit support

Installation

# Basic installation
pip install devliverepl

# With uv
uv add devliverepl

# With optional debugger integrations
pip install devliverepl[debuggers]
uv add devliverepl --extra debuggers

Quick Start

import devliverepl

app_state = {"users": [], "status": "running"}

# Start the REPL - captures app_state
devliverepl.detach()

# Connect from another terminal:
# $ telnet localhost 8022
#
# In the REPL, you can access:
# >>> app_state
# {'users': [], 'status': 'running'}
# >>> app_state['users'].append('test')

Usage

Basic Usage

import devliverepl

# Your application state
config = {"debug": True}
database = Database()

# Start REPL (captures locals)
devliverepl.detach(port=8022)

# ... application runs ...

Exposing Objects

Use the @expose decorator to make objects available across all connections:

import devliverepl

@devliverepl.expose
class Database:
    """Database connection pool."""

    def query(self, sql):
        return self._execute(sql)

@devliverepl.expose
def get_stats():
    """Get application statistics."""
    return stats

devliverepl.detach()

Configuration

import devliverepl

devliverepl.configure(
    port=8022,
    host="127.0.0.1",
    banner="rich",  # or "minimal" or "custom"
    log_connections=True,
)

devliverepl.detach()

Custom Banner

import devliverepl
import os

devliverepl.set_banner(lambda: f"""
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  MyApp Debugger โ€” PID {os.getpid()}   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
""")

devliverepl.detach()

REPL Commands

When connected, use % commands:

%ls          # List exposed objects and captured variables
%import os   # Import a module
%where db    # Show where an object was defined
%env         # Show captured environment summary
%help        # Show all commands

Debugger Integration

# In the REPL, use the debug helper:
debug.attach()      # Auto-detect best debugger
debug.pudb()        # Use PuDB
debug.ipdb()        # Use IPython debugger
debug.pdbpp()       # Use pdb++
debug.patdb()       # Use PatDB (pattern debugger)
debug.web()         # Use Web-PDB (browser UI)

debug.list_available()  # Show installed debuggers

Shutdown

import devliverepl

# Graceful shutdown (waits for connections to close)
devliverepl.shutdown()

# Immediate shutdown
devliverepl.shutdown(force=True)

Examples

See the examples/ directory for more:

How It Works

  1. Call devliverepl.detach() in your code
  2. The function captures the calling frame's locals() and globals()
  3. A ptpython REPL server starts in a daemon thread
  4. Connect via telnet to inspect the captured state
  5. Disconnect anytime without stopping your application

Architecture

devliverepl/
โ”œโ”€โ”€ __init__.py         # Public API: detach(), shutdown(), @expose
โ”œโ”€โ”€ core.py             # REPLServer, event loop management
โ”œโ”€โ”€ capture.py          # Frame capture, context extraction
โ”œโ”€โ”€ registry.py         # Exposed object registry
โ”œโ”€โ”€ banner.py           # Banner generation
โ”œโ”€โ”€ commands.py         # % commands implementation
โ”œโ”€โ”€ shutdown.py         # Graceful shutdown handling
โ””โ”€โ”€ integrations/       # Debugger integrations
    โ”œโ”€โ”€ pdb.py
    โ”œโ”€โ”€ pudb.py
    โ”œโ”€โ”€ ipdb.py
    โ””โ”€โ”€ ...

Requirements

  • Python 3.10+
  • ptpython >= 3.0.0
  • prompt-toolkit >= 3.0.0

Optional (for debugger integrations):

  • pudb >= 2022.1
  • ipdb >= 0.13.0
  • pdbpp >= 0.10.0
  • web-pdb >= 0.5.0

Roadmap

v0.2.0 (Current)

  • โœ… Multiple named REPLs (foundational support)
  • โœ… Enhanced configuration system
  • โœ… Full debugger integration suite

v0.3.0 (Planned)

  • โณ Thread-aware stack inspection
  • โณ Context manager pattern
  • โณ SSH support
  • โณ Authentication
  • โณ TLS/SSL
  • โณ Multi-client collaboration

Contributing

Contributions welcome! Please read our contributing guidelines.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development

# Clone the repository
git clone https://github.com/devliverepl/devliverepl.git
cd devliverepl

# Install in development mode
uv sync --extra dev

# Run tests
pytest

# Run type checking
mypy devliverepl/

# Run linting
ruff check devliverepl/

License

MIT License โ€” see LICENSE for details.

Acknowledgments

Built with:


Happy debugging! ๐Ÿ›

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

devliverepl-0.2.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

devliverepl-0.2.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file devliverepl-0.2.0.tar.gz.

File metadata

  • Download URL: devliverepl-0.2.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for devliverepl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3dd00de98d95d3e04bb4b5f1cc045239ec985cd5536c896b7d2163dc95a435aa
MD5 28520aa14004625d9f3b1989249a358a
BLAKE2b-256 0ed28c77a543c06b7ef398e527646234fa2314c8c21d8c7f88d319f4bd0e8a7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for devliverepl-0.2.0.tar.gz:

Publisher: release.yml on fkr-0/devliverepl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file devliverepl-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: devliverepl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for devliverepl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc10808006b67ec278157b673f3c8ac50ef28e6023f75a1615ecc8e752d0b3a3
MD5 2ea2b613ffa738ce3a1703aa82c1dba2
BLAKE2b-256 c2e4be7bf476d4d243270330a4440aa36fff9794252d6164981c605d5050d8dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for devliverepl-0.2.0-py3-none-any.whl:

Publisher: release.yml on fkr-0/devliverepl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page