Python library for the Brainfile task management protocol
Project description
brainfile
The Python engine behind Brainfile.
This library provides the core logic for managing Brainfile v2 projects: reading/writing task files, managing contracts, validating boards, and querying task state. It is the Python equivalent of @brainfile/core with full API parity.
Used by Cecli and other tools that need programmatic access to Brainfile workspaces.
Installation
pip install brainfile
Or with uv:
uv add brainfile
v2 Architecture
Brainfile v2 uses a directory-based structure. Each task is its own markdown file.
.brainfile/
├── brainfile.md # Board config (columns, types, rules)
├── board/ # Active tasks
│ ├── task-1.md
│ └── task-2.md
└── logs/ # Completed tasks (history)
└── task-0.md
Quick Start
from brainfile import ensureV2Dirs, addTaskFile, readTasksDir, completeTaskFile
# Initialize workspace
dirs = ensureV2Dirs(".brainfile/brainfile.md")
# Add a task
result = addTaskFile(
dirs.boardDir,
{"title": "Implement auth", "column": "in-progress", "priority": "high"},
body="## Description\nAdd JWT authentication to the API.\n",
)
print(result["task"].id) # "task-1"
# List all active tasks
for doc in readTasksDir(dirs.boardDir):
t = doc.task
print(f"{t.id}: {t.title} [{t.column}]")
# Complete a task (moves to logs/)
completeTaskFile(result["filePath"], dirs.logsDir)
Task File Operations
Read and write individual task files.
from brainfile import readTaskFile, writeTaskFile, findV2Task, getV2Dirs
# Read a single task
doc = readTaskFile(".brainfile/board/task-1.md")
print(doc.task.title)
print(doc.body) # Markdown content below frontmatter
# Find a task across board and logs
dirs = getV2Dirs(".brainfile/brainfile.md")
result = findV2Task(dirs, "task-1", searchLogs=True)
if result:
print(result["doc"].task.title, "in", "logs" if result["isLog"] else "board")
Contracts
Tasks can carry formal contracts for AI agent coordination: deliverables, validation commands, constraints, and feedback for rework.
from brainfile import readTaskFile, writeTaskFile, Contract, Deliverable
doc = readTaskFile(".brainfile/board/task-1.md")
task = doc.task
# Attach a contract
task.contract = Contract(
status="ready",
deliverables=[
Deliverable(path="src/auth.py", description="JWT auth module"),
Deliverable(path="tests/test_auth.py", description="Unit tests"),
],
validation={"commands": ["pytest tests/test_auth.py"]},
constraints=["Use PyJWT library", "Token expiry must be configurable"],
)
writeTaskFile(".brainfile/board/task-1.md", task, doc.body)
Contract Lifecycle
ready → in_progress → delivered → done
│ │
└─────────→ failed ←────┘
(add feedback, reset to ready)
from brainfile import setTaskContractStatus
# Agent picks up work
setTaskContractStatus(board, "task-1", "in_progress")
# Agent delivers
setTaskContractStatus(board, "task-1", "delivered")
# PM validates
setTaskContractStatus(board, "task-1", "done")
Board Operations (V1)
Immutable operations on in-memory board objects. Useful for single-file workflows or building custom tools.
from brainfile import Brainfile, add_task, move_task, patch_task, TaskInput, TaskPatch
# Parse a brainfile
result = Brainfile.parse(markdown_content)
board = result.board
# Add a task
result = add_task(board, "todo", TaskInput(title="New task", priority="high"))
board = result.board
# Move between columns
result = move_task(board, "task-1", "todo", "in-progress")
# Patch fields
result = patch_task(board, "task-1", TaskPatch(tags=["urgent"], assignee="codex"))
# Serialize back
output = Brainfile.serialize(board)
Queries
from brainfile import (
find_task_by_id,
get_all_tasks,
get_tasks_by_tag,
get_tasks_by_assignee,
search_tasks,
)
task_info = find_task_by_id(board, "task-1")
urgent = get_tasks_by_tag(board, "urgent")
results = search_tasks(board, "auth")
Validation and Linting
from brainfile import BrainfileValidator, BrainfileLinter, LintOptions
# Validate board structure
result = BrainfileValidator.validate(board)
for error in result.errors:
print(f"{error.path}: {error.message}")
# Lint with auto-fix
result = BrainfileLinter.lint(content, LintOptions(auto_fix=True))
File Discovery
from brainfile import discover, find_nearest_brainfile, isV2
# Find brainfiles in a project
result = discover("/path/to/project")
for f in result.files:
print(f"{f.name}: {f.item_count} tasks")
# Walk up to find nearest brainfile
path = find_nearest_brainfile()
# Check if a workspace is v2
if isV2(".brainfile/brainfile.md"):
print("V2 workspace detected")
Ecosystem
| Package | Description |
|---|---|
| brainfile (Python) | This library |
| @brainfile/core | TypeScript core library |
| @brainfile/cli | CLI with TUI and MCP server |
| Protocol | Specification and JSON Schema |
Development
git clone https://github.com/brainfile/py.git
cd py
uv sync --dev
uv run pytest
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brainfile-0.1.0.tar.gz.
File metadata
- Download URL: brainfile-0.1.0.tar.gz
- Upload date:
- Size: 113.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db4df248dd83ecad12eaeb44cd70a3335315e6f2a8db4bf9fe21f3484e1fa6c7
|
|
| MD5 |
4233fbea6996da20f8dafaaca86a3ba4
|
|
| BLAKE2b-256 |
d8c240d3566cf2da1d655fe8508a3a7c269725bdbe5ec42ce81bfbe50de153ba
|
Provenance
The following attestation bundles were made for brainfile-0.1.0.tar.gz:
Publisher:
publish.yml on brainfile/py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainfile-0.1.0.tar.gz -
Subject digest:
db4df248dd83ecad12eaeb44cd70a3335315e6f2a8db4bf9fe21f3484e1fa6c7 - Sigstore transparency entry: 1005498497
- Sigstore integration time:
-
Permalink:
brainfile/py@026db5de5fa1c702655aa02513170890f2bd7bc4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/brainfile
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@026db5de5fa1c702655aa02513170890f2bd7bc4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file brainfile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: brainfile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 60.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
023a2e687847bc5fddb4e3b0ee252fbfa8142e876a90a2492cc80564c1f5b095
|
|
| MD5 |
89a17c7a47d25406b7f1c9436391d5fc
|
|
| BLAKE2b-256 |
ed42136974cfb15f152b79dd60724d759c9e802fac9cea6f10ea6414f3d200c7
|
Provenance
The following attestation bundles were made for brainfile-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on brainfile/py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainfile-0.1.0-py3-none-any.whl -
Subject digest:
023a2e687847bc5fddb4e3b0ee252fbfa8142e876a90a2492cc80564c1f5b095 - Sigstore transparency entry: 1005498499
- Sigstore integration time:
-
Permalink:
brainfile/py@026db5de5fa1c702655aa02513170890f2bd7bc4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/brainfile
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@026db5de5fa1c702655aa02513170890f2bd7bc4 -
Trigger Event:
release
-
Statement type: