AIPy: Execute Python via Natural Language Directly in Your Terminal

8月6日 Published inLLM Tooling

AIPy integrates a complete Python environment with a Large Language Model (LLM). You type a command, hit enter, and see the result immediately. It functions exactly like the Python REPL you already know, but with the added capability to understand and act on plain English instructions.

If you work with data, this workflow will feel familiar:

  • You juggle various formats like CSVs, Excel files, JSON, HTML snippets, SQLite dumps, or Parquet.
  • You spend hours cleaning, transforming, aggregating, and plotting data.
  • You open a Python session, import pandas, and manually write out every command.
  • Your drive ends up cluttered with temporary files.
  • You explain a logic problem to ChatGPT, then copy, paste, and debug the resulting code.

AIPy removes the friction from this process. By staying entirely within the terminal, you simply describe the task you want to complete. AIPy writes the necessary code and executes it on the spot.

What Changes

  • No more memorizing or looking up boilerplate pandas syntax.
  • No more constant context-switching between your terminal and a browser-based chat window.

How It Works

AIPy (executed as aipython) is a Python interpreter with an embedded LLM.

  • Use it as a standard Python REPL for traditional coding.
  • Describe complex tasks in natural language, and AIPy will generate and run the code for you.

Both approaches share a single session. You can let the AI process a large CSV and then immediately inspect the resulting DataFrame using a standard command like df.head().

Modes of Operation

Task Mode Designed for users who want to focus on the result rather than the implementation. Just state the job and let the tool handle the rest.

uv run aipy
>>> Get the latest posts from Reddit r/LocalLLaMA
......
>>> /done

Alternatively, install it globally for quick access:

pip install aipyapp
aipy

Python Mode Built for developers who prefer working within a REPL environment. Use the --python flag to enable this mode.

>>> ai("Get the title of Google's homepage")

The tool also manages dependencies automatically. If the LLM determines that a library like psutil is required, it will prompt you for permission to install it.

>>> ai("Use psutil to list all processes on MacOS")

📦 LLM requests to install third-party packages: ['psutil']
If you agree and have installed, please enter 'y [y/n] (n): y

Configuration

To get started, set up an aipy.toml configuration file to manage your LLM settings.

[llm.deepseek]
type = "deepseek"
api_key = "Your DeepSeek API Key"
enable = true
default = true

API Hooks

The ai Object

  • ai(instruction): Initiates an automation loop that runs until the LLM completes the task.
  • ai.save(path): Exports the current session as an SVG or HTML file.
  • ai.llm: Provides direct access to the LLM client.
  • ai.runner: Provides access to the execution context.

The LLM Object

  • history: Contains the full message thread for the current session.

The Runner Object

  • globals / locals: The Python namespaces where the code is executed. This allows you to manually inspect variables after the AI has finished its task.

The runtime Object This object is utilized internally by LLM-generated code.

  • install_packages(packages): Prompts the user to install any missing libraries.
  • getenv(name, desc=None): Retrieves environment variables safely.
  • display(path=None, url=None): Renders images directly within the terminal.