> ## Documentation Index
> Fetch the complete documentation index at: https://explore.airia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Code Block

Add custom Python logic to your agent with pre-installed libraries. The Python Code Block lets you process data, integrate with external services, perform calculations, and implement custom business logic within your agent's workflow.

## Adding a Python Code Block

Navigate to your agent's workflow editor

* Drag the **Python Code Block** from the components panel
* Connect it to your desired step in the workflow
* Use the code editor to implement your custom logic

<Accordion title="Access the available variables">
  Available Variables:

  * input (str): Input from previous steps.
  * client\_data (dict): Contains user context with the following keys:
    * user\_id (str): The user's unique identifier.
    * user\_name (str): The user's display name.
    * conversation\_id (str): The conversation's unique identifier.
    * user\_input (str): The user's input text.
    * user\_roles (list\[str]): The user's roles.
    * user\_groups (list\[str]): The user's groups.
    * images (list\[str]): An array of image URLs.
    * additional\_info (list\[Any]): An array of objects containing additional information passed to the agent.
    * step\_inputs (list\[Any]): The inputs for the current step.
    * files (list\[str]): The files associated with the request.
    * parsed\_files (list\[dict]): Parsed file content from the Intelligent Parser (available when **Include Parsed Files** is enabled). Each entry contains:
      * file\_id (str): Blob storage identifier.
      * name (str): Original file name.
      * content (str): Parsed text output (markdown or structured content).
      * content\_type (str): MIME type of the original file.
    * variables (dict\[str, str]): Custom variables configured in the agent.
  * execution\_parameters (dict): Contains the following keys:
    * execution\_id (str): The unique identifier for the execution.
    * step\_results\_by\_type (dict): A dictionary containing the results of the previous steps, ordered by completion, with the following keys:
      * model (list\[Any]): The results of the model steps.
      * data\_source (list\[Any]): The results of the data search steps.
      * memory\_load (list\[Any]): The results of the memory load steps.
      * memory\_store (list\[Any]): The results of the memory store steps.
      * python (list\[Any]): The results of the python steps.
      * router (list\[Any]): The results of the router steps.
      * tool\_action (list\[Any]): The results of the tool action steps.
      * agent (list\[Any]): The results of the agent steps.
</Accordion>

## Accessing Parsed File Content

Python code blocks can access the content of files processed by the **Intelligent Parser** earlier in your agent pipeline. This allows you to programmatically manipulate, transform, or extract data from uploaded documents (PDFs, spreadsheets, etc.) directly in Python, without routing them through an LLM step.

### Enable Include Parsed Files

The feature is opt-in because file payloads can be large. To enable it:

1. Open your Python code block in the Agent Studio.
2. Toggle **"Include Parsed Files"** in the code block toolbar.

The toggle is available in both the classic editor and the vibe experience.

### Access Parsed Files in Your Code

When enabled, parsed file content is available in `client_data["parsed_files"]` as a list of objects. Each entry contains:

| Field          | Description                                         | Example                                  |
| -------------- | --------------------------------------------------- | ---------------------------------------- |
| `name`         | Original file name                                  | `"report.pdf"`                           |
| `content`      | Parsed text output (markdown or structured content) | `"# Report\n\nData..."`                  |
| `file_id`      | Blob storage identifier                             | `"a1b2c3d4-e5f6-7890-abcd-ef1234567890"` |
| `content_type` | MIME type of the original file                      | `"application/pdf"`                      |

```python theme={null}
for file in client_data.get("parsed_files", []):
    print(file["name"])         # e.g. "report.pdf"
    print(file["content"])      # Parsed markdown/structured output
    print(file["file_id"])      # Blob storage identifier
    print(file["content_type"]) # e.g. "application/pdf"
```

### Example: Extract and Process Parsed Documents

```python theme={null}
import json

results = []
for file in client_data.get("parsed_files", []):
    if file["content_type"] == "application/pdf":
        results.append({
            "source": file["name"],
            "data": file["content"]
        })

output = json.dumps(results)
```

### Parsed Files vs. LLM Step Attachments

If your pipeline also uses LLM steps with the **Include Attachments** option, here is how the two approaches compare:

|                      | Python Code Block (Include Parsed Files)   | LLM Step (Include Attachments) |
| -------------------- | ------------------------------------------ | ------------------------------ |
| **Content delivery** | Full content in a single entry per file    | Chunked into \~8 KB pieces     |
| **Processing**       | Programmatic (your Python code)            | Model-driven (prompt-based)    |
| **Best for**         | Data extraction, transformation, filtering | Summarization, Q\&A, analysis  |

Use **Include Parsed Files** when you need full programmatic control over the document content. Use **Include Attachments** on an LLM step when you want the model to reason over the content.

<Accordion title="Access the available libraries">
  airia==0.1.39

  aiohappyeyeballs==2.6.1

  aiohttp==3.13.4

  aiosignal==1.4.0

  annotated-types==0.7.0

  anyio==4.12.1

  asgiref==3.8.1

  asn1crypto==1.5.1

  atpublic==7.0.0

  attrs==25.3.0

  azure-ai-vision-imageanalysis==1.0.0

  azure-core==1.38.0

  azure-cli==2.83.0

  azure-identity==1.25.1

  azure-storage-blob==12.28.0b1

  azure-keyvault==4.2.0

  beautifulsoup4==4.13.4

  boto3==1.42.30

  botocore==1.42.30

  Brotli==1.2.0

  cachetools==7.0.0

  certifi==2025.4.26

  cffi==2.0.0

  charset-normalizer==3.4.1

  click==8.1.8

  cloudpickle==3.0.0

  cmdstanpy==1.3.0

  contourpy==1.3.2

  cryptography==46.0.7

  cycler==0.12.1

  Cython==3.0.12

  dataclasses-json==0.6.7

  decorator==5.2.1

  defusedxml==0.7.1

  Deprecated==1.3.1

  distro==1.9.0

  duckdb==1.4.4

  dnspython==2.7.0

  email\_validator==2.2.0

  et\_xmlfile==2.0.0

  fastapi==0.129.0

  fastapi-cli==0.0.20

  filelock==3.20.3

  filetype==1.2.0

  fonttools==4.61.0

  frozendict==2.4.6

  frozenlist==1.6.0

  gevent==25.4.2

  geventhttpclient==2.3.3

  googleapis-common-protos==1.70.0

  google-api-python-client==2.189.0

  greenlet==3.2.1

  grpcio==1.71.0

  gurobipy==12.0.2

  h11==0.16.0

  holidays==0.71

  html5lib==1.1

  httpcore==1.0.9

  httptools==0.7.1

  httpx==0.28.1

  idna==3.11

  imageio==2.37.2

  imageio-ffmpeg==0.6.0

  importlib\_metadata==8.6.1

  importlib\_resources==6.5.2

  iniconfig==2.1.0

  isodate==0.7.2

  Jinja2==3.1.6

  jiter==0.12.0

  jmespath==1.0.1

  joblib==1.5.3

  json\_repair==0.43.0

  jsonpatch==1.33

  jsonpointer==3.0.0

  kiwisolver==1.4.8

  langchain-core==1.2.28

  langchain-openai==1.0.2

  langchain-text-splitters==1.0.0

  langsmith==0.7.31

  lxml==6.1.0

  markdown-it-py==4.0.0

  MarkupSafe==3.0.2

  marshmallow==3.26.2

  matplotlib==3.10.1

  mdurl==0.1.2

  moviepy @ git+[https://github.com/Zulko/moviepy@c5b2423](https://github.com/Zulko/moviepy@c5b2423)  # pinned to commit with Pillow 11.2+ support

  multidict==6.4.3

  multitasking==0.0.12

  mypy\_extensions==1.1.0

  nltk==3.9.4

  numpy==1.26.4

  docxtpl==0.20.2

  openai==2.7.1

  opencv-python==4.11.0.86

  opencv-python-headless==4.11.0.86

  openpyxl==3.1.5

  opentelemetry-api==1.39.1

  opentelemetry-exporter-otlp==1.39.1

  opentelemetry-exporter-otlp-proto-common==1.39.1

  opentelemetry-exporter-otlp-proto-grpc==1.39.1

  opentelemetry-exporter-otlp-proto-http==1.39.1

  opentelemetry-instrumentation==0.60b1

  opentelemetry-instrumentation-asgi==0.60b1

  opentelemetry-instrumentation-fastapi==0.60b1

  opentelemetry-proto==1.39.1

  opentelemetry-sdk==1.39.1

  opentelemetry-semantic-conventions==0.60b1

  opentelemetry-util-http==0.60b1

  orjson==3.11.7

  packaging==24.2

  pandas==2.2.3

  pdf2image==1.17.0

  peewee==3.18.2

  pgeocode==0.5.0

  pillow==12.2.0

  pillow-avif-plugin==1.5.2

  pip-upgrade==0.0.6

  platformdirs==4.5.1

  playwright==1.58.0

  pluggy==1.5.0

  proglog==0.1.11

  prometheus\_client==0.21.1

  propcache==0.3.1

  prophet==1.1.6

  protobuf==6.33.5

  psycopg2-binary==2.9.11

  pybase64==1.4.2

  pycparser==2.22

  pydantic==2.11.3

  pydantic-settings==2.9.1

  pydantic\_core==2.33.1

  pyee==13.0.0

  Pygments==2.20.0

  PyJWT==2.12.0

  PyMuPDF==1.27.1

  pymupdf4llm==0.3.4

  PyMySQL==1.1.2

  pyodbc==5.3.0

  pyOpenSSL==26.0.0

  pyparsing==3.3.1

  pytesseract==0.3.13

  pytest==9.0.3

  pytest-asyncio==1.3.0

  python-dateutil==2.9.0.post0

  python-docx==1.1.2

  python-docx-replace==0.4.4

  python-dotenv==1.2.2

  python-multipart==0.0.26

  python-pptx==1.0.2

  python-rapidjson==1.20

  pytz==2025.2

  PyYAML==6.0.2

  regex==2025.10.23

  requests==2.33.0

  requests-toolbelt==1.0.0

  rich==14.3.3

  rich-toolkit==0.14.8

  s3transfer==0.16.0

  scipy==1.15.2

  shellingham==1.5.4

  simple-salesforce==1.12.6

  slack-sdk==3.35.0

  six==1.17.0

  sniffio==1.3.1

  snowflake-connector-python==4.4.0

  snowflake-snowpark-python==1.45.0

  snowflake.core==1.4.0

  sortedcontainers==2.4.0

  soupsieve==2.8.3

  SQLAlchemy==2.0.40

  stanio==0.5.1

  starlette==0.52.1

  tenacity==9.1.2

  tomlkit==0.13.2

  tqdm==4.67.1

  tritonclient==2.56.0

  typer==0.21.1

  typing-inspect==0.9.0

  typing-inspection==0.4.2

  typing\_extensions==4.13.2

  tzdata==2025.3

  tzlocal==5.3.1

  ujson==5.12.0

  urllib3==2.6.3

  uvicorn==0.34.2

  uvloop==0.21.0

  watchfiles==1.0.5

  weaviate-client==4.16.9

  webencodings==0.5.1

  websockets==15.0.1

  wrapt==1.17.2

  XlsxWriter==3.2.9

  yarl==1.22.0

  yfinance==0.2.57

  youtube-transcript-api==1.0.3

  zipp==3.23.0

  zope.event==6.1

  zope.interface==7.2

  zstandard==0.23.0
</Accordion>
