Namespaces
plateforme.core.namespaces
This module provides utilities for managing namespaces within the Plateforme framework.
Namespace
Namespace(name: str)
Bases: Representation
A namespace placeholder for packages within the Plateforme framework.
A namespace is a container for packages. It provides a way to group related packages together and manage their resources, routes, and API endpoints.
Attributes:
Name | Type | Description |
---|---|---|
_impls |
dict[Plateforme | None, NamespaceImpl]
|
The registered namespace implementations as a dictionary mapping the application context to the namespace implementation. |
name |
str
|
The name of the namespace that is unique within the entire
runtime environment. It can be |
Initialize a namespace.
Note
The import_namespace
method should be used to retrieve a
namespace instance based on the provided name.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/namespaces.py
impl
property
impl: NamespaceImpl
The current namespace implementation based on the app context.
A read-only property that returns the namespace implementation based on the application context. If no context is available, it returns the namespace default implementation. Otherwise, it raises an error if the namespace implementation is not available in the current application context.
NamespaceImpl
NamespaceImpl(
namespace: Namespace,
context: Plateforme | None,
*,
settings: NamespaceSettings | None = None,
auto_generated: bool = False,
)
Bases: Proxy[Namespace]
A namespace implementation proxy class.
It defines the implementation details of a namespace within the Plateforme
framework. It extends the Proxy
class and adds additional information
about the namespace.
Attributes:
Name | Type | Description |
---|---|---|
context |
Plateforme | None
|
The application context associated with the namespace implementation. |
packages |
dict[str, PackageImpl]
|
A dictionary of packages implemented within the namespace. |
settings |
NamespaceSettings
|
The namespace settings to use for the implementation. |
auto_generated |
bool
|
Whether the namespace implementation is auto-generated and should not be persisted when removing dependent packages. |
api |
APIManager
|
The API manager of the namespace implementation. |
Initialize a namespace implementation proxy instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
Namespace
|
The namespace instance to proxy. |
required |
context
|
Plateforme | None
|
The application context to associate with the namespace implementation. |
required |
settings
|
NamespaceSettings | None
|
The namespace settings to use. Defaults to an empty
|
None
|
auto_generated
|
bool
|
Whether the namespace implementation is
auto-generated and should not be persisted when removing
dependent packages. Defaults to |
False
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/namespaces.py
alias
property
alias: str
The namespace alias.
It is used to to define which database schema should store its resources in an application. Multiple namespaces can share the same alias within an application. It must be formatted to snake case and defaults to the namespace name.
Examples:
my_namespace
path
property
path: str
The namespace API route path.
It specifies the API route path of the namespace within an application.
Examples:
/my-namespace
slug
property
slug: str
The namespace slug.
It is used to define which URL path should be used to access the namespace resources in an API. Multiple namespaces can share the same slug within an application. It must be formatted to kebab case and defaults to the kebab case of the namespace name.
Examples:
my-namespace
formy_namespace
title
property
title: str | None
The namespace human-readable title.
It is used to display the namespace verbose name within an application. It defaults to the titleized version of the namespace alias.
Examples:
My Namespace
formy_namespace
setup_api
setup_api(*, reset: bool = False) -> None
Setup the namespace API manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reset
|
bool
|
Whether to reset the namespace API manager, i.e. clear all
existing routes from current router. Defaults to |
False
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/namespaces.py
mount
mount(
*names: str,
force: bool = False,
raise_errors: bool = True,
**overrides: Unpack[APIBaseRouterConfigDict],
) -> None
Mount given packages into the namespace API manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*names
|
str
|
A list of package module names to mount into the application namespace API manager. |
()
|
force
|
bool
|
Whether to force mount the packages even if they are already
mounted. This will not raise an error if a package is already
mounted, otherwise it will replace the existing package router
with a new one. Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently if a
package is already mounted within the API manager.
Defaults to |
True
|
**overrides
|
Unpack[APIBaseRouterConfigDict]
|
Additional router configuration keyword arguments to override the default router configuration when including the package routers. |
{}
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/namespaces.py
unmount
Unmount given packages from the namespace API manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*names
|
str
|
A list of package module names to unmount from the application namespace API manager. |
()
|
raise_errors
|
bool
|
Whether to raise errors or fail silently if a
package is not mounted within the API manager.
Defaults to |
True
|