API Reference¶
This part of the documentation covers all the interfaces of Platzky.
Engine¶
Flask application engine with notification support.
- class platzky.engine.Engine(config, db, import_name)[source]¶
Flask subclass composing database, plugins, notifications, and health checks.
- notify(message, topic='general', attachments=(), receiver='')[source]¶
Send a notification to all registered notifiers.
- Parameters:
message (str) – The notification message text.
topic (Literal['security', 'content', 'general']) – Notification topic for routing (default
"general").attachments (Sequence[AttachmentProtocol]) – Attachments to include; empty sequence if none.
receiver (str) – Target recipient identifier; empty string means broadcast.
- Return type:
None
- add_notifier(notifier)[source]¶
Register a simple notifier (message only).
Deprecated: implement NotifierPluginBase instead.
Deprecated since version 1.5.0: This will be removed in 2.0.0. Use NotifierPluginBase subclass instead.
- Parameters:
notifier (Notifier)
- Return type:
None
- add_notifier_with_attachments(notifier)[source]¶
Register a notifier that supports attachments.
Deprecated: implement NotifierPluginBase instead.
Deprecated since version 1.5.0: This will be removed in 2.0.0. Use NotifierPluginBase subclass instead.
- Parameters:
notifier (NotifierWithAttachments)
- Return type:
None
- transform_content(content, content_type)[source]¶
Apply all registered content-filter plugins for the given content type.
Checks plugin’s declared
accepted_content_typesfirst, then the engine-enforced allowlist set viaset_content_transformer_allowlist. Transformers chain their output, so a failing transformer aborts the chain rather than silently passing through partial output to the next stage.
- set_content_transformer_allowlist(plugin, allowed_types)[source]¶
Register engine-enforced content-type allowlist for a content-transformer plugin.
Empty frozenset blocks all content types. Plugin absent from the allowlist is also blocked. Called by the plugin loader; not intended to be called from plugin code.
- register_plugin_capabilities(instance, plugin_name)[source]¶
Register a plugin instance under all matching capability keys.
Each recognised capability base class becomes a key in
self.pluginsso the engine can look up e.g. all NotifierPluginBase plugins without knowing concrete types. Plugins that don’t match any capability are stored under PluginBase.- Parameters:
instance (PluginBase)
plugin_name (str)
- Return type:
None
- register_plugin_locale(plugin_instance, plugin_name)[source]¶
Register plugin’s locale directory with Babel if it exists.
- Parameters:
plugin_instance (PluginBase)
plugin_name (str)
- Return type:
None
- load_plugin(plugin_class, plugin_config, plugin_name, allowed_topics=frozenset({}), allowed_content_types=frozenset({}))[source]¶
Instantiate and register a class-based plugin. Returns the (possibly replaced) engine.
- Parameters:
plugin_class (type[PluginBase]) – The plugin class to instantiate.
plugin_config (dict[str, Any]) – Configuration dict passed to the plugin constructor.
plugin_name (str) – Human-readable name used in log messages.
allowed_topics (frozenset[Literal['security', 'content', 'general']]) – Topic allowlist for notifier plugins. Empty frozenset blocks all topics; a non-empty frozenset restricts to those topics.
allowed_content_types (frozenset[Literal['post', 'page', 'comment']]) – Content-type allowlist for transformer plugins. Empty frozenset blocks all types; a non-empty frozenset restricts.
- Returns:
The (possibly replaced) engine after loading the plugin.
- Return type:
- set_notifier_allowlist(plugin, allowed_topics)[source]¶
Register engine-enforced topic allowlist for a notifier.
Empty frozenset blocks all topics. Plugin absent from the allowlist is also blocked. Called by the plugin loader; not accessible to plugin code.
- add_cms_module(module)[source]¶
Add a CMS module to the modules list.
- Parameters:
module (CmsModule)
- Return type:
None
- add_dynamic_body(body)[source]¶
Append HTML to the dynamic body section rendered in templates.
- Parameters:
body (str)
- Return type:
None
- add_dynamic_head(head)[source]¶
Append HTML to the dynamic head section rendered in templates.
- Parameters:
head (str)
- Return type:
None
- get_locale()[source]¶
Return the current locale based on session or browser preferences.
- Return type:
Configuration¶
Configuration module for Platzky application.
This module defines all configuration models and parsing logic for the application.
- class platzky.config.LanguageConfig(*, name, flag, country, domain=None)[source]¶
Configuration for a single language.
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- platzky.config.languages_dict(languages)[source]¶
Convert Languages configuration to a mapping dictionary.
Excludes None values to align with type signature.
- class platzky.config.TelemetryConfig(*, enabled=False, endpoint=None, console_export=False, timeout=10, deployment_environment=None, service_instance_id=None, flush_on_request=True, flush_timeout_ms=5000, instrument_logging=True)[source]¶
OpenTelemetry configuration for application tracing.
- Parameters:
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.config.AttachmentConfig(*, allowed_mime_types=frozenset({'application/gzip', 'application/msword', 'application/pdf', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/x-tar', 'application/zip', 'audio/mpeg', 'audio/ogg', 'audio/wav', 'image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/webp', 'video/mp4', 'video/ogg', 'video/webm'}), validate_content=True, allow_unrecognized_content=False, max_size=10485760, blocked_extensions=frozenset({'app', 'appimage', 'bash', 'bat', 'class', 'cmd', 'com', 'cpl', 'csh', 'deb', 'dll', 'dmg', 'exe', 'gadget', 'hta', 'inf', 'jar', 'js', 'jse', 'ksh', 'lnk', 'msc', 'msi', 'php', 'php3', 'php4', 'php5', 'phtml', 'pif', 'pkg', 'pl', 'ps1', 'psd1', 'psm1', 'py', 'pyc', 'pyo', 'pyw', 'rb', 'reg', 'rpm', 'scf', 'scr', 'sh', 'url', 'vbe', 'vbs', 'war', 'ws', 'wsc', 'wsf', 'wsh', 'zsh'}), allowed_extensions=frozenset({'bmp', 'doc', 'docx', 'gif', 'gz', 'jpeg', 'jpg', 'mp3', 'mp4', 'ogg', 'pdf', 'png', 'ppt', 'pptx', 'tar', 'tiff', 'wav', 'webm', 'webp', 'xls', 'xlsx', 'zip'}))[source]¶
Configuration for attachment handling.
- Parameters:
- blocked_extensions¶
File extensions that are PERMANENTLY blocked (executable and script formats). These cannot be overridden via allowed_extensions.
- allowed_extensions¶
File extensions to allow. Defaults to common safe formats (images, documents, archives, audio/video). Set to None to block all. Note: blocked_extensions takes precedence over allowed_extensions. Files without extensions are always blocked when allowed_extensions is set.
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.config.Config(*, APP_NAME, SECRET_KEY, DB, USE_WWW=True, SEO_PREFIX='/', BLOG_PREFIX='/', LANGUAGES=<factory>, TRANSLATION_DIRECTORIES=<factory>, DEBUG=False, TESTING=False, FEATURE_FLAGS=<factory>, TELEMETRY=<factory>, ATTACHMENT=<factory>)[source]¶
Main application configuration.
- Parameters:
APP_NAME (str)
SECRET_KEY (str)
DB (DBConfig)
USE_WWW (bool)
SEO_PREFIX (str)
BLOG_PREFIX (str)
LANGUAGES (dict[str, LanguageConfig])
DEBUG (bool)
TESTING (bool)
FEATURE_FLAGS (FeatureFlagSet)
TELEMETRY (TelemetryConfig)
ATTACHMENT (AttachmentConfig)
- db¶
Database configuration
- Type:
- languages¶
Supported languages configuration
- Type:
- feature_flags¶
Feature flag configuration
- Type:
platzky.feature_flags_wrapper.FeatureFlagSet
- telemetry¶
OpenTelemetry configuration
- attachment¶
Attachment handling configuration
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- languages: dict[str, LanguageConfig]¶
- feature_flags: FeatureFlagSet¶
- telemetry: TelemetryConfig¶
- attachment: AttachmentConfig¶
- classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None, by_alias=None, by_name=None, extra=None)[source]¶
Validate and construct Config from dictionary.
Parses the raw FEATURE_FLAGS dict into a
FeatureFlagSet.- Parameters:
strict (bool | None) – Enable strict validation
from_attributes (bool | None) – Populate from object attributes
context (dict[str, Any] | None) – Additional validation context
by_alias (bool | None) – Whether to use field aliases
by_name (bool | None) – Whether to use field names
extra (Literal['allow', 'ignore', 'forbid'] | None) – Extra fields handling
- Returns:
Validated Config instance
- Return type:
- classmethod parse_yaml(path)[source]¶
Parse configuration from YAML file.
- Parameters:
path (str) – Path to YAML configuration file
- Returns:
Validated Config instance
- Raises:
SystemExit – If config file is not found
- Return type:
Database¶
Abstract base classes for database implementations.
- class platzky.db.db.DB[source]¶
Abstract base class for all database implementations.
- extend(function_name, function)[source]¶
Add a function to the DB object. The function must take the DB object as first parameter.
Parameters: function_name (str): The name of the function to add. function (Callable): The function to add to the DB object.
- abstract get_app_description(lang)[source]¶
Retrieve the application description for a specific language.
Retrieve menu items for a specific language.
- abstract get_primary_color()[source]¶
Retrieve the primary color for the application theme.
- Return type:
- abstract get_secondary_color()[source]¶
Retrieve the secondary color for the application theme.
- Return type:
Models¶
Pydantic models for blog posts, pages, comments, and CMS modules.
- class platzky.models.CmsModule(*, name, description, template, slug)[source]¶
Represents a CMS module with basic metadata.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.models.CmsModuleGroup(*, name, description, template, slug, modules=[])[source]¶
Represents a group of CMS modules, inheriting module properties.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.models.Image(*, url='', alternateText='')[source]¶
Represents an image with URL and alternate text.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.models.MenuItem(*, name, url)[source]¶
Represents a navigation menu item.
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.models.Comment(*, author, comment, date)[source]¶
Represents a user comment on a blog post or page.
- Parameters:
author (str)
comment (str)
date (Annotated[datetime, BeforeValidator(func=~platzky.models._parse_date_string, json_schema_input_type=PydanticUndefined)])
- date¶
Datetime when the comment was posted (timezone-aware recommended)
- Type:
- date: Annotated[datetime, BeforeValidator(func=_parse_date_string, json_schema_input_type=PydanticUndefined)]¶
- property time_delta: str¶
Calculate human-readable time since the comment was posted.
Uses timezone-aware datetimes to ensure accurate time delta calculations.
- Returns:
Human-friendly time description (e.g., “2 hours ago”, “3 days ago”)
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class platzky.models.Post(*, author, slug, title, contentInMarkdown, excerpt, coverImage=<factory>, language='en', comments=<factory>, tags=<factory>, date=None)[source]¶
Represents a blog post with metadata, content, and comments.
- Parameters:
- coverImage¶
Cover image for the post
- Type:
- comments¶
Optional list of comments on this post
- Type:
- date¶
Optional datetime when the post was published (timezone-aware recommended)
- Type:
datetime.datetime | None
- date: Annotated[datetime, BeforeValidator(func=_parse_date_string, json_schema_input_type=PydanticUndefined)] | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].