Parser for Swiss federal law documents. Downloads official AkomaNtoso XML from fedlex.admin.ch and extracts structured articles with full heading context, ready for LLM pipelines.
| Key | Name | Articles |
|---|---|---|
OR |
Obligationenrecht (Code of Obligations) | ~1600 |
ZGB |
Zivilgesetzbuch (Civil Code) | ~472 |
BV |
Bundesverfassung (Federal Constitution) | ~232 |
python3 -m venv .swisslaw-llm
source .swisslaw-llm/bin/activate
pip install -r requirements.txtfrom law_repo.law_repo import LawRepo
from parser.article_parser import parse_articles
xml = LawRepo.get_xml("OR") # downloads & caches to raw/
articles = parse_articles(xml)
art = articles[0]
art.article_number # "1"
art.paragraphs # ["Zum Abschlusse eines Vertrages ...", ...]
art.context # ["Erste Abteilung: Allgemeine Bestimmungen", ...]Each Article contains:
- article_number — e.g.
"1","17a" - paragraphs — list of paragraph texts (including list items and authorial notes for repealed articles)
- context — heading hierarchy from outermost to innermost (part, title, chapter, section, ...)
python -m unittest discover -s test -p "test*.py" -vmodel/ Article dataclass
parser/ XML parser (AkomaNtoso 3.0)
law_repo/ Download & cache layer
test/ Unit tests + fixtures
raw/ Cached XML files (gitignored)