Settings
plateforme.core.settings
This module provides utilities for managing settings within the Plateforme framework.
LoggingFormatterSettings
module-attribute
LoggingFormatterSettings = Union[
LoggingCustomFormatterSettings,
LoggingDefaultFormatterSettings,
LoggingJsonFormatterSettings,
LoggingSimpleFormatterSettings,
]
Logging formatter settings.
LoggingHandlerSettings
module-attribute
LoggingHandlerSettings = Union[
LoggingCustomHandlerSettings,
LoggingFileHandlerSettings,
LoggingStreamHandlerSettings,
]
Logging handler settings.
ADJECTIVES
module-attribute
ADJECTIVES = (
"Apex",
"Arc",
"Astro",
"Atomic",
"Black",
"Blue",
"Call",
"Cold",
"Core",
"Cyber",
"Dark",
"Data",
"Deep",
"Delta",
"Dual",
"Edge",
"Epsilon",
"Fast",
"Flat",
"Flow",
"Flux",
"Gamma",
"Gen",
"Gray",
"Grid",
"Hard",
"Hash",
"Heavy",
"High",
"Hot",
"Hyper",
"Iron",
"Kappa",
"Lab",
"Lambda",
"Late",
"Lead",
"Lens",
"Line",
"Mod",
"Mass",
"Max",
"Mega",
"Nano",
"Neo",
"Net",
"Neural",
"Nova",
"Omega",
"Port",
"Prime",
"Proto",
"Pull",
"Quad",
"Raw",
"Red",
"Sharp",
"Sigma",
"Solid",
"Sub",
"Tech",
"Var",
"Wire",
"Zeta",
)
A list of adjectives used to generate random application titles.
NOUNS
module-attribute
NOUNS = (
"Array",
"Axis",
"Base",
"Bit",
"Block",
"Bool",
"Boot",
"Buffer",
"Bus",
"Byte",
"Cache",
"Cell",
"Chain",
"Cube",
"Dict",
"Diff",
"Disk",
"Dock",
"Eval",
"Exec",
"File",
"Flag",
"Frame",
"Func",
"Gate",
"Graph",
"Group",
"Heap",
"Hook",
"Host",
"Hub",
"Init",
"Int",
"Item",
"Join",
"Key",
"Link",
"List",
"Loop",
"Map",
"Mesh",
"Mode",
"Num",
"Node",
"Null",
"Page",
"Path",
"Pipe",
"Pod",
"Pool",
"Proc",
"Queue",
"Ram",
"Ring",
"Root",
"Scan",
"Set",
"Shell",
"Stack",
"Sync",
"Task",
"Term",
"Tree",
"Word",
)
A list of nouns used to generate random application titles.
ContactInfo
ContactInfo(**data: Any)
Bases: BaseModel
Contact information.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
ContactInfoDict
Bases: TypedDict
Contact information dictionary.
email
instance-attribute
email: Email
The email address of the contact person or organization. It must be
formatted as a valid email address. Defaults to None
.
url
instance-attribute
url: AnyHttpUrl
A URL pointing to the contact information. It must be formatted as a
valid URL. Defaults to None
.
LicenseInfo
LicenseInfo(**data: Any)
Bases: BaseModel
License information.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LicenseInfoDict
Bases: TypedDict
License information dictionary.
identifier
instance-attribute
identifier: str
An SPDX license expression. The identifier
field is mutually exclusive
with the url
field. It is available within OpenAPI since version 3.1.0.
Defaults to None
.
url
instance-attribute
url: AnyHttpUrl
A URL pointing to the license information. The url
field is mutually
exclusive with the identifier
field. Defaults to None
.
APIRouterSettings
APIRouterSettings(**data: Any)
Bases: BaseModel
Plateforme API router settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
APISettings
APISettings(**data: Any)
Bases: BaseModel
Plateforme API settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingCustomFormatterSettings
LoggingCustomFormatterSettings(**data: Any)
Bases: BaseModel
Logging custom formatter settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingDefaultFormatterSettings
LoggingDefaultFormatterSettings(**data: Any)
Bases: BaseModel
Logging default formatter settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingJsonFormatterSettings
LoggingJsonFormatterSettings(**data: Any)
Bases: BaseModel
Logging JSON formatter settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingSimpleFormatterSettings
LoggingSimpleFormatterSettings(**data: Any)
Bases: BaseModel
Logging simple formatter settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingCustomHandlerSettings
LoggingCustomHandlerSettings(**data: Any)
Bases: BaseModel
Logging custom handler settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingFileHandlerSettings
LoggingFileHandlerSettings(**data: Any)
Bases: BaseModel
Logging file handler settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingStreamHandlerSettings
LoggingStreamHandlerSettings(**data: Any)
Bases: BaseModel
Logging stream handler settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingSettings
LoggingSettings(**data: Any)
Bases: BaseModel
Plateforme logging settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
LoggingSettingsDict
Bases: TypedDict
Plateforme logging settings dictionary.
level
instance-attribute
level: Literal[
"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
]
The logging level for the application. Defaults to 'INFO'
.
filters
instance-attribute
A dictionary of logging filters used in the application with their names
as keys and the fully qualified name of the filter class as values. By
default, it includes one built-in filter under the key 'no_errors'
that
can be overridden. If provided, the custom filters are merged with these
defaults. Defaults to an empty dictionary.
formatters
instance-attribute
formatters: dict[str, LoggingFormatterSettings]
A dictionary of logging formatters used in the application. By default,
it includes three built-in formatters under the keys 'default'
,
'color'
, and 'json'
that can be overridden. If provided, the custom
formatters are merged with these defaults.
Defaults to an empty dictionary.
handlers
instance-attribute
handlers: dict[str, LoggingHandlerSettings]
A dictionary of logging handlers used in the application. By default, it
includes two built-in handlers under the keys 'stdout'
and 'stderr'
that can be overridden. If provided, the custom handlers are merged with
these defaults. Defaults to an empty dictionary.
NamespaceSettings
NamespaceSettings(**data: Any)
Bases: BaseModel
Plateforme namespace settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
PackageSettings
PackageSettings(**data: Any)
Bases: BaseModel
Plateforme package settings.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
Settings
SettingsDict
Bases: TypedDict
Plateforme application settings dictionary.
context
instance-attribute
context: bool
Whether to set up and maintain the application context in the current
thread when creating the instance. When enabled, the application context
will be set to the current application being initialized, and won't require
an explicit context manager. Defaults to True
.
debug
instance-attribute
debug: bool
Whether to run the application in debug mode. When debug mode is
enabled, debug tracebacks will be returned on server and the application
will automatically reload when changes are detected in the underlying code.
Defaults to False
.
logging
instance-attribute
logging: LoggingSettings | LoggingSettingsDict | bool
Whether to enable logging in the application. When enabled, the
application will log messages to the configured handlers. It accepts either
a boolean to enable or disable default logging settings or a dictionary
with custom logging settings. Defaults to True
.
secret_key
instance-attribute
The application secret key. If not provided, a random alphanumeric secret key marked as insecure will be generated. Please note that it must be kept secret and should not be shared, it's insecure to use a secret key in a public repository. Consider using an environment variable instead. Defaults to a random secret key.
title
instance-attribute
title: str
The application human-readable title that is used to display the
application verbose name and will be added to the generated OpenAPI,
visible at /docs
. When not provided, a random title will be generated.
Defaults to a random title.
summary
instance-attribute
summary: str | None
A short summary of the application. It will be added to the generated
OpenAPI, visible at /docs
. Defaults to None
.
description
instance-attribute
description: str | None
A description of the application. Supports Markdown (using CommonMark
syntax). It will be added to the generated OpenAPI, visible at /docs
.
Defaults to None
.
version
instance-attribute
version: str
The application version. It is used to define the version of the
application, not the version of the OpenAPI specification or the version
of the Plateforme framework being used. It will be added to the generated
OpenAPI, visible at /docs
. Defaults to '0.1.0'
.
contact
instance-attribute
contact: ContactInfo | ContactInfoDict | str | None
The contact information for the application exposed API. It can be
provided either as a string with the contact name and optionally an email
address, or as a dictionary. The following fields will be added to the
generated OpenAPI, visible at /docs
:
- name
(str): The name of the contact person or organization. If not
provided, it defaults to an empty string.
- url
(str): An URL pointing to the contact information. It must be
formatted as a valid URL.
- email
(str): The email address of the contact person or organization.
It must be formatted as a valid email address.
Defaults to None
.
license
instance-attribute
license: LicenseInfo | LicenseInfoDict | str | None
The license information for the application exposed API. It can be
provided either as a string with the license name, or as a dictionary. The
following fields will be added to the generated OpenAPI, visible at
/docs
:
- name
(str): The license name used for the API.
- identifier
(str): An SPDX license expression for the API. The
identifier
field is mutually exclusive of the url
field.
Available since OpenAPI 3.1.0.
- url
(str): An URL to the license used for the API. This must be
formatted as a valid URL.
Defaults to None
.
terms_of_service
instance-attribute
terms_of_service: str | None
A URL to the Terms of Service for the application exposed API. It will
be added to the generated OpenAPI, visible at /docs
.
Defaults to None
.
namespaces
instance-attribute
namespaces: Sequence[str | tuple[str, NamespaceSettings]]
The application namespaces to load. Each namespace can be provided
either as a string for the namespace name or a tuple with the namespace
name and its settings. The namespace name is used to group package
resources and services within the application to avoid name collisions.
The default namespace uses the empty string as its name ''
. The
namespace settings are used to override the default namespace
implementation configuration. Defaults to an empty list.
packages
instance-attribute
packages: Sequence[str | tuple[str, PackageSettings]]
The application packages to load. Each package can be provided either
as a string for the package name or a tuple with the package name and its
settings. The package name is used to load the package with its resources
and services within the application. The package settings are used to
override the default package implementation configuration. The default
special package symbol $
is used to reference the application caller
package and load its module resources and services.
Defaults to a list with the special package symbol '$'
.
auto_import_dependencies
instance-attribute
auto_import_dependencies: bool
Whether to automatically import dependencies of the application
packages. Auto-imported package dependencies are implemented with their
default settings. Defaults to True
.
auto_import_namespaces
instance-attribute
auto_import_namespaces: bool
Whether to automatically import and create missing namespace
configurations for packages within the application.
Defaults to True
.
api_max_depth
instance-attribute
api_max_depth: int
The maximum depth to walk through the resource path to collect manager
methods from resource dependencies. It is used to generate the API routes
for resources within the application. Defaults to 2
.
api_max_selection
instance-attribute
api_max_selection: int
The limit of resources to return for the API route selections. It is
used when generating the API routes for resources within the application
to avoid too many resources being returned. Defaults to 20
.
deprecated
instance-attribute
deprecated: bool | None
Whether the application is deprecated. Defaults to None
.
database_engines
instance-attribute
The application database engines. It accepts either:
- A string with the database engine URL such as ':memory:'
for an
in-memory SQLite database, a path to a SQLite database file, or a
database URL for other database engines.
- A dictionary with the database engine URL for the default engine and
other engines.
Defaults to ':memory:'
.
generate_secret_key
Generate a secure alphanumeric secret key of the given length.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/settings.py
generate_seed_from_path
Generates a reproducible seed from a system path.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/settings.py
generate_title
generate_title() -> str
Generate a random title.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/settings.py
merge_settings
Merge multiple settings into a single settings instance.
It copies the provided settings model instance and merges other settings
model instances into for matching fields. The last settings model instance
has precedence over the previous ones. Additional settings can be provided
as keyword arguments, where a DefaultPlaceholder
can be used to set a
default value for a field when no previous settings have set it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
_T
|
The settings model instance to copy and use as a base. |
required |
*others
|
BaseModel | None
|
The other settings model instances to merge into the base. |
()
|
**update
|
Any
|
Values to add/modify within the new model. Note that the
integrity of the data is not validated when creating the new model.
Data should be trusted or pre-validated in this case. Additionaly
it can include |
{}
|
Returns:
Type | Description |
---|---|
_T
|
The merged settings model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the merged settings are invalid. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/settings.py
plateforme.core.loaders
This module provides utilities for managing loaders used in settings within the Plateforme framework.
LoaderInfo
Bases: Representation
Information about a loader.
This class is used to store information about an object that is loaded using a fullname. It is used to serialize and deserialize the object.
Attributes:
Name | Type | Description |
---|---|---|
name |
The fullname of the object. |
|
static |
Whether the object was loaded statically. |
Initialize the loader information.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/loaders.py
Loader
Bases: Generic[_T]
A loader for objects.
This class is used to load objects from a fullname. It is used to serialize and deserialize the object.
Attributes:
Name | Type | Description |
---|---|---|
type_ |
type[_T]
|
The type of the object to load. |
Initialize the loader.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/loaders.py
serialize
serialize(
obj: _T, info: SerializationInfo | None = None
) -> LoaderInfo | str
Serialize the loaded object.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/loaders.py
validate
Validate and load an object.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/loaders.py
validate_instance
Validate an object instance against the loader type.