typing
Provides publicly available typing definitions.
Classes:
-
Backend–An enum of library names corresponding to anyio.
-
Hosts–An enum of host names that are available in async_kernel.event_loop.run.run.
-
Channel–An enum of channel names Ref.
-
RunMode–An Enum of the run modes available for handling
execute_requestmessages. -
MsgType–An enumeration of Message
msg_typefor shell and control messages. -
Tags–Cell tags used in async-kernel.
-
CallerState–The State of a async_kernel.caller.Caller.
-
MsgHeader– -
Message–A message.
-
Job–A
Messagerequest bundle. -
ExecuteContent–Ref.
-
FixedCreate–A TypedDict relevant to Fixed.
-
FixedCreated–A TypedDict relevant to Fixed.
-
RunSettings–A dict of settings to use with async_kernel.event_loop.run.
-
CallerCreateOptions–Options to use when creating an instance of a Caller.
Attributes:
-
NoValue(Final) –A sentinel to indicate a value has not been provided.
-
DebugMessage–A TypeAlias for a debug message.
-
Content–A TypeAlias for the content in
Message. -
HandlerType–A TypeAlias for the handler of message requests.
NoValue
module-attribute
¶
NoValue: Final = Sentinel('NoValue')
A sentinel to indicate a value has not been provided.
DebugMessage
module-attribute
¶
A TypeAlias for a debug message.
Content
module-attribute
¶
A TypeAlias for the content in Message.
Notes
- The content of a message handler can provide 'buffers'. When present, the buffers are extracted from dict and handled separately by the interface.
HandlerType
module-attribute
¶
A TypeAlias for the handler of message requests.
Backend
¶
Bases: StrEnum
An enum of library names corresponding to anyio.
- Reference event_loop
- Reference
Attributes:
Source code in src/async_kernel/typing.py
58 59 60 61 62 63 64 65 | |
asyncio
class-attribute
instance-attribute
¶
asyncio = 'asyncio'
An asyncio style event loop.
-
Reference
event_loop
run
Hosts
¶
Bases: StrEnum
An enum of host names that are available in async_kernel.event_loop.run.run.
- Reference
- Reference
Methods:
-
from_gui–Transform a matplotlib gui type to a host name if possible.
Attributes:
Source code in src/async_kernel/typing.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
from_gui
classmethod
¶
Transform a matplotlib gui type to a host name if possible.
Source code in src/async_kernel/typing.py
81 82 83 84 85 86 87 88 89 | |
Channel
¶
Bases: StrEnum
An enum of channel names Ref.
Attributes:
Source code in src/async_kernel/typing.py
92 93 94 95 96 97 98 99 100 101 102 103 104 | |
RunMode
¶
Bases: StrEnum
An Enum of the run modes available for handling execute_request messages.
Cell overrides
The user can also specify an execution mode in execute requests.
Top line comment:
# task
```python
# thread
```
Methods:
-
to_runmode–Converts value to
Runmode,CallerCreateOptionsor default where it is not possible. -
line_to_options–Convert the line string to CallerCreateOptions.
Attributes:
-
queue–Run the message handler using async_kernel.caller.Caller.queue_call.
-
task–Run the message handler using async_kernel.caller.Caller.call_soon.
-
thread–Run the message handler using async_kernel.caller.Caller.to_thread.
Source code in src/async_kernel/typing.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
queue
class-attribute
instance-attribute
¶
queue = 'queue'
Run the message handler using async_kernel.caller.Caller.queue_call.
task
class-attribute
instance-attribute
¶
task = 'task'
Run the message handler using async_kernel.caller.Caller.call_soon.
thread
class-attribute
instance-attribute
¶
thread = 'thread'
Run the message handler using async_kernel.caller.Caller.to_thread.
to_runmode
classmethod
¶
to_runmode(value: Any, default: T = None) -> Self | T | CallerCreateOptions
Converts value to Runmode, CallerCreateOptions or default where it is not possible.
CallerCreateOptions will only return when a string is passed specifying a thread and options.
Example
value = "# thread name='My exeecutor' backend=trio
Source code in src/async_kernel/typing.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
line_to_options
classmethod
¶
line_to_options(line: str) -> CallerCreateOptions
Convert the line string to CallerCreateOptions.
Source code in src/async_kernel/typing.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
MsgType
¶
Bases: StrEnum
An enumeration of Message msg_type for shell and control messages.
Some message types are on the control channel only.
Attributes:
-
kernel_info_request– -
comm_info_request– -
execute_request– -
complete_request– -
is_complete_request– -
inspect_request– -
history_request– -
comm_open– -
comm_msg– -
comm_close– -
interrupt_request–async_kernel.kernel.Kernel.interrupt_request (control channel only)
-
shutdown_request–async_kernel.kernel.Kernel.shutdown_request (control channel only)
-
debug_request–async_kernel.kernel.Kernel.debug_request (control channel only)
-
create_subshell_request–async_kernel.kernel.Kernel.create_subshell_request (control channel only)
-
delete_subshell_request–async_kernel.kernel.Kernel.delete_subshell_request (control channel only)
-
list_subshell_request–async_kernel.kernel.Kernel.debug_request (control channel only)
-
input_request–A message sent from the kernel interface to a client asking for raw input.
-
iopub_welcome–A welcome message on the iopub channel for new iopub channel subscriptions.
-
iopub_status–An iopub message about a handlers status which can be 'busy' or 'idle'.
-
iopub_execute_input–An iopub message with detail of an execute request.
-
iopub_execute_result–An iopub message with for the global display hook. Generally the last executed line of an execute request.
-
iopub_error–An iopub message for an error.
-
iopub_stream–Stream data such as stdout and stderr.
-
iopub_display_data–An iopub message with display output data.
-
iopub_update_display_data–An iopub message to update display data.
-
iopub_clear_output–An iopub display message instructing the associated display to clear.
-
debug_event–An event published by an attached debug adapter.
-
input_reply–A reply sent from the client to a kernel interface corresponding to an input request.
Source code in src/async_kernel/typing.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
kernel_info_request
class-attribute
instance-attribute
¶
kernel_info_request = 'kernel_info_request'
comm_info_request
class-attribute
instance-attribute
¶
comm_info_request = 'comm_info_request'
execute_request
class-attribute
instance-attribute
¶
execute_request = 'execute_request'
complete_request
class-attribute
instance-attribute
¶
complete_request = 'complete_request'
is_complete_request
class-attribute
instance-attribute
¶
is_complete_request = 'is_complete_request'
inspect_request
class-attribute
instance-attribute
¶
inspect_request = 'inspect_request'
history_request
class-attribute
instance-attribute
¶
history_request = 'history_request'
comm_open
class-attribute
instance-attribute
¶
comm_open = 'comm_open'
async_kernel.kernel.Kernel.comm_open
-
Reference
kernel
Kernelhandle_in_shell_thread
comm_msg
class-attribute
instance-attribute
¶
comm_msg = 'comm_msg'
async_kernel.kernel.Kernel.comm_msg
-
Reference
kernel
Kernelhandle_in_shell_thread
comm_close
class-attribute
instance-attribute
¶
comm_close = 'comm_close'
async_kernel.kernel.Kernel.comm_close
-
Reference
kernel
Kernelhandle_in_shell_thread
interrupt_request
class-attribute
instance-attribute
¶
interrupt_request = 'interrupt_request'
async_kernel.kernel.Kernel.interrupt_request (control channel only)
shutdown_request
class-attribute
instance-attribute
¶
shutdown_request = 'shutdown_request'
async_kernel.kernel.Kernel.shutdown_request (control channel only)
debug_request
class-attribute
instance-attribute
¶
debug_request = 'debug_request'
async_kernel.kernel.Kernel.debug_request (control channel only)
create_subshell_request
class-attribute
instance-attribute
¶
create_subshell_request = 'create_subshell_request'
async_kernel.kernel.Kernel.create_subshell_request (control channel only)
delete_subshell_request
class-attribute
instance-attribute
¶
delete_subshell_request = 'delete_subshell_request'
async_kernel.kernel.Kernel.delete_subshell_request (control channel only)
list_subshell_request
class-attribute
instance-attribute
¶
list_subshell_request = 'list_subshell_request'
async_kernel.kernel.Kernel.debug_request (control channel only)
input_request
class-attribute
instance-attribute
¶
input_request = 'input_request'
A message sent from the kernel interface to a client asking for raw input.
iopub_welcome
class-attribute
instance-attribute
¶
iopub_welcome = 'iopub_welcome'
A welcome message on the iopub channel for new iopub channel subscriptions.
iopub_status
class-attribute
instance-attribute
¶
iopub_status = 'status'
An iopub message about a handlers status which can be 'busy' or 'idle'.
iopub_execute_input
class-attribute
instance-attribute
¶
iopub_execute_input = 'execute_input'
An iopub message with detail of an execute request.
iopub_execute_result
class-attribute
instance-attribute
¶
iopub_execute_result = 'execute_result'
An iopub message with for the global display hook. Generally the last executed line of an execute request.
iopub_error
class-attribute
instance-attribute
¶
iopub_error = 'error'
An iopub message for an error.
iopub_stream
class-attribute
instance-attribute
¶
iopub_stream = 'stream'
Stream data such as stdout and stderr.
iopub_display_data
class-attribute
instance-attribute
¶
iopub_display_data = 'display_data'
An iopub message with display output data.
iopub_update_display_data
class-attribute
instance-attribute
¶
iopub_update_display_data = 'iopub_update_display_data'
An iopub message to update display data.
iopub_clear_output
class-attribute
instance-attribute
¶
iopub_clear_output = 'clear_output'
An iopub display message instructing the associated display to clear.
debug_event
class-attribute
instance-attribute
¶
debug_event = 'debug_event'
An event published by an attached debug adapter.
input_reply
class-attribute
instance-attribute
¶
input_reply = 'input_reply'
A reply sent from the client to a kernel interface corresponding to an input request.
Tags
¶
Bases: StrEnum
Cell tags used in async-kernel.
Info
Tags are can be added per cell.
- Jupyter: via the right side bar.
- VS Code: via Jupyter variables explorer
-
Reference
utils
get_tag_value
Methods:
-
get_value–Extract the value and convert it to match the type of default using
tag=value.
Attributes:
-
raises_exception–Indicates the cell should expect an exception to be raised.
-
stop_on_error–Override
stop_on_error. -
timeout–Specify a timeout in seconds for code execution to complete.
Source code in src/async_kernel/typing.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
raises_exception
class-attribute
instance-attribute
¶
raises_exception = 'raises-exception'
Indicates the cell should expect an exception to be raised.
Notes
- When an exception is raised, stop_on_error is False/
- When an exception is not raised an exception will be raise and stop_on_error is True.
stop_on_error
class-attribute
instance-attribute
¶
stop_on_error = 'stop-on-error'
Override stop_on_error.
Examples:
- True
- stop_on_error=true
- stop_on_error=True
- False
- stop_on_error=False
timeout
class-attribute
instance-attribute
¶
timeout = 'timeout'
Specify a timeout in seconds for code execution to complete.
Examples:
- timeout=0.0 (no timeout)
- timeout=0.1 (100 ms)
get_value
classmethod
¶
get_value(value: str, default: T_fsb) -> T_fsb
Extract the value and convert it to match the type of default using tag=value.
Source code in src/async_kernel/typing.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
CallerState
¶
Bases: Enum
The State of a async_kernel.caller.Caller.
Source code in src/async_kernel/typing.py
400 401 402 403 404 405 406 407 408 | |
MsgHeader
¶
Bases: TypedDict
Attributes:
-
msg_id(str) – -
session(str) – -
username(str) – -
date(str | datetime) – -
msg_type(MsgType | str) – -
version(str) – -
subshell_id(NotRequired[str | None]) –
Source code in src/async_kernel/typing.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
Message
¶
Bases: TypedDict, Generic[T]
A message.
- Reference
Attributes:
-
channel(Channel) –The channel of the message.
-
header(MsgHeader) – -
parent_header(MsgHeader | None) – -
metadata(dict[str, Any]) – -
content(T | Content) – -
buffers(BuffersType) –
Source code in src/async_kernel/typing.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
Job
¶
Bases: TypedDict, Generic[T]
A Message request bundle.
- Reference
Attributes:
-
msg(Message[T]) –The message received over the socket.
-
ident(list[bytes]) –The ident associated with the message and its origin.
-
owner(Callable[[], MessageProtocol]) –A callable that returns the object from which a message originated.
-
received_time(float) –The time the message was received.
Source code in src/async_kernel/typing.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
ExecuteContent
¶
Bases: TypedDict
Ref.
Attributes:
-
code(str) –The code to execute.
-
silent(bool) – -
store_history(bool) – -
user_expressions(dict[str, str]) – -
allow_stdin(bool) – -
stop_on_error(bool) – -
subshell_id(NotRequired[str | None]) –
Source code in src/async_kernel/typing.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
FixedCreate
¶
Bases: TypedDict, Generic[S]
A TypedDict relevant to Fixed.
Attributes:
Source code in src/async_kernel/typing.py
552 553 554 555 556 557 558 | |
FixedCreated
¶
Bases: TypedDict, Generic[S, T]
A TypedDict relevant to Fixed.
Attributes:
Source code in src/async_kernel/typing.py
561 562 563 564 565 566 567 568 569 | |
RunSettings
¶
Bases: TypedDict
A dict of settings to use with async_kernel.event_loop.run.
-
Reference
typing
CallerCreateOptions
- Reference event_loop
Attributes:
-
backend(NotRequired[Backend | Literal['asyncio', 'trio']]) –The backend to use for the caller.
-
backend_options(NotRequired[dict | None]) –The backend options to specify for anyio.run (or
start_guest_runwhen a host is specified). -
host(NotRequired[Hosts | Literal['tk', 'qt'] | None]) –The type of host where the backend will run.
-
host_options(NotRequired[dict | None]) –Options to use when starting the host.
Source code in src/async_kernel/typing.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
backend
instance-attribute
¶
backend: NotRequired[Backend | Literal['asyncio', 'trio']]
The backend to use for the caller.
backend_options
instance-attribute
¶
backend_options: NotRequired[dict | None]
The backend options to specify for anyio.run (or start_guest_run when a host is specified).
Tip
When there is no host and the backend is asyncio. 'loop_factory' can be specified as a function
or importable path like 'asyncio.new_event_loop'.
host
instance-attribute
¶
host: NotRequired[Hosts | Literal['tk', 'qt'] | None]
The type of host where the backend will run.
host_options
instance-attribute
¶
host_options: NotRequired[dict | None]
Options to use when starting the host.
CallerCreateOptions
¶
Bases: RunSettings
Options to use when creating an instance of a Caller.
Attributes:
-
name(NotRequired[str]) –The name for the new caller instance.
-
no_debug(NotRequired[bool]) –Disable debugpy in the thread if a new thread is created.
Source code in src/async_kernel/typing.py
593 594 595 596 597 598 599 600 | |
no_debug
instance-attribute
¶
no_debug: NotRequired[bool]
Disable debugpy in the thread if a new thread is created.