🤖HermesBlog
Hermes Practical Guides · Part 18/9/2026

Use Hermes as a Python Library

Use Hermes as a Python Library — easy-to-understand guide based on official docs

Think of Hermes as a friendly robot assistant you can boss around with plain Python code — no need to learn a new language or click through a fancy dashboard.

What Does “Use as a Library” Mean?

Normally, you talk to Hermes through a chat window. But when you use it as a Python library, you write Python scripts that tell Hermes what to do. This is perfect for automating repetitive tasks like fixing code, running tests, or cleaning up files.

Your First Commands: Searching and Patching

Let’s say you have a big project with old API calls that need updating. Instead of opening each file manually, you can write a script that finds and fixes them all:

# Find all Python files using deprecated API and fix them
matches = search_files("old_api_call", path="src/", file_glob="*.py")
fixed = 0
for match in matches.get("matches", []):
    result = patch(
        path=match["path"],
        old_string="old_api_call(",
        new_string="new_api_call(",
        replace_all=True
    )
    if "error" not in str(result):
        fixed += 1

print(f"Fixed {fixed} files out of {len(matches.get('matches', []))} matches")

Here’s what happens: Hermes searches every .py file in src/, finds old_api_call(, and replaces it with new_api_call(. You just saved yourself hours of manual work.

Running Tests and Getting a Report

Want to know if your code actually works? You can run your test suite and get a clean summary:

from hermes_tools import terminal, read_file
import json

# Run tests, parse results, and report
result = terminal("cd /project && python -m pytest --tb=short -q 2>&1", timeout=120)
output = result.get("output", "")

# Parse test output
passed = output.count(" passed")
failed = output.count(" failed")
errors = output.count(" error")

report = {
    "passed": passed,
    "failed": failed,
    "errors": errors,
    "exit_code": result.get("exit_code", -1),
    "summary": output[-500:] if len(output) > 500 else output
}

print(json.dumps(report, indent=2))

This script runs your tests, counts how many passed or failed, and prints a neat JSON report. You can even email this report to your team automatically.

Two Ways to Run Your Code

Hermes gives you two “modes” for running scripts:

  • Project mode (default): Your script runs in your project folder, using the same Python environment you already have. This is best for everyday work — you can import pandas or read files with relative paths just like normal.

  • Strict mode: Your script runs in a separate, isolated folder with Hermes’s own Python. Use this when you want maximum reproducibility — like when you’re sharing a script with someone else and want to be sure it runs the same everywhere.

You can switch modes in your config file:

# ~/.hermes/config.yaml
code_execution:
  mode: project   # or "strict"

Safety First (Even When Coding)

Don’t worry about security — Hermes is careful. In both modes, it:

  • Removes API keys and passwords from your script’s environment
  • Blocks scripts from calling other Hermes tools recursively
  • Limits how long a script can run (5 minutes max) and how much output it can print

Wrap-Up and Pro Tip

Using Hermes as a Python library turns tedious chores into one-liner scripts. Start small: pick one repetitive task (like renaming variables or running tests) and automate it.

Practical tip: Always test your script on a copy of your project first, not the original. That way, if something goes wrong, you haven’t broken anything. Once you’re confident, run it on the real thing. Happy automating!

📖 Official Docs

This article is based on the official Hermes Agent documentation:Official docs › developer-guide/programmatic-integration