# environment

URL: /kida/api/environment/
Section: environment
Description: Kida Environment — central configuration and template management.

The Environment is the central hub for all template operations:

- **Configuration**: Delimiters, autoescape, strict mode
- **Loading**: File system, dict, or custom loaders
- **Caching**: LRU caches for templates and fragments
- **Extensibility**: Custom filters, tests, and global variables

Thread-Safety:
Environment is designed for concurrent access:
- Copy-on-write for `add_filter()`, `add_test()`, `add_global()`
- Lock-free LRU cache with atomic pointer swaps
- Immutable configuration after construction

Public API:
- `Environment`: Central configuration class
- `FileSystemLoader`: Load templates from directories
- `DictLoader`: Load templates from memory (testing)
- `FilterRegistry`: Dict-like interface for filters/tests
- `Loader`, `Filter`, `Test`: Protocol definitions

Exceptions:
- `TemplateError`: Base exception for all template errors
- `TemplateNotFoundError`: Template not found by loader
- `TemplateSyntaxError`: Parse-time syntax error
- `UndefinedError`: Undefined variable in strict mode

Example:
    >>> from kida import Environment, FileSystemLoader
    >>> env = Environment(
    ...     loader=FileSystemLoader("templates/"),
    ...     autoescape=True,
    ...     strict=True,
    ... )
    >>> env.add_filter("upper", str.upper)
    >>> template = env.get_template("page.html")
    >>> template.render(title="Hello")

---

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

Open LLM text
(/kida/api/environment/index.txt)

Share with AI

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

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

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

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

Module

#
`environment`

Kida Environment — central configuration and template management.

The Environment is the central hub for all template operations:

- Configuration: Delimiters, autoescape, strict mode

- Loading: File system, dict, or custom loaders

- Caching: LRU caches for templates and fragments

- Extensibility: Custom filters, tests, and global variables

Thread-Safety:

Environment is designed for concurrent access:

- Copy-on-write for`add_filter()`, `add_test()`, `add_global()`

- Lock-free LRU cache with atomic pointer swaps

- Immutable configuration after construction

Public API:

- `Environment`: Central configuration class

- `FileSystemLoader`: Load templates from directories

- `DictLoader`: Load templates from memory (testing)

- `FilterRegistry`: Dict-like interface for filters/tests

- `Loader`, `Filter`, `Test`: Protocol definitions

Exceptions:

- `TemplateError`: Base exception for all template errors

- `TemplateNotFoundError`: Template not found by loader

- `TemplateSyntaxError`: Parse-time syntax error

- `UndefinedError`: Undefined variable in strict mode

Example:

```
>>> from kida import Environment, FileSystemLoader
>>> env = Environment(
...     loader=FileSystemLoader("templates/"),
...     autoescape=True,
...     strict=True,
... )
>>> env.add_filter("upper", str.upper)
>>> template = env.get_template("page.html")
>>> template.render(title="Hello")
```
