arkitekt-runtime 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. arkitekt_runtime/__init__.py +8 -0
  2. arkitekt_runtime/actors/__init__.py +6 -0
  3. arkitekt_runtime/actors/actify.py +91 -0
  4. arkitekt_runtime/actors/base.py +641 -0
  5. arkitekt_runtime/actors/build.py +28 -0
  6. arkitekt_runtime/actors/debug.py +117 -0
  7. arkitekt_runtime/actors/dependency.py +163 -0
  8. arkitekt_runtime/actors/errors.py +15 -0
  9. arkitekt_runtime/actors/functional.py +210 -0
  10. arkitekt_runtime/actors/helper.py +164 -0
  11. arkitekt_runtime/actors/types.py +279 -0
  12. arkitekt_runtime/agents/__init__.py +1 -0
  13. arkitekt_runtime/agents/backend.py +93 -0
  14. arkitekt_runtime/agents/base.py +1893 -0
  15. arkitekt_runtime/agents/dataclasses.py +51 -0
  16. arkitekt_runtime/agents/hooks/__init__.py +1 -0
  17. arkitekt_runtime/agents/hooks/background.py +78 -0
  18. arkitekt_runtime/agents/hooks/materialize.py +35 -0
  19. arkitekt_runtime/agents/hooks/shutdown.py +80 -0
  20. arkitekt_runtime/agents/hooks/startup.py +120 -0
  21. arkitekt_runtime/agents/journal.py +772 -0
  22. arkitekt_runtime/agents/lock.py +146 -0
  23. arkitekt_runtime/agents/policy.py +102 -0
  24. arkitekt_runtime/agents/transport/__init__.py +1 -0
  25. arkitekt_runtime/agents/transport/base.py +149 -0
  26. arkitekt_runtime/agents/transport/types.py +159 -0
  27. arkitekt_runtime/calls.py +205 -0
  28. arkitekt_runtime/constants.py +4 -0
  29. arkitekt_runtime/invoke.py +253 -0
  30. arkitekt_runtime/messages.py +1235 -0
  31. arkitekt_runtime/postmans/__init__.py +1 -0
  32. arkitekt_runtime/postmans/errors.py +25 -0
  33. arkitekt_runtime/postmans/types.py +131 -0
  34. arkitekt_runtime/qt/__init__.py +1 -0
  35. arkitekt_runtime/qt/builders.py +347 -0
  36. arkitekt_runtime/state/__init__.py +1 -0
  37. arkitekt_runtime/state/gate.py +79 -0
  38. arkitekt_runtime/state/observable.py +809 -0
  39. arkitekt_runtime/state/readonly.py +201 -0
  40. arkitekt_runtime/state/shrink.py +36 -0
  41. arkitekt_runtime/state/write.py +174 -0
  42. arkitekt_runtime/structures/__init__.py +1 -0
  43. arkitekt_runtime/structures/serialization/__init__.py +1 -0
  44. arkitekt_runtime/structures/serialization/actor.py +856 -0
  45. arkitekt_runtime/structures/serialization/batching.py +100 -0
  46. arkitekt_runtime/structures/serialization/context.py +112 -0
  47. arkitekt_runtime/structures/serialization/expand.py +340 -0
  48. arkitekt_runtime/structures/serialization/memory.py +50 -0
  49. arkitekt_runtime/structures/serialization/port_errors.py +64 -0
  50. arkitekt_runtime/structures/serialization/postman.py +10 -0
  51. arkitekt_runtime/structures/serialization/predication.py +103 -0
  52. arkitekt_runtime/structures/serialization/protocols.py +99 -0
  53. arkitekt_runtime/structures/serialization/shrink.py +307 -0
  54. arkitekt_runtime/task.py +362 -0
  55. arkitekt_runtime/task_scope.py +24 -0
  56. arkitekt_runtime/types.py +125 -0
  57. arkitekt_runtime-1.0.1.dist-info/METADATA +29 -0
  58. arkitekt_runtime-1.0.1.dist-info/RECORD +59 -0
  59. arkitekt_runtime-1.0.1.dist-info/WHEEL +4 -0
@@ -0,0 +1,8 @@
1
+ """arkitekt-runtime: the execution core every runtime of an Arkitekt app shares.
2
+
3
+ A declared app (:mod:`arkitekt_spec.declare`) is run by a runtime: rekuest in
4
+ distributed mode, arkitekt-fastapi in server mode. Both are built on this package --
5
+ the agent (:mod:`arkitekt_runtime.agents.base`), actors, :class:`~arkitekt_runtime.task.Task`,
6
+ the journal, state, locks, hook runners and structure serialization. A runtime plugs
7
+ in its transport, its caller and its task scope; this package has none of its own.
8
+ """
@@ -0,0 +1,6 @@
1
+ """The actors: what runs one assignment of an action.
2
+
3
+ Nothing is re-exported here -- an actor, a builder or a strategy is imported
4
+ from the module that defines it (``actors.base``, ``actors.functional``,
5
+ ``actors.actify``).
6
+ """
@@ -0,0 +1,91 @@
1
+ """Actifier
2
+
3
+ This module contains the actify function, which is used to convert a function
4
+ into an actor.
5
+ """
6
+
7
+ import inspect
8
+ from functools import partial
9
+ from typing import Any
10
+
11
+ from arkitekt_runtime.actors.functional import (
12
+ FUNC,
13
+ GEN,
14
+ THREADED_FUNC,
15
+ THREADED_GEN,
16
+ FunctionalActor,
17
+ )
18
+ from arkitekt_spec.declare.protocol.types import AnyFunction
19
+ from arkitekt_spec.declare.actors.types import (
20
+ ImplementationDetails,
21
+ RegisterConfig,
22
+ )
23
+ from arkitekt_runtime.actors.types import ActorBuilder
24
+ from arkitekt_spec.actions import DefinitionInput
25
+ from arkitekt_spec.declare.structures.registry import StructureRegistry
26
+ from arkitekt_spec.declare.actors.actify import (
27
+ derive_implementation_details,
28
+ prepare_definition_from_config,
29
+ )
30
+
31
+
32
+
33
+
34
+
35
+
36
+ def reactify(
37
+ function: AnyFunction,
38
+ structure_registry: StructureRegistry,
39
+ config: RegisterConfig | None = None,
40
+ ) -> tuple[DefinitionInput, ImplementationDetails, ActorBuilder]:
41
+ """Reactify a function
42
+
43
+ This function takes a callable (of type async or sync function or generator) and
44
+ returns a builder function that creates an actor that makes the function callable
45
+ from the rekuest server.
46
+
47
+ All registration options are read from the bundled ``config``
48
+ (:class:`~rekuest.actors.types.RegisterConfig`); ``config`` defaults to an
49
+ empty config so ``reactify(func, registry)`` keeps working.
50
+ """
51
+ config = config or RegisterConfig()
52
+
53
+ implementation_details = derive_implementation_details(function, config, structure_registry)
54
+ definition = prepare_definition_from_config(
55
+ function, structure_registry, config, implementation_details
56
+ )
57
+
58
+ is_coroutine = inspect.iscoroutinefunction(function)
59
+ is_asyncgen = inspect.isasyncgenfunction(function)
60
+ is_method = inspect.ismethod(function)
61
+
62
+ is_generatorfunction = inspect.isgeneratorfunction(function)
63
+ is_function = inspect.isfunction(function)
64
+
65
+ actor_attributes: dict[str, Any] = {
66
+ "assign": function,
67
+ "expand_inputs": not config.bypass_expand,
68
+ "shrink_outputs": not config.bypass_shrink,
69
+ "structure_registry": structure_registry,
70
+ "definition": definition,
71
+ **implementation_details.actor_kwargs(),
72
+ "concurrency": config.concurrency,
73
+ "policy": config.policy,
74
+ }
75
+
76
+ if is_coroutine:
77
+ iterator = FUNC
78
+ elif is_asyncgen:
79
+ iterator = GEN
80
+ elif is_generatorfunction and not config.in_process:
81
+ iterator = THREADED_GEN
82
+ elif (is_function or is_method) and not config.in_process:
83
+ iterator = THREADED_FUNC
84
+ else:
85
+ raise NotImplementedError("No way of converting this to a function")
86
+
87
+ return (
88
+ definition,
89
+ implementation_details,
90
+ partial(FunctionalActor, iterator=iterator, **actor_attributes),
91
+ )