agentleFS
Cogni-AI-OUCogni-AI-OU/cogni-ai-agent-skills/python-cli/SKILL.md

python-cli

Skill4 starsChanged 6 months agoMITView on GitHub

Execute Python inline scripts via heredocs for complex log processing, data transformation, or CLI utilities like URL encoding/decoding. You MUST load this skill when processing large logs or performing one-liner data operations.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use Python via python3 - <<'PY' heredocs or one-liners when processing large log files, performing data transformations (like URL …

    line 14
  2. Very specific:

    When processing complex JSON structures in shell scripts where jq is insufficient or unavailable.

    line 21
  3. Distinctive:

    When iterating over massive log files requiring stateful parsing that breaks standard bash pipelines.

    line 23
  4. Very specific:

    When a simple grep or sed command is completely sufficient and more performant for the task.

    line 28
  5. Distinctive:

    If the environment explicitly lacks a Python interpreter.

    line 29
  6. Very specific:

    Self-Contained Execution: Use heredoc (<<'PY') to execute inline Python without writing temporary .py scripts.

    line 40
  7. Very specific:

    Quote the delimiter: Always quote the heredoc delimiter (<<'PY') to prevent variable expansion by bash.

    line 41
  8. Distinctive:

    Use this pattern when you need to extract and print a specific slice of lines from a file.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: python-cli

<!-- markdownlint-disable MD013 MD023 MD031 MD032 -->

Use Python via python3 - <<'PY' heredocs or one-liners when processing large log files, performing data transformations (like URL encoding/decoding), or parsing structured data (like JSON) where standard bash utilities (awk/sed/grep) become unwieldy or fragile. If python3 is unavailable, you may fall back to python.

When to Use

  • When processing complex JSON structures in shell scripts where jq is insufficient or unavailable.
  • To perform multi-line text transformations, URL encoding, or regex processing inline.
  • When iterating over massive log files requiring stateful parsing that breaks standard bash pipelines.

When Not to Use

  • For writing permanent, complex application logic (create a proper .py module instead).
  • When a simple grep or sed command is completely sufficient and more performant for the task.
  • If the environment explicitly lacks a Python interpreter.

Common Pitfalls

  • Unquoted Heredocs: Failing to quote the heredoc delimiter (<<'PY'), causing bash to prematurely expand $variables intended for Python logic.
  • Memory Exhaustion: Using file.read() or readlines() on multi-gigabyte log files instead of iterating line-by-line (for line in file:).
  • Silent Failures: Forgetting to wrap file operations in a try...except block, causing the entire inline script to crash if one log file is missing.

Core Principles

  • Avoid Fragile Bash Pipelines: Transition to Python for multi-file processing, stateful parsing, or complex data transformations.
  • Self-Contained Execution: Use heredoc (<<'PY') to execute inline Python without writing temporary .py scripts.
  • Quote the delimiter: Always quote the heredoc delimiter (<<'PY') to prevent variable expansion by bash.
  • Robust Parsing: Utilize built-in json, pathlib, and re modules for robust text parsing.

Usage Patterns

Generic Log Processing and Filtering

Process multiple files, parse JSON structures, and filter for specific keywords or conditions dynamically.

python3 - <<'PY'
import json
import pathlib

# Define input sources mapping logical names to file paths
files = {
    'system-A': '/tmp/log-A.json',
    'system-B': '/tmp/log-B.json'
}

keywords = ['failed', 'fatal', 'error']

for name, path in files.items():
    print(f'===== {name} =====')
    try:
        # Use streaming approach for large files to minimize memory footprint
        with open(path, 'r', encoding='utf-8') as f:
            for i, line in enumerate(f):
                lower_line = line.lower()
                if any(k in lower_line for k in keywords):
                    # strip() removes trailing newline for cleaner output
                    print(f'{i+1}: {line.strip()}')
    except Exception as e:
        print(f"Failed to process {name} (path: {path}): {e}")
    print()
PY

Read Specific Line Range

Use this pattern when you need to extract and print a specific slice of lines from a file.

python3 -c "import sys; print(''.join(open('<file-path>').readlines()[140:160]))"

URL Encoding and Decoding

Perform quick URL encoding or decoding using Python's urllib.parse.

URL Encode:

echo "text to encode" | python3 -c "import urllib.parse; print(urllib.parse.quote(input()))"

URL Decode:

echo "text%20to%20decode" | python3 -c "import urllib.parse; print(urllib.parse.unquote(input()))"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.