shab-parser
Typed Python client for the Swiss Official Gazette of Commerce (SHAB/SOGC/FUSC).
Fetches publications from the Amtsblattportal public API, parses the XML into dataclasses, and classifies each publication into structured events (incorporation, seat move, capital increase, deletion, and others).
Built and maintained by Prospex, a Swiss B2B sales intelligence platform.
Install
pip install shab-parser
To use the HTTP client (for fetching from the live API):
pip install shab-parser[http]
Quick start
Parse XML you already have
from shab_parser import parse_xml
with open("publication.xml", "rb") as f:
pub = parse_xml(f.read())
print(pub.company_name) # "Alpenblick Handel AG"
print(pub.uid) # "CHE-123.456.789"
print(pub.canton) # "ZH"
for event in pub.events:
print(event.event_type, event.effective_date, event.payload)
Fetch and parse from the API
from datetime import date
from shab_parser.client import ShabClient
from shab_parser import parse
with ShabClient() as client:
refs = client.discover(date(2026, 6, 15), date(2026, 6, 15))
for ref in refs[:5]:
raw = client.fetch(ref)
pub = parse(raw)
print(f"{pub.company_name}: {[e.event_type.value for e in pub.events]}")
The client rate-limits itself to one request per second and retries transient failures with exponential backoff.
Event types
The parser classifies each publication into one or more of these events, based on the machine-readable XML fields (not free text):
| Event | Sub-rubric | Trigger |
|---|---|---|
INCORPORATION |
HR01 | <registration>true</registration> |
SEAT_MOVED |
HR02 | Different seat in commonsNew vs. commonsActual |
ADDRESS_CHANGED |
HR02 | <addressChanged>true</addressChanged> |
NAME_CHANGED |
HR02 | Different company name in commonsNew vs. commonsActual |
CAPITAL_INCREASED |
HR02 | Structured nominal comparison, phrase fallback |
LIQUIDATION |
any | Dissolution flags or "in Liquidation" added to name |
DELETED |
HR03 | <delete> block with deletion date |
Data model
parse() and parse_xml() return a Publication dataclass:
@dataclass(frozen=True)
class Publication:
external_id: str
publication_date: date
language: str # "de", "fr", or "it"
source_url: str
company_name: str
raw_text: str
sub_rubric: str # "HR01", "HR02", or "HR03"
effective_date: date | None
canton: str | None
uid: str | None # CHE-xxx.xxx.xxx
legal_form_code: str | None
publication_state: str # "PUBLISHED" or "CANCELLED"
events: list[Event]
company_new: Company | None
company_actual: Company | None
capital_new: float | None
capital_actual: float | None
API reference
shab_parser.parse(raw: RawResponse) -> Publication
Parse a RawResponse (as returned by ShabClient.fetch()) into a Publication.
shab_parser.parse_xml(xml_bytes, *, source_url="", ref_state=None) -> Publication
Parse raw XML bytes directly. Use this when you already have the XML and don't need the HTTP client.
shab_parser.client.ShabClient
HTTP client for the Amtsblattportal API. Requires the http extra.
discover(start, end)lists all HR publications in a date range. Queries bothPUBLISHEDandCANCELLEDstates, deduplicating by external ID.fetch(ref)downloads one publication's full XML.
shab_parser.client.parse_bulk_export(xml_bytes) -> (list[PublicationRef], int)
Parse a bulk-export list page into publication references and a total count. Useful if you handle pagination yourself.
Background
SHAB (Schweizerisches Handelsamtsblatt) is the official gazette where Swiss commercial
register entries are published. Every new company, every seat change, every capital
increase, every deletion passes through it. The same publication appears in German, French,
and Italian, each under a different namespace (HR01:, HR02:, HR03:), but with
identical XML structure.
This library handles the namespace differences transparently using ElementPath's {*}
wildcard, so you get the same parsed output regardless of language.
License
MIT
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 shab_parser-0.1.0.tar.gz.
File metadata
- Download URL: shab_parser-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a9d3b3c29985328b12b079792ff76c3b1426024f0c5ca763289b947b6e325f
|
|
| MD5 |
63345cb4c2f88396003cabc6552a04b6
|
|
| BLAKE2b-256 |
93c66ec321518168195bd03c9e3f1ab00df282cde55a0a699d11cab5f5023db9
|
File details
Details for the file shab_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shab_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04a7e0b16fce3d522718444400f7e51c0334d5058011536ca3bbfdd395dec22c
|
|
| MD5 |
8e793d90989d16459fda239d03ceae6c
|
|
| BLAKE2b-256 |
54a64f758a3ae3071b2989fd2eb4ccd52a079c4b7e4d49510c349b9734e0bc5d
|