Skip to main content

CLI to start a PyCharm debug session and then run a Python target in-process

Project description

charmd

A PyCharm debug session helper that starts a debug server and then runs your Python target in the same process.

Why charmd?

PyCharm's debugger is powerful, but debugging scripts with different arguments or configurations typically means editing Run Configurations through the IDE. This becomes cumbersome when:

  • You need to debug one-off commands with unique CLI arguments
  • You're testing different script variations or parameter combinations
  • You want the simplicity of command-line debugging (like pdb or debugpy) with PyCharm's full IDE debugging experience

charmd eliminates this friction by letting you debug any Python command directly from the terminal.


TOC


Requirements

Note: charmd does not automatically install pydevd-pycharm as a dependency. This is intentional, as PyCharm installations ship with their own preferred version of the library that should be used for debugging. See Locating or Installing pydevd-pycharm below.

Quick start

⚠️ Important: Before running any charmd command, ensure that:

  • PyCharm's Python Debug Server is running and listening on the configured host and port (default: localhost:5678)
  • You set breakpoints in your code where you want to pause execution

See PyCharm's Debug Documentation for more information.

usage

charmd [debug-options ...] [--] (-m module | -c command | pyfile) [args ...]

Note: charmd is good at distinguishing debug options from the target specification. In cases where they may be ambiguity, you can use -- to clearly specify the start of the target specification.

examples

charmd -m mypkg.mymod arg1
charmd -c "print('hello')"
charmd -- script.py arg1 arg2

debug options

  -h, --help             Show this help message and exit
  --version              Show program's version number and exit

  --host HOST            PyCharm debug server host (default: localhost)
  --port PORT            PyCharm debug server port (default: 5678)
  --suspend              Suspend on start (default: False)

  --stdout-to-server     Redirect stdout to debug server (default: True)
  --no-stdout-to-server  Do not redirect stdout to debug server

  --stderr-to-server     Redirect stderr to debug server (default: True)
  --no-stderr-to-server  Do not redirect stderr to debug server

  --pydevd-path PATH     Path to the pydevd-pycharm module directory.

  --conf-init            Create a charmd.conf file with current settings and exit.

Locating or Installing pydevd-pycharm

charmd requires the pydevd-pycharm library to communicate with PyCharm's debug server. You can either locate an existing installation (if PyCharm is installed) or install a compatible version via pip.

Option 1: Use the library from your PyCharm installation

If you have PyCharm installed, you can point charmd to the bundled pydevd-pycharm.egg file in your PyCharm installation directory:

Linux/Windows:

<PyCharm directory>/debug-egg/pydevd-pycharm.egg

MacOS:

<PyCharm directory>/Contents/debug-eggs/pydevd-pycharm.egg

For example, on MacOS:

/Applications/PyCharm.app/Contents/debug-eggs/pydevd-pycharm.egg

Configure charmd to use this path via the pydevd_path setting in your configuration file or the --pydevd-path command-line option.

Option 2: Install using pip

If PyCharm is not installed on your system, install the pydevd-pycharm package matching your PyCharm version:

pip install pydevd-pycharm~=<version of PyCharm on the local machine>

For example, if your PyCharm version is 242.20224.428:

pip install pydevd-pycharm~=242.20224.428

To find your PyCharm version, go to PyCharmAbout PyCharm (or HelpAbout on some platforms).

For more information, see the JetBrains Remote Debugging documentation.

Configuration File

charmd supports a configuration file for setting default debug options on a per-project basis. This eliminates the need to specify common options on the command line for every invocation.

File Location

The configuration file must be named charmd.conf and placed in the current working directory (the directory from which you run charmd).

Creating the Configuration File

Option 1: Automatic Generation

Use the --conf-init flag to generate a configuration file with your current settings:

charmd --host 192.168.1.100 --port 5679 --suspend --conf-init

This creates a charmd.conf file in the current directory with the specified settings.

Option 2: Manual Creation

Create a charmd.conf file manually with your preferred text editor:

# charmd configuration file
# Lines starting with '#' are comments.

host = localhost
port = 5678
suspend = false
stdout_to_server = true
stderr_to_server = true
#pydevd_path = /path/to/pydevd_pycharm

Configuration Options

All command-line debug options can be configured in the file:

Option Type Default Description
host string localhost PyCharm debug server host
port integer 5678 PyCharm debug server port
suspend boolean false Suspend execution on start
stdout_to_server boolean true Redirect stdout to debug server
stderr_to_server boolean true Redirect stderr to debug server
pydevd_path string (none) Path to pydevd-pycharm module directory

File Format

  • Key-value pairs: Use key = value syntax
  • Comments: Lines starting with # are ignored
  • Whitespace: Leading and trailing whitespace is trimmed
  • Quotes: Values can be quoted with single or double quotes to preserve internal whitespace
    host = "my host with spaces"
    pydevd_path = '/Applications/PyCharm.app/Contents/debug-eggs'
    
  • Boolean values: Accepted values are true, false, 1, 0, yes, no, y, n, on, off (case-insensitive)

Configuration Precedence

Settings are applied in the following order (later sources override earlier ones):

  1. Built-in defaults (e.g., host=localhost, port=5678)
  2. Configuration file (charmd.conf in current directory)
  3. Command-line arguments (highest priority)

This allows you to set project-wide defaults in charmd.conf and override them on a per-invocation basis when needed.

Example Workflow

# Set up project-specific debug configuration
cd /path/to/myproject
charmd --host 192.168.1.100 --port 5679 --conf-init

# Now run with config file defaults
charmd -- myscript.py

# Override specific settings when needed
charmd --suspend -- myscript.py

Installation

From PyPI (Recommended)

Install the latest stable version from PyPI using pip:

pip install charmd

To install for the current user only:

pip install --user charmd

To upgrade an existing installation:

pip install --upgrade charmd

From Wheel File

Wheel (.whl) files are available as release assets on the GitHub releases page. Download the desired version and install it directly:

pip install charmd-*.whl

Replace * with the specific version number, or use the exact filename.

From Source (Clone Repository)

Standard Installation

Clone the repository and install using pip:

git clone https://github.com/tekwizely/python-charmd.git
cd python-charmd
pip install .

Editable/Development Installation

For development work, install in editable mode so changes take effect immediately:

git clone https://github.com/tekwizely/python-charmd.git
cd python-charmd
pip install -e .

This allows you to modify the source code and test changes without reinstalling.

Running Without Installation

You can also run charmd directly from the cloned repository without installing:

git clone https://github.com/tekwizely/python-charmd.git
cd python-charmd
python charmd.py [options]
# or
python -m charmd [options]

Verifying Installation

After installation, verify that charmd is properly installed:

charmd --version

Or:

python -m charmd --version

Uninstalling

To remove charmd:

pip uninstall charmd

License

The tekwizely/python-charmd project is released under the MIT License. See LICENSE file.

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

charmd-0.2.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

charmd-0.2.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file charmd-0.2.3.tar.gz.

File metadata

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

File hashes

Hashes for charmd-0.2.3.tar.gz
Algorithm Hash digest
SHA256 67c6d2def5e5f08a12fafa5243dd56573da736d1ab8317f1cc3dc25bb186d388
MD5 d83b5b078e024c079abd7c5e334b2572
BLAKE2b-256 1c66ee2555948c22381b87f0c43f2cd849ddcfd4fb8edee01a40ab55bbd38056

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmd-0.2.3.tar.gz:

Publisher: publish.yml on TekWizely/python-charmd

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

File details

Details for the file charmd-0.2.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for charmd-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 113bcebe459d79bfaf9c69576fc0dda1329830362c8597a0ea7e24d058aadc46
MD5 1d1d9a847b7178b655bcc888c779811d
BLAKE2b-256 6a3ae8834e6af35bfa79566d60441a7de3d5cb0308a3879ae468292870548506

See more details on using hashes here.

Provenance

The following attestation bundles were made for charmd-0.2.3-py3-none-any.whl:

Publisher: publish.yml on TekWizely/python-charmd

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