pycoreux


Namepycoreux JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA Python library providing shell-like utilities for file operations, text processing, and subprocess management
upload_time2025-07-31 14:39:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords shell utilities coreutils file-processing text-processing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycoreux

<div align="center">
  <img src="pycoreux.png" alt="pycoreux - Python Unix Core Utilities" />
</div>

[![Build Status](https://github.com/kumarmunish/pycoreux/workflows/CI/badge.svg)](https://github.com/kumarmunish/pycoreux/actions)
[![PyPI version](https://img.shields.io/pypi/v/pycoreux.svg)](https://pypi.org/project/pycoreux/)
[![Python versions](https://img.shields.io/pypi/pyversions/pycoreux.svg)](https://pypi.org/project/pycoreux/)
[![Tests](https://img.shields.io/github/actions/workflow/status/kumarmunish/pycoreux/ci.yml?label=tests&logo=pytest)](https://github.com/kumarmunish/pycoreux/actions)
[![Coverage](https://codecov.io/gh/kumarmunish/pycoreux/branch/main/graph/badge.svg)](https://codecov.io/gh/kumarmunish/pycoreux)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
---

**A modern Python library that provides shell-like utilities for file operations, text processing, and subprocess management. Inspired by Unix coreutils, pycoreux offers a Pythonic API for building portable, scriptable command-line workflows with ease.**

## Features

- **File Operations**: Read, write, and manipulate files with ease
- **Text Processing**: Count lines/words, search patterns, head/tail operations
- **Process Management**: Execute subprocesses with simple APIs
- **String Utilities**: Pattern matching, text manipulation
- **Path Operations**: Directory listing, file system navigation
- **Archive Operations**: Create and extract tar/zip archives
- **Pipeline Support**: Chain operations together like shell pipes

## Installation

```bash
pip install pycoreux
```

## Quick Start: Unix Equivalents

If you're already familiar with shell scripting and the Unix toolset, here is a comprehensive guide to the equivalent pycoreux operation for each Unix command:

| Unix / shell | pycoreux equivalent |
|--------------|-------------------|
| `cat file.txt` | `FileOps.cat("file.txt")` |
| `head -n 10 file.txt` | `FileOps.head("file.txt", 10)` |
| `tail -n 10 file.txt` | `FileOps.tail("file.txt", 10)` |
| `wc file.txt` | `FileOps.wc("file.txt")` |
| `ls -la` | `FileOps.ls(".", show_hidden=True, long_format=True)` |
| `grep pattern file.txt` | `TextUtils.grep("pattern", "file.txt")` |
| `grep -i pattern file.txt` | `TextUtils.grep("pattern", "file.txt", ignore_case=True)` |
| `grep -n pattern file.txt` | `TextUtils.grep("pattern", "file.txt", line_numbers=True)` |
| `grep -v pattern file.txt` | `TextUtils.grep("pattern", "file.txt", invert=True)` |
| `sort file.txt` | `TextUtils.sort(lines)` |
| `sort -r file.txt` | `TextUtils.sort(lines, reverse=True)` |
| `sort -n file.txt` | `TextUtils.sort(lines, numeric=True)` |
| `uniq file.txt` | `TextUtils.uniq(lines)` |
| `uniq -c file.txt` | `TextUtils.uniq(lines, count=True)` |
| `nl file.txt` | `TextUtils.nl("file.txt")` |
| `echo "hello world"` | `TextUtils.echo("hello", "world")` |
| `cut -d',' -f1 file.txt` | `TextUtils.cut(line, delimiter=",", fields=1)` |
| `sed 's/old/new/g' file.txt` | `TextUtils.replace(text, "old", "new")` |
| `find . -name "*.txt"` | `PathUtils.find(".", name="*.txt")` |
| `find . -type f` | `PathUtils.find(".", type_filter="f")` |
| `which python` | `ProcessUtils.which("python")` |
| `ps aux` | `ProcessUtils.ps()` |
| `tar -czf archive.tar.gz files/` | `ArchiveUtils.tar_create("archive.tar.gz", ["files/"], "gz")` |
| `tar -xzf archive.tar.gz` | `ArchiveUtils.tar_extract("archive.tar.gz")` |
| `gzip file.txt` | `ArchiveUtils.gzip_file("file.txt")` |
| `gunzip file.txt.gz` | `ArchiveUtils.gunzip_file("file.txt.gz")` |

## Some Examples

Let's see some simple examples. Suppose you want to read the contents of a file as a string:

```python
from pycoreux import FileOps

content = FileOps.cat("test.txt")
```

That looks straightforward enough, but suppose you now want to count the lines in that file:

```python
lines, words, chars = FileOps.wc("test.txt")
print(f"File has {lines} lines")
```

For something a bit more challenging, let's try finding all lines in the file that contain "Error":

```python
from pycoreux import TextUtils

error_lines = TextUtils.grep("Error", "test.txt")
print(error_lines)
```

Want to get just the first 10 lines of a file?

```python
first_ten = FileOps.head("test.txt", 10)
print(first_ten)
```

Let's combine operations - read a file, find lines containing "Error", and get only the first 5 matches:

```python
# Read file and split into lines
content = FileOps.cat("test.txt")
lines = content.split('\n')

# Filter for error lines
error_lines = [line for line in lines if "Error" in line]

# Get first 5
first_five_errors = error_lines[:5]
print('\n'.join(first_five_errors))

# Or using grep directly for the same result
error_output = TextUtils.grep("Error", "test.txt")
error_lines = error_output.split('\n')
first_five = error_lines[:5]
print('\n'.join(first_five))
```

Want to sort some data? No problem:

```python
lines = ["zebra", "apple", "banana", "cherry"]
sorted_output = TextUtils.sort(lines)
print(sorted_output)
# Output:
# apple
# banana
# cherry
# zebra
```

Let's try something more complex - count unique occurrences:

```python
lines = ["apple", "apple", "banana", "apple", "cherry", "banana"]
unique_output = TextUtils.uniq(lines, count=True)
print(unique_output)
# Output:
#       2 apple
#       1 banana
#       1 apple
#       1 cherry
#       1 banana
```

Running external commands:

```python
from pycoreux import ProcessUtils

# Simple command execution
result = ProcessUtils.run("ls -la")
if result.success:
    print(result.stdout)

# Capture output directly
output = ProcessUtils.capture("date")
print(f"Current date: {output.strip()}")

# Find executable location
python_path = ProcessUtils.which("python3")
print(f"Python is at: {python_path}")
```

Working with archives:

```python
from pycoreux import ArchiveUtils

# Create a tar.gz archive
ArchiveUtils.tar_create("backup.tar.gz", ["important_files/"], compression="gz")

# Extract it later
extracted_files = ArchiveUtils.tar_extract("backup.tar.gz", "restore/")
print(f"Extracted: {extracted_files}")

# Compress a single file
compressed_file = ArchiveUtils.gzip_file("large_file.txt")
print(f"Compressed to: {compressed_file}")
```

## A Realistic Use Case

Let's use pycoreux to write a program that system administrators might actually need. Suppose we want to analyze web server logs to find the most frequent visitors. Given an Apache log file, we want to extract IP addresses and count their occurrences.

In a shell script, you might do:

```bash
cut -d' ' -f 1 access.log | sort | uniq -c | sort -rn | head -10
```

Here's the equivalent using pycoreux:

```python
from pycoreux import FileOps, TextUtils

# Direct pipeline style - each step mirrors the Unix command
def analyze_access_log(log_file):
    content = FileOps.cat(log_file)                                    # cat access.log
    ips = [TextUtils.cut(line, ' ', 1) for line in content.split('\n') if line.strip()]  # cut -d' ' -f 1
    sorted_ips = TextUtils.sort(ips)                                   # sort
    unique_counts = TextUtils.uniq(sorted_ips.split('\n'), count=True) # uniq -c
    reverse_sorted = TextUtils.sort(unique_counts.split('\n'), reverse=True, numeric=True)  # sort -rn
    return FileOps.head(content=reverse_sorted, lines=10)             # head -10

# Usage
print(analyze_access_log("access.log"))

# Or using the TextUtils.pipe function for functional composition:
from functools import partial

pipeline = TextUtils.pipe(
    FileOps.cat,
    lambda content: [TextUtils.cut(line, ' ', 1) for line in content.split('\n') if line.strip()],
    TextUtils.sort,
    lambda ips: TextUtils.uniq(ips.split('\n'), count=True),
    lambda counts: TextUtils.sort(counts.split('\n'), reverse=True, numeric=True),
    lambda sorted_counts: FileOps.head(content=sorted_counts, lines=10)
)
result = pipeline("access.log")
```

Output:

```text
      16 176.182.2.191
       7 212.205.21.11
       1 190.253.121.1
       1 90.53.111.17
```

## Pipeline-Style Operations

You can chain operations together for powerful data processing, mimicking Unix shell pipelines:

```python
from pycoreux import FileOps, TextUtils

# Example 1: Simple one-liner chaining
# Shell equivalent: cat app.log | grep "ERROR" | head -5
first_errors = FileOps.head(content=TextUtils.grep("ERROR", content=FileOps.cat("app.log")), lines=5)
print(first_errors)

# Example 2: Multi-step chaining (easier to read)
# Shell equivalent: cat app.log | grep "ERROR" | sort | head -3
content = FileOps.cat("app.log")                           # cat app.log
errors = TextUtils.grep("ERROR", content=content)          # | grep "ERROR"
sorted_errors = TextUtils.sort(errors.split('\n'))         # | sort
top_errors = FileOps.head(content=sorted_errors, lines=3)  # | head -3
print(top_errors)

# Example 3: Processing multiple files
# Shell equivalent: cat *.log | grep "WARN" | head -10
import glob
all_logs = '\n'.join([FileOps.cat(f) for f in glob.glob("*.log")])  # cat *.log
warnings = TextUtils.grep("WARN", content=all_logs)                 # | grep "WARN"
first_warnings = FileOps.head(content=warnings, lines=10)           # | head -10
print(first_warnings)
```

## CLI Usage

pycoreux also provides command-line tools:

```bash
# Using the CLI scripts
python -m pycoreux.scripts.pycoreux_cli cat myfile.txt
python -m pycoreux.scripts.pycoreux_cli head -n 5 myfile.txt
python -m pycoreux.scripts.pycoreux_cli grep "pattern" myfile.txt
python -m pycoreux.scripts.pycoreux_cli wc myfile.txt
```

## API Reference

### FileOps

- `cat(filepath)` - Read and return file contents
- `head(filepath=None, lines=10, content=None)` - Return first N lines as string (from file or content)
- `tail(filepath, lines=10)` - Return last N lines as string
- `ls(path=".", show_hidden=False, long_format=False)` - List directory contents
- `wc(filepath)` - Count lines, words, and characters
- `touch(filepath)` - Create empty file or update timestamp
- `mkdir(dirpath, parents=False)` - Create directory
- `rm(filepath, recursive=False)` - Remove files or directories

### TextUtils

- `echo(*args, sep=" ", end="\n")` - Join and return arguments as string
- `grep(pattern, filepath=None, content=None, ignore_case=False, line_numbers=False, invert=False)` - Search for patterns (in file or content)
- `nl(filepath, start=1, skip_empty=True)` - Add line numbers
- `sort(lines, reverse=False, numeric=False)` - Sort lines
- `uniq(lines, count=False)` - Remove duplicate consecutive lines
- `cut(line, delimiter="\t", fields=1)` - Extract fields from line
- `replace(text, pattern, replacement, count=0, ignore_case=False)` - Replace patterns in text
- `wc(text)` - Count words, lines, characters in text
- `pipe(*functions)` - Create a pipeline of functions for chaining operations

### ProcessUtils

- `run(command, shell=True, **kwargs)` - Execute command and return ProcessResult
- `capture(command, **kwargs)` - Execute command and return stdout
- `pipe(commands)` - Chain commands with pipes
- `which(program)` - Find program in PATH
- `kill(pid, signal=15)` - Send signal to process
- `ps()` - List running processes

### PathUtils

- `find(path=".", name=None, type_filter=None, max_depth=None)` - Find files and directories
- `which_all(program)` - Find all instances of program in PATH
- `du(path, human_readable=False)` - Calculate disk usage
- `chmod(path, mode)` - Change file permissions
- `stat_info(path)` - Get detailed file information
- `copy(src, dst, recursive=False)` - Copy files or directories
- `move(src, dst)` - Move/rename files or directories
- `symlink(target, link_name)` - Create symbolic link
- `readlink(path)` - Read symbolic link target

### ArchiveUtils

- `tar_create(archive_path, files, compression=None)` - Create tar archive
- `tar_extract(archive_path, extract_to=".")` - Extract tar archive
- `tar_list(archive_path)` - List tar archive contents
- `zip_create(archive_path, files, compression_level=6)` - Create zip archive
- `zip_extract(archive_path, extract_to=".")` - Extract zip archive
- `zip_list(archive_path)` - List zip archive contents
- `gzip_file(file_path, output_path=None)` - Compress file with gzip
- `gunzip_file(file_path, output_path=None)` - Decompress gzip file
- `compress_file(file_path, method="gz")` - Compress with specified method
- `decompress_file(file_path)` - Auto-detect and decompress file

## Development

```bash
# Clone the repository
git clone https://github.com/kumarmunish/pycoreux.git
cd pycoreux

# Install in development mode
pip install -e ".[dev]"

# Set up pre-commit hooks (optional)
pre-commit install

# Run tests
pytest

# Format code
black .
isort .

# Type checking
mypy pycoreux

# Run all checks (like CI)
black --check .
isort --check-only .
flake8 pycoreux
mypy pycoreux
pytest
```

## Package Information

**pycoreux** is published on PyPI and can be installed using pip:

```bash
pip install pycoreux
```

### Package Details

- **Latest Version**: 0.1.1
- **License**: MIT
- **Python Support**: 3.8+
- **Platform**: Cross-platform (Windows, macOS, Linux)
- **Dependencies**: No external dependencies required for core functionality

### Development Status

- **Status**: Alpha
- **Intended Audience**: Developers, System Administrators, DevOps Engineers
- **Use Cases**: Shell scripting in Python, file processing, log analysis, automation

### Release History

- **v0.1.1** (2025-07-31): Refactored to renamed functions for consistency
- **v0.1.0** (2025-07-31): Initial release with core shell-like utilities

## License

MIT License – see [LICENSE](./LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pycoreux",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "shell, utilities, coreutils, file-processing, text-processing",
    "author": null,
    "author_email": "Munish Kumar <munishkumar631@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/dd/e7/e1a58542ad1851670bb487d8c238231d19abb1d932d812e9274bd47302c4/pycoreux-0.1.1.tar.gz",
    "platform": null,
    "description": "# pycoreux\n\n<div align=\"center\">\n  <img src=\"pycoreux.png\" alt=\"pycoreux - Python Unix Core Utilities\" />\n</div>\n\n[![Build Status](https://github.com/kumarmunish/pycoreux/workflows/CI/badge.svg)](https://github.com/kumarmunish/pycoreux/actions)\n[![PyPI version](https://img.shields.io/pypi/v/pycoreux.svg)](https://pypi.org/project/pycoreux/)\n[![Python versions](https://img.shields.io/pypi/pyversions/pycoreux.svg)](https://pypi.org/project/pycoreux/)\n[![Tests](https://img.shields.io/github/actions/workflow/status/kumarmunish/pycoreux/ci.yml?label=tests&logo=pytest)](https://github.com/kumarmunish/pycoreux/actions)\n[![Coverage](https://codecov.io/gh/kumarmunish/pycoreux/branch/main/graph/badge.svg)](https://codecov.io/gh/kumarmunish/pycoreux)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n---\n\n**A modern Python library that provides shell-like utilities for file operations, text processing, and subprocess management. Inspired by Unix coreutils, pycoreux offers a Pythonic API for building portable, scriptable command-line workflows with ease.**\n\n## Features\n\n- **File Operations**: Read, write, and manipulate files with ease\n- **Text Processing**: Count lines/words, search patterns, head/tail operations\n- **Process Management**: Execute subprocesses with simple APIs\n- **String Utilities**: Pattern matching, text manipulation\n- **Path Operations**: Directory listing, file system navigation\n- **Archive Operations**: Create and extract tar/zip archives\n- **Pipeline Support**: Chain operations together like shell pipes\n\n## Installation\n\n```bash\npip install pycoreux\n```\n\n## Quick Start: Unix Equivalents\n\nIf you're already familiar with shell scripting and the Unix toolset, here is a comprehensive guide to the equivalent pycoreux operation for each Unix command:\n\n| Unix / shell | pycoreux equivalent |\n|--------------|-------------------|\n| `cat file.txt` | `FileOps.cat(\"file.txt\")` |\n| `head -n 10 file.txt` | `FileOps.head(\"file.txt\", 10)` |\n| `tail -n 10 file.txt` | `FileOps.tail(\"file.txt\", 10)` |\n| `wc file.txt` | `FileOps.wc(\"file.txt\")` |\n| `ls -la` | `FileOps.ls(\".\", show_hidden=True, long_format=True)` |\n| `grep pattern file.txt` | `TextUtils.grep(\"pattern\", \"file.txt\")` |\n| `grep -i pattern file.txt` | `TextUtils.grep(\"pattern\", \"file.txt\", ignore_case=True)` |\n| `grep -n pattern file.txt` | `TextUtils.grep(\"pattern\", \"file.txt\", line_numbers=True)` |\n| `grep -v pattern file.txt` | `TextUtils.grep(\"pattern\", \"file.txt\", invert=True)` |\n| `sort file.txt` | `TextUtils.sort(lines)` |\n| `sort -r file.txt` | `TextUtils.sort(lines, reverse=True)` |\n| `sort -n file.txt` | `TextUtils.sort(lines, numeric=True)` |\n| `uniq file.txt` | `TextUtils.uniq(lines)` |\n| `uniq -c file.txt` | `TextUtils.uniq(lines, count=True)` |\n| `nl file.txt` | `TextUtils.nl(\"file.txt\")` |\n| `echo \"hello world\"` | `TextUtils.echo(\"hello\", \"world\")` |\n| `cut -d',' -f1 file.txt` | `TextUtils.cut(line, delimiter=\",\", fields=1)` |\n| `sed 's/old/new/g' file.txt` | `TextUtils.replace(text, \"old\", \"new\")` |\n| `find . -name \"*.txt\"` | `PathUtils.find(\".\", name=\"*.txt\")` |\n| `find . -type f` | `PathUtils.find(\".\", type_filter=\"f\")` |\n| `which python` | `ProcessUtils.which(\"python\")` |\n| `ps aux` | `ProcessUtils.ps()` |\n| `tar -czf archive.tar.gz files/` | `ArchiveUtils.tar_create(\"archive.tar.gz\", [\"files/\"], \"gz\")` |\n| `tar -xzf archive.tar.gz` | `ArchiveUtils.tar_extract(\"archive.tar.gz\")` |\n| `gzip file.txt` | `ArchiveUtils.gzip_file(\"file.txt\")` |\n| `gunzip file.txt.gz` | `ArchiveUtils.gunzip_file(\"file.txt.gz\")` |\n\n## Some Examples\n\nLet's see some simple examples. Suppose you want to read the contents of a file as a string:\n\n```python\nfrom pycoreux import FileOps\n\ncontent = FileOps.cat(\"test.txt\")\n```\n\nThat looks straightforward enough, but suppose you now want to count the lines in that file:\n\n```python\nlines, words, chars = FileOps.wc(\"test.txt\")\nprint(f\"File has {lines} lines\")\n```\n\nFor something a bit more challenging, let's try finding all lines in the file that contain \"Error\":\n\n```python\nfrom pycoreux import TextUtils\n\nerror_lines = TextUtils.grep(\"Error\", \"test.txt\")\nprint(error_lines)\n```\n\nWant to get just the first 10 lines of a file?\n\n```python\nfirst_ten = FileOps.head(\"test.txt\", 10)\nprint(first_ten)\n```\n\nLet's combine operations - read a file, find lines containing \"Error\", and get only the first 5 matches:\n\n```python\n# Read file and split into lines\ncontent = FileOps.cat(\"test.txt\")\nlines = content.split('\\n')\n\n# Filter for error lines\nerror_lines = [line for line in lines if \"Error\" in line]\n\n# Get first 5\nfirst_five_errors = error_lines[:5]\nprint('\\n'.join(first_five_errors))\n\n# Or using grep directly for the same result\nerror_output = TextUtils.grep(\"Error\", \"test.txt\")\nerror_lines = error_output.split('\\n')\nfirst_five = error_lines[:5]\nprint('\\n'.join(first_five))\n```\n\nWant to sort some data? No problem:\n\n```python\nlines = [\"zebra\", \"apple\", \"banana\", \"cherry\"]\nsorted_output = TextUtils.sort(lines)\nprint(sorted_output)\n# Output:\n# apple\n# banana\n# cherry\n# zebra\n```\n\nLet's try something more complex - count unique occurrences:\n\n```python\nlines = [\"apple\", \"apple\", \"banana\", \"apple\", \"cherry\", \"banana\"]\nunique_output = TextUtils.uniq(lines, count=True)\nprint(unique_output)\n# Output:\n#       2 apple\n#       1 banana\n#       1 apple\n#       1 cherry\n#       1 banana\n```\n\nRunning external commands:\n\n```python\nfrom pycoreux import ProcessUtils\n\n# Simple command execution\nresult = ProcessUtils.run(\"ls -la\")\nif result.success:\n    print(result.stdout)\n\n# Capture output directly\noutput = ProcessUtils.capture(\"date\")\nprint(f\"Current date: {output.strip()}\")\n\n# Find executable location\npython_path = ProcessUtils.which(\"python3\")\nprint(f\"Python is at: {python_path}\")\n```\n\nWorking with archives:\n\n```python\nfrom pycoreux import ArchiveUtils\n\n# Create a tar.gz archive\nArchiveUtils.tar_create(\"backup.tar.gz\", [\"important_files/\"], compression=\"gz\")\n\n# Extract it later\nextracted_files = ArchiveUtils.tar_extract(\"backup.tar.gz\", \"restore/\")\nprint(f\"Extracted: {extracted_files}\")\n\n# Compress a single file\ncompressed_file = ArchiveUtils.gzip_file(\"large_file.txt\")\nprint(f\"Compressed to: {compressed_file}\")\n```\n\n## A Realistic Use Case\n\nLet's use pycoreux to write a program that system administrators might actually need. Suppose we want to analyze web server logs to find the most frequent visitors. Given an Apache log file, we want to extract IP addresses and count their occurrences.\n\nIn a shell script, you might do:\n\n```bash\ncut -d' ' -f 1 access.log | sort | uniq -c | sort -rn | head -10\n```\n\nHere's the equivalent using pycoreux:\n\n```python\nfrom pycoreux import FileOps, TextUtils\n\n# Direct pipeline style - each step mirrors the Unix command\ndef analyze_access_log(log_file):\n    content = FileOps.cat(log_file)                                    # cat access.log\n    ips = [TextUtils.cut(line, ' ', 1) for line in content.split('\\n') if line.strip()]  # cut -d' ' -f 1\n    sorted_ips = TextUtils.sort(ips)                                   # sort\n    unique_counts = TextUtils.uniq(sorted_ips.split('\\n'), count=True) # uniq -c\n    reverse_sorted = TextUtils.sort(unique_counts.split('\\n'), reverse=True, numeric=True)  # sort -rn\n    return FileOps.head(content=reverse_sorted, lines=10)             # head -10\n\n# Usage\nprint(analyze_access_log(\"access.log\"))\n\n# Or using the TextUtils.pipe function for functional composition:\nfrom functools import partial\n\npipeline = TextUtils.pipe(\n    FileOps.cat,\n    lambda content: [TextUtils.cut(line, ' ', 1) for line in content.split('\\n') if line.strip()],\n    TextUtils.sort,\n    lambda ips: TextUtils.uniq(ips.split('\\n'), count=True),\n    lambda counts: TextUtils.sort(counts.split('\\n'), reverse=True, numeric=True),\n    lambda sorted_counts: FileOps.head(content=sorted_counts, lines=10)\n)\nresult = pipeline(\"access.log\")\n```\n\nOutput:\n\n```text\n      16 176.182.2.191\n       7 212.205.21.11\n       1 190.253.121.1\n       1 90.53.111.17\n```\n\n## Pipeline-Style Operations\n\nYou can chain operations together for powerful data processing, mimicking Unix shell pipelines:\n\n```python\nfrom pycoreux import FileOps, TextUtils\n\n# Example 1: Simple one-liner chaining\n# Shell equivalent: cat app.log | grep \"ERROR\" | head -5\nfirst_errors = FileOps.head(content=TextUtils.grep(\"ERROR\", content=FileOps.cat(\"app.log\")), lines=5)\nprint(first_errors)\n\n# Example 2: Multi-step chaining (easier to read)\n# Shell equivalent: cat app.log | grep \"ERROR\" | sort | head -3\ncontent = FileOps.cat(\"app.log\")                           # cat app.log\nerrors = TextUtils.grep(\"ERROR\", content=content)          # | grep \"ERROR\"\nsorted_errors = TextUtils.sort(errors.split('\\n'))         # | sort\ntop_errors = FileOps.head(content=sorted_errors, lines=3)  # | head -3\nprint(top_errors)\n\n# Example 3: Processing multiple files\n# Shell equivalent: cat *.log | grep \"WARN\" | head -10\nimport glob\nall_logs = '\\n'.join([FileOps.cat(f) for f in glob.glob(\"*.log\")])  # cat *.log\nwarnings = TextUtils.grep(\"WARN\", content=all_logs)                 # | grep \"WARN\"\nfirst_warnings = FileOps.head(content=warnings, lines=10)           # | head -10\nprint(first_warnings)\n```\n\n## CLI Usage\n\npycoreux also provides command-line tools:\n\n```bash\n# Using the CLI scripts\npython -m pycoreux.scripts.pycoreux_cli cat myfile.txt\npython -m pycoreux.scripts.pycoreux_cli head -n 5 myfile.txt\npython -m pycoreux.scripts.pycoreux_cli grep \"pattern\" myfile.txt\npython -m pycoreux.scripts.pycoreux_cli wc myfile.txt\n```\n\n## API Reference\n\n### FileOps\n\n- `cat(filepath)` - Read and return file contents\n- `head(filepath=None, lines=10, content=None)` - Return first N lines as string (from file or content)\n- `tail(filepath, lines=10)` - Return last N lines as string\n- `ls(path=\".\", show_hidden=False, long_format=False)` - List directory contents\n- `wc(filepath)` - Count lines, words, and characters\n- `touch(filepath)` - Create empty file or update timestamp\n- `mkdir(dirpath, parents=False)` - Create directory\n- `rm(filepath, recursive=False)` - Remove files or directories\n\n### TextUtils\n\n- `echo(*args, sep=\" \", end=\"\\n\")` - Join and return arguments as string\n- `grep(pattern, filepath=None, content=None, ignore_case=False, line_numbers=False, invert=False)` - Search for patterns (in file or content)\n- `nl(filepath, start=1, skip_empty=True)` - Add line numbers\n- `sort(lines, reverse=False, numeric=False)` - Sort lines\n- `uniq(lines, count=False)` - Remove duplicate consecutive lines\n- `cut(line, delimiter=\"\\t\", fields=1)` - Extract fields from line\n- `replace(text, pattern, replacement, count=0, ignore_case=False)` - Replace patterns in text\n- `wc(text)` - Count words, lines, characters in text\n- `pipe(*functions)` - Create a pipeline of functions for chaining operations\n\n### ProcessUtils\n\n- `run(command, shell=True, **kwargs)` - Execute command and return ProcessResult\n- `capture(command, **kwargs)` - Execute command and return stdout\n- `pipe(commands)` - Chain commands with pipes\n- `which(program)` - Find program in PATH\n- `kill(pid, signal=15)` - Send signal to process\n- `ps()` - List running processes\n\n### PathUtils\n\n- `find(path=\".\", name=None, type_filter=None, max_depth=None)` - Find files and directories\n- `which_all(program)` - Find all instances of program in PATH\n- `du(path, human_readable=False)` - Calculate disk usage\n- `chmod(path, mode)` - Change file permissions\n- `stat_info(path)` - Get detailed file information\n- `copy(src, dst, recursive=False)` - Copy files or directories\n- `move(src, dst)` - Move/rename files or directories\n- `symlink(target, link_name)` - Create symbolic link\n- `readlink(path)` - Read symbolic link target\n\n### ArchiveUtils\n\n- `tar_create(archive_path, files, compression=None)` - Create tar archive\n- `tar_extract(archive_path, extract_to=\".\")` - Extract tar archive\n- `tar_list(archive_path)` - List tar archive contents\n- `zip_create(archive_path, files, compression_level=6)` - Create zip archive\n- `zip_extract(archive_path, extract_to=\".\")` - Extract zip archive\n- `zip_list(archive_path)` - List zip archive contents\n- `gzip_file(file_path, output_path=None)` - Compress file with gzip\n- `gunzip_file(file_path, output_path=None)` - Decompress gzip file\n- `compress_file(file_path, method=\"gz\")` - Compress with specified method\n- `decompress_file(file_path)` - Auto-detect and decompress file\n\n## Development\n\n```bash\n# Clone the repository\ngit clone https://github.com/kumarmunish/pycoreux.git\ncd pycoreux\n\n# Install in development mode\npip install -e \".[dev]\"\n\n# Set up pre-commit hooks (optional)\npre-commit install\n\n# Run tests\npytest\n\n# Format code\nblack .\nisort .\n\n# Type checking\nmypy pycoreux\n\n# Run all checks (like CI)\nblack --check .\nisort --check-only .\nflake8 pycoreux\nmypy pycoreux\npytest\n```\n\n## Package Information\n\n**pycoreux** is published on PyPI and can be installed using pip:\n\n```bash\npip install pycoreux\n```\n\n### Package Details\n\n- **Latest Version**: 0.1.1\n- **License**: MIT\n- **Python Support**: 3.8+\n- **Platform**: Cross-platform (Windows, macOS, Linux)\n- **Dependencies**: No external dependencies required for core functionality\n\n### Development Status\n\n- **Status**: Alpha\n- **Intended Audience**: Developers, System Administrators, DevOps Engineers\n- **Use Cases**: Shell scripting in Python, file processing, log analysis, automation\n\n### Release History\n\n- **v0.1.1** (2025-07-31): Refactored to renamed functions for consistency\n- **v0.1.0** (2025-07-31): Initial release with core shell-like utilities\n\n## License\n\nMIT License \u2013 see [LICENSE](./LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library providing shell-like utilities for file operations, text processing, and subprocess management",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/kumarmunish/pycoreux",
        "Issues": "https://github.com/kumarmunish/pycoreux/issues",
        "Repository": "https://github.com/kumarmunish/pycoreux"
    },
    "split_keywords": [
        "shell",
        " utilities",
        " coreutils",
        " file-processing",
        " text-processing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bc998a8b4d3ee6c6af5f52f6f64fe34ac7e0ff068ce161dd70c1c54d6d554dbf",
                "md5": "a25a941b4c5a761df24d5b56b91aaca7",
                "sha256": "b87a681726aa575030ef6f2dbeaf1a0c7d6e4961c9ada91e62e723cc00f41e88"
            },
            "downloads": -1,
            "filename": "pycoreux-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a25a941b4c5a761df24d5b56b91aaca7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18351,
            "upload_time": "2025-07-31T14:39:14",
            "upload_time_iso_8601": "2025-07-31T14:39:14.800634Z",
            "url": "https://files.pythonhosted.org/packages/bc/99/8a8b4d3ee6c6af5f52f6f64fe34ac7e0ff068ce161dd70c1c54d6d554dbf/pycoreux-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dde7e1a58542ad1851670bb487d8c238231d19abb1d932d812e9274bd47302c4",
                "md5": "5de68d20d5c5cfeeb633f79b890a7eb0",
                "sha256": "eba7bbdd689ab9058878ea2e40ddcaa9951bd4ecca53e0b9216142a84839a4fd"
            },
            "downloads": -1,
            "filename": "pycoreux-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5de68d20d5c5cfeeb633f79b890a7eb0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 23281,
            "upload_time": "2025-07-31T14:39:15",
            "upload_time_iso_8601": "2025-07-31T14:39:15.652535Z",
            "url": "https://files.pythonhosted.org/packages/dd/e7/e1a58542ad1851670bb487d8c238231d19abb1d932d812e9274bd47302c4/pycoreux-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 14:39:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kumarmunish",
    "github_project": "pycoreux",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pycoreux"
}
        
Elapsed time: 2.96979s