The main application instance You will create an instance of this class and use it to register routes, listeners, middleware, blueprints, error handlers, etc. By convention, it is often called `app`. It must be named using the `name` parameter and is roughly constrained to the same
| 107 | |
| 108 | |
| 109 | class Sanic( |
| 110 | Generic[config_type, ctx_type], |
| 111 | StaticHandleMixin, |
| 112 | BaseSanic, |
| 113 | StartupMixin, |
| 114 | CommandMixin, |
| 115 | metaclass=TouchUpMeta, |
| 116 | ): |
| 117 | """The main application instance |
| 118 | |
| 119 | You will create an instance of this class and use it to register |
| 120 | routes, listeners, middleware, blueprints, error handlers, etc. |
| 121 | |
| 122 | By convention, it is often called `app`. It must be named using |
| 123 | the `name` parameter and is roughly constrained to the same |
| 124 | restrictions as a Python module name, however, it can contain |
| 125 | hyphens (`-`). |
| 126 | |
| 127 | ```python |
| 128 | # will cause an error because it contains spaces |
| 129 | Sanic("This is not legal") |
| 130 | ``` |
| 131 | |
| 132 | ```python |
| 133 | # this is legal |
| 134 | Sanic("Hyphens-are-legal_or_also_underscores") |
| 135 | ``` |
| 136 | |
| 137 | Args: |
| 138 | name (str): The name of the application. Must be a valid |
| 139 | Python module name (including hyphens). |
| 140 | config (Optional[config_type]): The configuration to use for |
| 141 | the application. Defaults to `None`. |
| 142 | ctx (Optional[ctx_type]): The context to use for the |
| 143 | application. Defaults to `None`. |
| 144 | router (Optional[Router]): The router to use for the |
| 145 | application. Defaults to `None`. |
| 146 | signal_router (Optional[SignalRouter]): The signal router to |
| 147 | use for the application. Defaults to `None`. |
| 148 | error_handler (Optional[ErrorHandler]): The error handler to |
| 149 | use for the application. Defaults to `None`. |
| 150 | env_prefix (Optional[str]): The prefix to use for environment |
| 151 | variables. Defaults to `SANIC_`. |
| 152 | request_class (Optional[Type[Request]]): The request class to |
| 153 | use for the application. Defaults to `Request`. |
| 154 | strict_slashes (bool): Whether to enforce strict slashes. |
| 155 | Defaults to `False`. |
| 156 | log_config (Optional[Dict[str, Any]]): The logging configuration |
| 157 | to use for the application. Defaults to `None`. |
| 158 | configure_logging (bool): Whether to configure logging. |
| 159 | Defaults to `True`. |
| 160 | dumps (Optional[Callable[..., AnyStr]]): The function to use |
| 161 | for serializing JSON. Defaults to `None`. |
| 162 | loads (Optional[Callable[..., Any]]): The function to use |
| 163 | for deserializing JSON. Defaults to `None`. |
| 164 | inspector (bool): Whether to enable the inspector. Defaults |
| 165 | to `False`. |
| 166 | inspector_class (Optional[Type[Inspector]]): The inspector |
no outgoing calls
searching dependent graphs…