Skip to content
View pymainprocess's full-sized avatar

Block or report pymainprocess

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 250 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
pymainprocess/README.md

pymainprocess

Python Extension Module for the best System Interaction, based on Rust.

Opinion

  1. Faster then Python OS and Python Subprocess Module.
  2. Great Interaction, fast Import.
  3. Runs Greate on Windows and Unix.

Install

Install with pip
  • Install from pypi.org

    pymainprocess
    pip install -U --no-cache-dir pymainprocess
  • Install via git (Way 1)

    1. Install Rust (Only Unix)

      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    2. Install Module with git

      pip install git+https://github.com/pymainprocess/pymainprocess
  • Install via git (Way 2)

    1. Install Rust (Only Unix)
    2. Install Module with git

      pip install https://github.com/pymainprocess/pymainprocess/archive/master.zip

Import

import pymainprocess as proc

Using

Run Command

command = 'apt-get update'
# Simple Run
proc.call(command)
# Run a Sudo
proc.sudo(command)
# Safe all output
stdout, stderr = proc.call(command, stdout=True, stderr=True)
# Safe all ouput as sudo
stdout, stderr = proc.sudo(command, stdout=True, stderr=True)
# Get only stdout
stdout = proc.call(command, stdout=True)
# Get only stderr
stderr = proc.call(command, stderr=True)
# Now as sudo
stdout = proc.sudo(command, stdout=True)
# Now as sudo
stderr = proc.sudo(command, stderr=True)

Work with Child Process (Only on Unix)

# Create a New Function
def cmd(command: str):
    # Get the pid
    pid = proc.fork(rust=True)
    # Now make the Command as List
    command = command.split(" ")
    # Now get the needed varibles
    file = command[0]
    args = command
    # Wait for PID 0
    if proc.wait(pid):
        proc.execvp(file, args, rust=True)

# Now Test the Function
command = 'ls -A'
cmd(command)

Walk the Current Dir

# A Simple walk will sort all Files and Dirs in the Given Path
path = proc.path.join('/', 'usr', 'local')
result = proc.path.walk(path)
# A Recursive Run will list the Current Path with all Sub Paths
result = proc.path.walk(path, recursive=True)

The Output looks so

(.venv) alex@DESKTOP-E4UA3DM:~/pymainprocess$ python
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymainprocess as proc
>>> path = '/usr/local'
>>> result = proc.path.walk(path)
>>> result2 = proc.path.walk(path, recursive=True)
>>>

result

>>> result
{'local': {'dirs': ['etc', 'man', 'share', 'sbin', 'games', 'src', 'lib', 'bin', 'include'], 'files': []}}
>>>

result2

>>> result2
{'local': {'dirs': [{'etc': {'files': [], 'dirs': []}}, {'man': {'dirs': [], 'files': []}}, {'share': {'dirs': [{'xml': {'files': [], 'dirs': [{'entities': {'files': [], 'dirs': []}}, {'misc': {'dirs': [], 'files': []}}, {'schema': {'files': [], 'dirs': []}}, {'declaration': {'dirs': [], 'files': []}}]}}, {'man': {'dirs': [], 'files': []}}, {'sgml': {'dirs': [{'entities': {'dirs': [], 'files': []}}, {'stylesheet': {'dirs': [], 'files': []}}, {'dtd': {'dirs': [], 'files': []}}, {'misc': {'dirs': [], 'files': []}}, {'declaration': {'files': [], 'dirs': []}}], 'files': []}}, {'fonts': {'files': [], 'dirs': []}}, {'ca-certificates': {'dirs': [], 'files': []}}], 'files': []}}, {'sbin': {'files': [], 'dirs': []}}, {'games': {'files': [], 'dirs': []}}, {'src': {'dirs': [], 'files': []}}, {'lib': {'files': [], 'dirs': [{'python3.12': {'files': [], 'dirs': [{'dist-packages': {'dirs': [], 'files': []}}]}}]}}, {'bin': {'files': ['maturin', 'cargo-deb', 'cargo-clone', 'mdbook'], 'dirs': []}}, {'include': {'dirs': [], 'files': []}}], 'files': []}}
>>>

The Output can be very Big, for this is Include as Function walksearch

walksearch

>>> proc.path.walksearch(result2, ['lib', 'python3.12'])
{'files': [], 'dirs': [{'dist-packages': {'dirs': [], 'files': []}}]}
>>>

Popular repositories Loading

  1. pymainprocess pymainprocess Public

    Python Process Module, written in rust and Python

    Rust

  2. pytype pytype Public

    pyo3 Extension Module

    Rust

  3. anyscript-compiler anyscript-compiler Public

    An Script Compiler, Self Extracted Manager and Co

    Rust

  4. termux_go_aarch64 termux_go_aarch64 Public

    Shell