# 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:
```bash
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:
```python
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](https://github.com/y4kupkaya/pm2/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.
Raw data
{
"_id": null,
"home_page": "https://github.com/y4kupkaya/pm2",
"name": "pm2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "process-manager, pm2, pm2-py",
"author": "y4kupkaya",
"author_email": "contact@yakupkaya.net.tr",
"download_url": "https://files.pythonhosted.org/packages/a7/71/fb86d8d2745ed32789c16675284b661e32a93b443eb0b48981d12bcf4ba9/pm2-0.0.4.4.tar.gz",
"platform": null,
"description": "\r\n# PM2 Python Library for Process Management\r\n\r\n## Introduction\r\n\r\nThis 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.\r\n\r\n## Features\r\n\r\n- **Easy Process Management:** Start, stop, restart, and delete processes with simple Python functions.\r\n- **Automatic Process Launch:** Automatically launch multiple processes with predefined configurations.\r\n- **Real-time Process Monitoring:** Retrieve real-time information about process status, CPU, and memory usage.\r\n- **Flexible Configuration:** Configure processes programmatically, including environment variables, names, and log file locations.\r\n- **Event Handling:** Listen to and handle PM2 events directly within your Python scripts.\r\n\r\n## Installation\r\n\r\nTo install the PM2 Python Library, run the following command:\r\n\r\n```bash\r\npip install pm2\r\n```\r\n\r\n## Quick Start\r\n\r\nTo get started with the PM2 Python Library, here's a simple example that demonstrates how to start a process:\r\n\r\n```python\r\nfrom pm2 import PM2, AioPM2\r\nimport asyncio\r\n\r\npm2 = PM2()\r\naiopm2 = AioPM2()\r\n\r\n\r\n# Sync Methods\r\ndef pm2_manager():\r\n # List all processes\r\n processes = pm2.list()\r\n print(processes)\r\n\r\n # Start a process\r\n pm2.start(\r\n \"your_script.py\",\r\n name=\"Script-Name\",\r\n extra_args=[\"-arg1\", \"value1\"],\r\n name=\"YourProcessName\",\r\n )\r\n # Restart a process\r\n pm2.restart(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n # Stop a process\r\n pm2.stop(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n # Delete a process\r\n pm2.delete(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n\r\n# Async Methods\r\nasync def pm2_manager():\r\n # List all processes\r\n processes = await aiopm2.list()\r\n print(processes)\r\n\r\n # Start a process\r\n await aiopm2.start(\r\n \"your_script.py\",\r\n name=\"Script-Name\",\r\n extra_args=[\"-arg1\", \"value1\"],\r\n name=\"Script-Name\",\r\n )\r\n\r\n # Restart a process\r\n await aiopm2.restart(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n # Stop a process\r\n await aiopm2.stop(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n # Delete a process\r\n await aiopm2.delete(name=\"Script-Name\") # or pid=12345 or pm_id=1\r\n\r\n\r\n# Run the function\r\npm2_manager()\r\n# or\r\nasyncio.run(pm2_manager())\r\n```\r\n\r\nReplace `'your_script.py'`, `'Script-Name'`, and the args as necessary to fit your needs.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! If you would like to contribute, please follow these steps:\r\n\r\n1. Fork the repository.\r\n2. Create a new branch for your feature.\r\n3. Add your changes and commit them.\r\n4. Push to your branch.\r\n5. Create a pull request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/y4kupkaya/pm2/LICENSE) file for details.\r\n\r\n## Acknowledgments\r\n\r\n- Thanks to the PM2 team for creating such a powerful process manager.\r\n- This library was inspired by the need to simplify process management in Python projects.\r\n",
"bugtrack_url": null,
"license": "GNU AFFERO GENERAL PUBLIC LICENSE (v3)",
"summary": "Python wrapper for PM2",
"version": "0.0.4.4",
"project_urls": {
"Homepage": "https://github.com/y4kupkaya/pm2"
},
"split_keywords": [
"process-manager",
" pm2",
" pm2-py"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "08c09a6b119a2f3d765ca1bd0bff10ffb5e4e5d6d2701b4e3d12b0ac959e0ad0",
"md5": "c5393af6d2ecad6b5d246929cb54cd93",
"sha256": "b02b3b1282481c4b62fc3b5e6037a0d1d870d87ce4014722f90e3b15d7fb7e1e"
},
"downloads": -1,
"filename": "pm2-0.0.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c5393af6d2ecad6b5d246929cb54cd93",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 17494,
"upload_time": "2024-05-02T12:39:51",
"upload_time_iso_8601": "2024-05-02T12:39:51.661595Z",
"url": "https://files.pythonhosted.org/packages/08/c0/9a6b119a2f3d765ca1bd0bff10ffb5e4e5d6d2701b4e3d12b0ac959e0ad0/pm2-0.0.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a771fb86d8d2745ed32789c16675284b661e32a93b443eb0b48981d12bcf4ba9",
"md5": "e7681be064c8120af7104bf4c55345f4",
"sha256": "0f09ff899a7a31fef0ee0de344688c1fac7243787c6509206c6eac8b87cb8c7d"
},
"downloads": -1,
"filename": "pm2-0.0.4.4.tar.gz",
"has_sig": false,
"md5_digest": "e7681be064c8120af7104bf4c55345f4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 17436,
"upload_time": "2024-05-02T12:39:53",
"upload_time_iso_8601": "2024-05-02T12:39:53.431958Z",
"url": "https://files.pythonhosted.org/packages/a7/71/fb86d8d2745ed32789c16675284b661e32a93b443eb0b48981d12bcf4ba9/pm2-0.0.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-02 12:39:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "y4kupkaya",
"github_project": "pm2",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pm2"
}