Skip to content

APIBlueprint

Flask's Blueprint object with some web API support.

Examples:

from apiflask import APIBlueprint

bp = APIBlueprint(__name__, 'foo')

Version added: 0.2.0

__init__(self, name, import_name, tag=None, static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, root_path=None, cli_group=<object object at 0x7f64147920f0>) special

Make a blueprint instance.

Parameters:

Name Type Description Default
name str

The name of the blueprint. Will be prepended to each endpoint name.

required
import_name str

The name of the blueprint package, usually __name__. This helps locate the root_path for the blueprint.

required
tag Union[str, dict]

The tag of this blueprint. If not set, the <blueprint name>.title() will be used ('foo' -> 'Foo'). Accepts a tag name string or an OpenAPI tag dict. Example:

bp = APIBlueprint(__name__, 'foo', tag='Foo')
bp = APIBlueprint(__name__, 'foo', tag={'name': 'Foo'})
None

Other keyword arguments are directly pass to flask.Blueprint.

Source code in apiflask/blueprint.py
def __init__(
    self,
    name: str,
    import_name: str,
    tag: Optional[Union[str, dict]] = None,
    static_folder: Optional[str] = None,
    static_url_path: Optional[str] = None,
    template_folder: Optional[str] = None,
    url_prefix: Optional[str] = None,
    subdomain: Optional[str] = None,
    url_defaults: Optional[dict] = None,
    root_path: Optional[str] = None,
    cli_group: Union[Optional[str]] = _sentinel  # type: ignore
) -> None:
    """Make a blueprint instance.

    Arguments:
        name: The name of the blueprint. Will be prepended to
            each endpoint name.
        import_name: The name of the blueprint package, usually
            `__name__`. This helps locate the `root_path` for the
            blueprint.
        tag: The tag of this blueprint. If not set, the
            `<blueprint name>.title()` will be used (`'foo'` -> `'Foo'`).
            Accepts a tag name string or an OpenAPI tag dict.
            Example:

            ```python
            bp = APIBlueprint(__name__, 'foo', tag='Foo')
            ```

            ```python
            bp = APIBlueprint(__name__, 'foo', tag={'name': 'Foo'})
            ```

    Other keyword arguments are directly pass to `flask.Blueprint`.
    """
    super(APIBlueprint, self).__init__(
        name,
        import_name,
        static_folder=static_folder,
        static_url_path=static_url_path,
        template_folder=template_folder,
        url_prefix=url_prefix,
        subdomain=subdomain,
        url_defaults=url_defaults,
        root_path=root_path,
        cli_group=cli_group,
    )
    self.tag = tag

delete(self, rule, **options)

Shortcut for app.route(methods=['DELETE']).

Source code in apiflask/blueprint.py
def delete(self, rule: str, **options: Any):
    """Shortcut for `app.route(methods=['DELETE'])`."""
    return cls_route(self, rule, methods=['DELETE'], **options)

get(self, rule, **options)

Shortcut for app.route().

Source code in apiflask/blueprint.py
def get(self, rule: str, **options: Any):
    """Shortcut for `app.route()`."""
    return cls_route(self, rule, methods=['GET'], **options)

patch(self, rule, **options)

Shortcut for app.route(methods=['PATCH']).

Source code in apiflask/blueprint.py
def patch(self, rule: str, **options: Any):
    """Shortcut for `app.route(methods=['PATCH'])`."""
    return cls_route(self, rule, methods=['PATCH'], **options)

post(self, rule, **options)

Shortcut for app.route(methods=['POST']).

Source code in apiflask/blueprint.py
def post(self, rule: str, **options: Any):
    """Shortcut for `app.route(methods=['POST'])`."""
    return cls_route(self, rule, methods=['POST'], **options)

put(self, rule, **options)

Shortcut for app.route(methods=['PUT']).

Source code in apiflask/blueprint.py
def put(self, rule: str, **options: Any):
    """Shortcut for `app.route(methods=['PUT'])`."""
    return cls_route(self, rule, methods=['PUT'], **options)