Builder pattern
Each facade exposes a fluent builder that composes a request by method
chaining, terminated by .execute().
Example: Code.search()
Section titled “Example: Code.search()”results = ( code.search() .in_code(NomCode.CC) .article_number("1382") .with_formatter() .execute())Builders return Self to allow chaining; they take the
LegifranceClient as the
first argument.
Existing builders
Section titled “Existing builders”| Builder | Entry point | Typical methods |
|---|---|---|
CodeSearchBuilder | Code.search() | .in_code(), .text(), .article_number(), .at_date(), .with_formatter(), .paginate(), .execute() |
CodeConsultFetcher | Code.fetch_code(id) | .include_abrogated(), .section(), .at(date) |
ArticleFetcher | Code.fetch_article(id) | .at(date) |
Why a builder instead of a big dataclass?
Section titled “Why a builder instead of a big dataclass?”- Readability: the request reads like a sentence.
- Progressivity: each step is optional and composable.
- Typing: each method narrows the permissible parameters (e.g.
in_codeaccepts aNomCode, not astr). - Discoverability: autocompletion guides the user towards valid methods.