Metadata-Version: 2.3
Name: flasklet
Version: 1.2.1
Summary: A few nice things for Flask
Author: Marcel Kröker
Author-email: Marcel Kröker <kroeker.marcel@gmail.com>
License: MIT License
         
         Copyright (c) 2026 mkrd
         
         Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
         associated documentation files (the "Software"), to deal in the Software without restriction, including
         without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
         following conditions:
         
         The above copyright notice and this permission notice shall be included in all copies or substantial
         portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
         LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
         EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
         IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
         USE OR OTHER DEALINGS IN THE SOFTWARE.
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Framework :: Flask
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: flask>=3.1
Requires-Dist: jinja2>=3.1
Requires-Dist: markupsafe>=2.1
Requires-Python: >=3.13, <3.15
Description-Content-Type: text/markdown

# flasklet

A few nice things for Flask: typed flash messages, convention-based blueprint
auto-discovery, route auto-importing, and helpers for rendering partials, blocks,
and macros from Python.

## Typed configuration

`flasklet.config` gives Flask apps a typed, environment-backed settings object
instead of untyped `app.config` dict lookups.

```python
from flasklet import config


class Settings(config.Config, prefix="BOXMINDER_"):
	base_url: str = config.from_env(default="/")
	flush_interval_seconds: int = config.from_env(default=60)


def create_app() -> Flask:
	app = Flask(__name__)
	settings = config.load(Settings)
	config.init_app(app, settings, flask_keys={"APPLICATION_ROOT": "base_url"})
	return app
```

A field's variable name defaults to the field name uppercased, prefixed with
the class-level `prefix` (here `BOXMINDER_BASE_URL` and
`BOXMINDER_FLUSH_INTERVAL_SECONDS`). Pass a name to `from_env` to override it.
The prefix is inherited by subclasses. `load(Settings, prefix=...)` prepends a further prefix at load
time.

`load` reads the environment when called (inside the app factory, not at
import time) and converts values to the field's declared type: `str`, `int`,
`float`, `bool`, `Path`, `Optional[T]`, `list[T]`, and `NewType` wrappers.
A `bool` accepts only the exact strings `true` and `false`; a list is split on
commas, with an empty variable meaning the empty list. A required field with a
missing variable, or a value that cannot be converted, raises with the
offending variable named.

Settings derived from other settings are declared with `derived`. They are
computed once when the object is built, in declaration order, so a derived
field may read earlier ones. They are not constructor arguments.

```python
class Settings(config.Config, prefix="BOXMINDER_"):
	data_dir: Path | None = config.from_env(default=None)
	base_dir: Path = config.derived(lambda s: (s.data_dir or PROJECT_ROOT).resolve())
	db_uri: str = config.derived(lambda s: f"sqlite:///{s.base_dir / 'db.sqlite3'}")
```

Request-time access is typed through the generic `read_config`, passing the
settings class:

```python
config.read_config(Settings).base_url
```
