Skip to main content

Python wrapper for PM2

Project description

PM2 Python Library for Process Management

Introduction

This Python library provides a seamless integration with PM2, enabling users to automate the launching and management of processes using PM2 through Python. Designed to cater to developers and system administrators who require a programmable interface to control their processes with the power and flexibility of Python, this library simplifies interactions with PM2, making it more accessible and versatile.

Features

  • Easy Process Management: Start, stop, restart, and delete processes with simple Python functions.
  • Automatic Process Launch: Automatically launch multiple processes with predefined configurations.
  • Real-time Process Monitoring: Retrieve real-time information about process status, CPU, and memory usage.
  • Flexible Configuration: Configure processes programmatically, including environment variables, names, and log file locations.
  • Event Handling: Listen to and handle PM2 events directly within your Python scripts.

Installation

To install the PM2 Python Library, run the following command:

pip install pm2

Quick Start

To get started with the PM2 Python Library, here's a simple example that demonstrates how to start a process:

from pm2 import PM2, AioPM2
import asyncio

pm2 = PM2()
aiopm2 = AioPM2()


# Sync Methods
def pm2_manager():
    # List all processes
    processes = pm2.list()
    print(processes)

    # Start a process
    pm2.start(
        "your_script.py",
        name="Script-Name",
        extra_args=["-arg1", "value1"],
        name="YourProcessName",
    )
    # Restart a process
    pm2.restart(name="Script-Name")  # or pid=12345 or pm_id=1

    # Stop a process
    pm2.stop(name="Script-Name")  # or pid=12345 or pm_id=1

    # Delete a process
    pm2.delete(name="Script-Name")  # or pid=12345 or pm_id=1


# Async Methods
async def pm2_manager():
    # List all processes
    processes = await aiopm2.list()
    print(processes)

    # Start a process
    await aiopm2.start(
        "your_script.py",
        name="Script-Name",
        extra_args=["-arg1", "value1"],
        name="Script-Name",
    )

    # Restart a process
    await aiopm2.restart(name="Script-Name")  # or pid=12345 or pm_id=1

    # Stop a process
    await aiopm2.stop(name="Script-Name")  # or pid=12345 or pm_id=1

    # Delete a process
    await aiopm2.delete(name="Script-Name")  # or pid=12345 or pm_id=1


# Run the function
pm2_manager()
# or
asyncio.run(pm2_manager())

Replace 'your_script.py', 'Script-Name', and the args as necessary to fit your needs.

Contributing

Contributions are welcome! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature.
  3. Add your changes and commit them.
  4. Push to your branch.
  5. Create a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Thanks to the PM2 team for creating such a powerful process manager.
  • This library was inspired by the need to simplify process management in Python projects.

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

pm2-0.0.4.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

pm2-0.0.4.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file pm2-0.0.4.1.tar.gz.

File metadata

  • Download URL: pm2-0.0.4.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for pm2-0.0.4.1.tar.gz
Algorithm Hash digest
SHA256 c5c3a8cbd1a8d37e68fdf57fe6083d37edfe3d0615dbd20e9a349b2e360c4446
MD5 e69a601761f80e18ca233843ce88aed6
BLAKE2b-256 2fae616d4c493ab36a3cbac3afb1a4071e62697f1638e449f52d3d0660a1d86e

See more details on using hashes here.

File details

Details for the file pm2-0.0.4.1-py3-none-any.whl.

File metadata

  • Download URL: pm2-0.0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.0

File hashes

Hashes for pm2-0.0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae102e877e22f3476a952feaab6e03647cf263114fe77298ca99a8bb0295b184
MD5 e12c977fbfdf19c71e74d0553def2171
BLAKE2b-256 d3ef888faea6f8fa1f55c8b6b1114ff05a8bb8cce821b115f7db2ebb38a5d24f

See more details on using hashes here.

Supported by

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