MCPcopy
hub / github.com/sanic-org/sanic / Sanic

Class Sanic

sanic/app.py:109–2552  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

107
108
109class 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

Callers 15

create_simple_serverFunction · 0.90
__call__Method · 0.90
create_appFunction · 0.90
__init__Method · 0.90
test_endpoint_basicFunction · 0.90
test_endpoint_basic_asgiFunction · 0.90
test_endpoint_named_appFunction · 0.90
test_endpoint_blueprintFunction · 0.90
test_vhostsFunction · 0.90
exception_handler_appFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_endpoint_basicFunction · 0.72
test_endpoint_basic_asgiFunction · 0.72
test_endpoint_named_appFunction · 0.72
test_endpoint_blueprintFunction · 0.72
test_vhostsFunction · 0.72
exception_handler_appFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…