# What Programming Language Is Used in AI Berkshire?

> Discover the programming language powering AI Berkshire. Learn how Python's extensive data science libraries drive financial research pipelines for this innovative project.

- Repository: [Xbt Lin/ai-berkshire](https://github.com/xbtlin/ai-berkshire)
- Tags: getting-started
- Published: 2026-07-09

---

**AI Berkshire is built entirely in Python, leveraging the language’s data‑science ecosystem to power financial research pipelines.**

The open‑source repository `xbtlin/ai-berkshire` implements a complete value‑investing research stack. Every data scraper, valuation checker, and report generator is written as a Python module, making the project accessible to data scientists and quant analysts familiar with the PyData stack.

## Core Language and Architecture

The codebase is **Python‑centric**. All executable logic resides in `.py` files that use standard libraries (`asyncio`, `json`, `pathlib`) alongside third‑party packages for numerical computing and web automation.

Key architectural characteristics include:

- **Synchronous and asynchronous patterns** – Blocking I/O for local file operations and `async/await` for web scraping.
- **Modular tool design** – Individual scripts in `tools/` handle discrete tasks such as valuation, screening, and scraping.
- **Codex integration** – Helper scripts in `scripts/` generate OpenAI Codex‑compatible skill packages from Markdown definitions.

## Key Python Modules and Source Files

### Financial Validation Engine

The [[`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py)](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py) module contains deterministic functions for sanity‑checking financial statements.

```python
def verify_market_cap(price, shares, reported_cap, currency=""):
    """Validate that the market‑cap computed from price × shares
    matches the reported market‑cap within a tolerance."""
    computed = price * shares
    diff_pct = abs(computed - reported_cap) / reported_cap * 100
    return diff_pct < 2.0   # passes if within 2 %

```

This function exemplifies the straightforward, math‑heavy Python used throughout the project.

### Stock Screening Utilities

[[`tools/stock_screener.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/stock_screener.py)](https://github.com/xbtlin/ai-berkshire/blob/main/tools/stock_screener.py) implements momentum and value grading.

```python
def check_momentum(prices):
    """Calculate a simple momentum signal from historic price series."""
    if len(prices) < 20:
        return None
    recent = prices[-1]
    past   = prices[-20]
    return (recent - past) / past

```

### Async Web Scraping

For data ingestion, [[`tools/xueqiu_scraper.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/xueqiu_scraper.py)](https://github.com/xbtlin/ai-berkshire/blob/main/tools/xueqiu_scraper.py) uses Playwright via Python’s `asyncio` API:

```python
async def browser_fetch_json(page, url, timeout_s=15):
    await page.goto(url, timeout=timeout_s * 1000)
    content = await page.content()
    return json.loads(content)

```

### Workflow Automation Scripts

The [[`scripts/sync-codex-skills.py`](https://github.com/xbtlin/ai-berkshire/blob/main/scripts/sync-codex-skills.py)](https://github.com/xbtlin/ai-berkshire/blob/main/scripts/sync-codex-skills.py) and [[`scripts/sync-codex-prompts.py`](https://github.com/xbtlin/ai-berkshire/blob/main/scripts/sync-codex-prompts.py)](https://github.com/xbtlin/ai-berkshire/blob/main/scripts/sync-codex-prompts.py) files parse Markdown skill definitions and emit JSON payloads suitable for OpenAI’s Codex CLI.

## Why Python for Financial Research?

Python dominates quantitative finance because of its **rich package ecosystem** (pandas, NumPy, requests) and **readability**. The AI Berkshire maintainers exploit these strengths to:

- Rapidly prototype valuation algorithms without compilation overhead.
- Integrate browser automation (Playwright) and data parsing in a single runtime.
- Generate Markdown reports programmatically using standard string templating.

## Summary

- **AI Berkshire is a Python‑only repository** – every tool, script, and automation workflow is implemented in Python.
- **Core logic** resides in [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py) and [`tools/stock_screener.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/stock_screener.py), utilizing pure Python functions for quantitative checks.
- **Data acquisition** relies on async Python patterns in [`tools/xueqiu_scraper.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/xueqiu_scraper.py).
- **Integration scripts** convert Markdown skills into Codex packages using Python file I/O and JSON serialization.

## Frequently Asked Questions

### Is AI Berkshire written in any language other than Python?

No. The repository contains exclusively Python source files (`.py`) and Markdown documentation (`.md`). All executables, including the web scrapers and financial validators, are invoked via the Python interpreter.

### Which Python version does AI Berkshire target?

While the repository does not explicitly pin a Python version in the provided analysis, the use of `async/await` syntax and type hints suggests **Python 3.8+** compatibility, which is standard for modern data‑science projects using Playwright and Pandas.

### Can I run AI Berkshire without installing Python?

No. You must have a Python 3 environment to execute the scripts in `tools/` and `scripts/`. The README (located at [[`README.md`](https://github.com/xbtlin/ai-berkshire/blob/main/README.md)](https://github.com/xbtlin/ai-berkshire/blob/main/README.md)) typically provides installation instructions for the required dependencies.

### Does AI Berkshire use Jupyter Notebooks for analysis?

Based on the source file structure, the project favors **plain Python scripts** over Jupyter Notebooks. This choice supports version control and automation workflows, allowing the code to run headlessly in CI/CD pipelines or scheduled cron jobs.