# config

URL: /patitas/api/config/
Section: api
Description: ContextVar-based parse configuration for Patitas.

Provides thread-local configuration using Python's ContextVars (PEP 567).
Config is set once per Markdown instance, read by all parsers in the context.

Thread Safety:
    ContextVars are thread-local by design. Each thread has independent storage,
    so no locks are needed and race conditions are impossible.

Usage:
    # In Markdown class
    md = Markdown(plugins=["table", "math"])
    html = md("# Hello")  # Sets config internally via ContextVar

    # Direct parser usage (advanced)
    from patitas.config import set_parse_config, reset_parse_config, ParseConfig

    set_parse_config(ParseConfig(tables_enabled=True))
    try:
        parser = Parser(source)
        result = parser.parse()
    finally:
        reset_parse_config()

    # Or use the context manager
    with parse_config_context(ParseConfig(tables_enabled=True)):
        parser = Parser(source)
        result = parser.parse()

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/config/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fconfig%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fconfig%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fconfig%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fconfig%2Findex.txt)

Module

#
`config`

ContextVar-based parse configuration for Patitas.

Provides thread-local configuration using Python's ContextVars (PEP 567).
Config is set once per Markdown instance, read by all parsers in the context.

Thread Safety:

```
ContextVars are thread-local by design. Each thread has independent storage,
so no locks are needed and race conditions are impossible.
```

Usage:

```
# In Markdown class
md = Markdown(plugins=["table", "math"])
html = md("# Hello")  # Sets config internally via ContextVar

# Direct parser usage (advanced)
from patitas.config import set_parse_config, reset_parse_config, ParseConfig

set_parse_config(ParseConfig(tables_enabled=True))
try:
    parser = Parser(source)
    result = parser.parse()
finally:
    reset_parse_config()

# Or use the context manager
with parse_config_context(ParseConfig(tables_enabled=True)):
    parser = Parser(source)
    result = parser.parse()
```

1Class4Functions

## Classes

`ParseConfig`

11

▼

Immutable parse configuration.

Set once per Markdown instance, read by all parsers in the context.…

Immutable parse configuration.

Set once per Markdown instance, read by all parsers in the context.
Frozen dataclass ensures thread-safety (immutable after creation).

Note: source_file is intentionally excluded—it's per-call state,
not configuration. It remains on the Parser instance.

#### Attributes

Name
Type
Description

`tables_enabled`

`bool`

Enable GFM table parsing

`strikethrough_enabled`

`bool`

Enable strikethrough syntax

`task_lists_enabled`

`bool`

Enable - [ ] task list items

`footnotes_enabled`

`bool`

Enable [^ref] footnote references

`math_enabled`

`bool`

Enable $inline$ and $$block$$ math

`autolinks_enabled`

`bool`

Enable automatic URL linking

`directive_registry`

`DirectiveRegistry (/patitas/api/directives/registry/#DirectiveRegistry) | None`

Registry for directive handlers

`strict_contracts`

`bool`

Raise errors on directive contract violations

`text_transformer`

`Callable[[str], str] | None`

Optional callback to transform plain text lines

`max_nesting_depth`

`int`

Maximum nesting depth, bounding BOTH deep block-container nesting (block quotes, lists, directives) AND deep inline emphasis/strong nesting. Adversarially deep input of either kind raises a catchable`ParseError` instead of crashing the interpreter with an uncaught `RecursionError`. Real documents nest only a handful of levels; the default (100) is far above any legitimate content.

#### Methods

`from_dict`

1

`ParseConfig (/patitas/api/config/#ParseConfig)`

▼

Create ParseConfig from dictionary.

Useful for framework integration where con…

classmethod

`def from_dict(cls, config_dict: dict) -> ParseConfig`

Create ParseConfig from dictionary.

Useful for framework integration where config may come from external
sources (e.g., Bengal's own ParseConfig, YAML files, etc.).

Only includes keys that are valid ParseConfig fields; unknown keys
are silently ignored.

##### Parameters

Name
Type
Description

`config_dict`
`—`

Dictionary with config values. Keys should match ParseConfig attribute names.

##### Returns

`ParseConfig (/patitas/api/config/#ParseConfig)`

New ParseConfig instance with values from dict.

## Functions

`get_parse_config`

0

`ParseConfig (/patitas/api/config/#ParseConfig)`

▼

Get current parse configuration (thread-local).

**Thread Safety:**
ContextVars…

`def get_parse_config() -> ParseConfig`

Get current parse configuration (thread-local).

Thread Safety:
ContextVars are thread-local by design. Safe to call from any thread.

##### Returns

`ParseConfig (/patitas/api/config/#ParseConfig)`

`set_parse_config`

1

`None`

▼

Set parse configuration for current context.

**Thread Safety:**
Only affects t…

`def set_parse_config(config: ParseConfig) -> None`

Set parse configuration for current context.

Thread Safety:
Only affects the current thread's context. Other threads are unaffected.

##### Parameters

Name
Type
Description

`config`
`ParseConfig (/patitas/api/config/#ParseConfig)`

ParseConfig instance to use for this context.

`reset_parse_config`

0

`None`

▼

Reset to default configuration.

Reuses the module-level _DEFAULT_CONFIG single…

`def reset_parse_config() -> None`

Reset to default configuration.

Reuses the module-level _DEFAULT_CONFIG singleton, avoiding allocation.

Thread Safety:

```
Only affects the current thread's context. Other threads are unaffected.
```

`parse_config_context`

1

`Iterator[None]`

▼

Context manager for temporary config changes.

Useful for tests and isolated pa…

`def parse_config_context(config: ParseConfig) -> Iterator[None]`

Context manager for temporary config changes.

Useful for tests and isolated parsing operations.

Thread Safety:
Only affects the current thread's context. Properly restores previous
config even if an exception is raised.

##### Parameters

Name
Type
Description

`config`
`ParseConfig (/patitas/api/config/#ParseConfig)`

ParseConfig to use within the context.

##### Returns

`Iterator[None]`
