Skip to main content

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.

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.

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:

config.read_config(Settings).base_url

Metadata

Release files for flasklet 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flasklet 1.2.1
File Size Uploaded
flasklet-1.2.1.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flasklet 1.2.1
File Interpreter ABI Platform
flasklet-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / flasklet-1.2.1.tar.gz

Download URL flasklet-1.2.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0f5c3ef17228e3dbb9fce7f5736f082e395cee41f959a5bc84df042e25d68563
BLAKE2b-256 checksum
How to use checksums
39a4fe300ed025f548e10ce578841f53032ce8cf818a5d4eed709e1320b338a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / flasklet-1.2.1-py3-none-any.whl

Download URL flasklet-1.2.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
453561a2276e24a4711fa01ee2be2152a8b1fedf0e064c452deb8a4cc478df80
BLAKE2b-256 checksum
How to use checksums
51594f1be44303f64cd3876106baed562a73a7bd1998c542ff7db888f26e54b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

3.0.1

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.0

2 release files

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.0.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page