Skip to main content

PyCodeI (Python Code Interpreter)

This project provides a Python code interpreter that interacts with large language models trained by OpenAI. This interpreter is designed to run Python code in a notebook environment, enabling data analysis, visualization, and prediction. The Python code runs interactively, but in the notebook from the beginning each time.

Features

  • Data Analysis and Visualization: Analyze datasets and create appropriate graphs for visualization.
  • Trend Extraction and Future Projections: Extract trends from data and provide future projections.
  • Wide Range of Scientific Topics: Provide information on various scientific topics, including NLP, machine learning, mathematics, physics, chemistry, and biology.
  • Secure Handling of User Files: Store and persist user files in the /mnt/data drive.

Installation

Quick start (PyPI)

pip install pycodei

This installs the published package and exposes the pycodei CLI on your PATH.

Local development workflow

  1. Clone the repository:

    git clone https://github.com/KentaroAOKI/python_code_interpreter.git
    cd python_code_interpreter
    
  2. Install in editable mode (also registers the CLI):

    pip install -e .
    
  3. Create your user configuration file:

    mkdir -p ~/.pycodei
    cat > ~/.pycodei/config.json <<'EOF'
    {
      "DEPLOYMENT_NAME": "gpt-4o-mini",
      "PYCODEI_CLIENT": "azure",
      "AZURE_OPENAI_API_KEY": "<your azure openai api key>",
      "AZURE_OPENAI_ENDPOINT": "https://<your endpoint>.openai.azure.com/",
      "OPENAI_API_VERSION": "2024-10-01-preview",
      "OPENAI_API_KEY": "<your openai api key>"
    }
    EOF
    

    Running pycodei --help will also create this file with placeholder values if it does not exist.

Usage

To use the Python Code Interpreter, run the following command (replace the prompt text with your task):

pycodei "Retrieve NVIDIA stock prices from Jan-Mar 2023 and predict April onward."

Use pycodei --help to see optional flags such as --deployment-name, which overrides the value in ~/.pycodei/config.json.

Example

You can also start without an inline prompt; the CLI will ask for one interactively:

# Start CLI and respond to the input prompt
pycodei

A notebook file with the execution date and time is created in the results directory. You can view it with Visual Studio Code's Jupyter extension.

  • results/result_20250113-082727.ipynb
    Notebook where data analysis steps were recorded.
  • results/result_20250113-082727.json
    Log of messages sent to API.

Example 1

"Retrieve NVIDIA stock prices from Yahoo for January to March 2023 and predict prices from April 2023 onwards."
Result: sample_01.ipynb

Example 2

"Determine whether the data in /mnt/data/diagnosis.csv is malignant or benign. To make a decision, use the model learned using the load_breast_cancer data available from scikit-learn."
Result: sample_02.ipynb

Example 3

"2023年の1月から3月のNVIDIA株価をYahooから取得して、2023年4月以降の株価を予測してください。"
Result: sample_03.ipynb

Example 4

"/mnt/data/diagnosis.csv のデータが悪性か良性か判断してください。判断は、scikit-learn から取得できる load_breast_cancer データで学習したモデルを使ってください。日本語で説明してください。"
Result: sample_04.ipynb

Configuration

Runtime credentials are read from ~/.pycodei/config.json. Example:

{
  "DEPLOYMENT_NAME": "gpt-4o-mini",
  "PYCODEI_CLIENT": "azure",
  "AZURE_OPENAI_API_KEY": "<your azure openai api key>",
  "AZURE_OPENAI_ENDPOINT": "https://<your endpoint>.openai.azure.com/",
  "OPENAI_API_VERSION": "2024-10-01-preview",
  "OPENAI_API_KEY": "<your openai api key>",
  "mcpServers": {
    "filesystem": {
      "disabled": true,
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/share"
      ],
      "env": {
        "FS_ROOT": "/path/to/share"
      }
    }
  }
}

Set "PYCODEI_CLIENT" to azure (default) or openai to choose which SDK client the interpreter instantiates; you can temporarily override it with the PYCODEI_CLIENT environment variable. All other keys map directly to the environment variables expected by the OpenAI/Azure SDKs. Leaving a value blank may cause authentication failures, so be sure to populate the entries relevant to your deployment.

Optional: PYCODEI.md

If you keep a PYCODEI.md file, its contents are appended to the system prompt every time pycodei starts. Place the file in one of these locations (checked in order): ~/.pycodei/PYCODEI.md, the directory where the package is installed (alongside python_code_interpreter.py), or your current working directory. Use it for persistent guardrails, safety rules, or project-specific requirements.

Optional: MCP servers

pycodei can now connect to multiple Model Context Protocol servers using the same schema. Add them under the "mcpServers" key in ~/.pycodei/config.json and set "disabled": false for the entries you want to enable. Example:

"mcpServers": {
  "filesystem": {
    "disabled": false,
    "command": "npx",
    "args": [
      "-y",
      "@modelcontextprotocol/server-filesystem",
      "/Users/me/workspace"
    ],
    "env": {
      "FS_ROOT": "/Users/me/workspace"
    }
  },
  "custom_tool": {
    "command": "/usr/local/bin/python",
    "args": [
      "/path/to/server.py"
    ],
    "cwd": "/path/to",
    "transport": "stdio"
  }
}

When pycodei starts it will spin up each enabled server, discover its MCP tools, and register them as callable functions. Tool names are derived from server_name__tool_name and become available to the model alongside the built-in run_python tool. SSE (transport: "sse") and WebSocket (transport: "websocket") endpoints are also supported if you prefer remote servers—specify a url instead of a command.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for pycodei 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycodei 0.1.9
File Size Uploaded Provenance Actions
pycodei-0.1.9.tar.gz 74.0 kB Without provenance Details for pycodei-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycodei 0.1.9
File Interpreter ABI Platform Actions
pycodei-0.1.9-py3-none-any.whl Python 3 none any Details for pycodei-0.1.9-py3-none-any.whl

Total release size: 159.9 kB

Release files / pycodei-0.1.9.tar.gz

Download URL pycodei-0.1.9.tar.gz
Size 74.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cc011c4e69c95ac06b745a341c2cc8ac6c8f85416b7b9b8e7d2790d2fdfb5e47
BLAKE2b-256 checksum
How to use checksums
292b0010af0cdbaf2c7e8edf11376bcf6ae0d6c7f8e1f33c5df2f441fe0fee8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / pycodei-0.1.9-py3-none-any.whl

Download URL pycodei-0.1.9-py3-none-any.whl
Size 85.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbfa5e70bbee6ecd3e029798ee4303264c92ede57b5f6d3a85f474dc594ecac1
BLAKE2b-256 checksum
How to use checksums
dbb9dad898ca572e28abbfd038964fb1341f348f85efb21b5323abd0aa543a11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for pycodei 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page