faust.app
¶
-
class
faust.app.
App
(id: str, *, monitor: faust.sensors.monitor.Monitor = None, config_source: Any = None, loop: asyncio.events.AbstractEventLoop = None, **options) → None[source]¶ Faust Application.
Parameters: id (str) – Application ID. Keyword Arguments: loop (asyncio.AbstractEventLoop) – optional event loop to use. See also
Application Parameters – for supported keyword arguments.
-
client_only
= False¶ Set this to True if app should only start the services required to operate as an RPC client (producer and simple reply consumer).
-
config_from_object
(obj: Any, *, silent: bool = False, force: bool = False) → None[source]¶ Read configuration from object.
Object is either an actual object or the name of a module to import.
Examples
>>> app.config_from_object('myproj.faustconfig')
>>> from myproj import faustconfig >>> app.config_from_object(faustconfig)
Parameters: Return type: None
-
discover
(*extra_modules, categories: Iterable[str] = ['faust.agent', 'faust.command', 'faust.page', 'faust.service', 'faust.task'], ignore: Iterable[str] = ['test_.*', '.*__main__.*']) → None[source]¶ Return type: None
-
topic
(*topics, pattern: Union[str, Pattern[~AnyStr]] = None, key_type: Union[typing.Type[faust.types.models.ModelT], typing.Type[bytes], typing.Type[str]] = None, value_type: Union[typing.Type[faust.types.models.ModelT], typing.Type[bytes], typing.Type[str]] = None, key_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, value_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, partitions: int = None, retention: Union[datetime.timedelta, float, str] = None, compacting: bool = None, deleting: bool = None, replicas: int = None, acks: bool = True, internal: bool = False, config: Mapping[str, Any] = None, maxsize: int = None, loop: asyncio.events.AbstractEventLoop = None) → faust.types.topics.TopicT[source]¶ Create topic description.
Topics are named channels (for example a Kafka topic), that exist on a server. To make an ephemeral local communication channel use:
channel()
.See also
Return type: TopicT
[]
-
channel
(*, key_type: Union[typing.Type[faust.types.models.ModelT], typing.Type[bytes], typing.Type[str]] = None, value_type: Union[typing.Type[faust.types.models.ModelT], typing.Type[bytes], typing.Type[str]] = None, maxsize: int = 1, loop: asyncio.events.AbstractEventLoop = None) → faust.types.channels.ChannelT[source]¶ Create new channel.
By default this will create an in-memory channel used for intra-process communication, but in practice channels can be backed by any transport (network or even means of inter-process communication).
See also
Return type: ChannelT
[]
-
agent
(channel: Union[str, faust.types.channels.ChannelT] = None, *, name: str = None, concurrency: int = 1, supervisor_strategy: Type[mode.types.supervisors.SupervisorStrategyT] = None, sink: Iterable[Union[_ForwardRef('AgentT'), faust.types.channels.ChannelT, typing.Callable[[typing.Any], typing.Union[typing.Awaitable, NoneType]]]] = None, isolated_partitions: bool = False, **kwargs) → Callable[Callable[Union[typing.AsyncIterator, faust.types.streams.StreamT], Union[typing.Awaitable, typing.AsyncIterable]], faust.types.agents.AgentT][source]¶ Create Agent from async def function.
It can be a regular async function:
@app.agent() async def my_agent(stream): async for number in stream: print(f'Received: {number!r}')
Or it can be an async iterator that yields values. These values can be used as the reply in an RPC-style call, or for sinks: callbacks that forward events to other agents/topics/statsd, and so on:
@app.agent(sink=[log_topic]) async def my_agent(requests): async for number in requests: yield number * 2
Return type: Callable
[[Callable
[[Union
[AsyncIterator
[+T_co],StreamT
[+T_co]]],Union
[Awaitable
[+T_co],AsyncIterable
[+T_co]]]],AgentT
[]]
-
actor
(channel: Union[str, faust.types.channels.ChannelT] = None, *, name: str = None, concurrency: int = 1, supervisor_strategy: Type[mode.types.supervisors.SupervisorStrategyT] = None, sink: Iterable[Union[_ForwardRef('AgentT'), faust.types.channels.ChannelT, typing.Callable[[typing.Any], typing.Union[typing.Awaitable, NoneType]]]] = None, isolated_partitions: bool = False, **kwargs) → Callable[Callable[Union[typing.AsyncIterator, faust.types.streams.StreamT], Union[typing.Awaitable, typing.AsyncIterable]], faust.types.agents.AgentT]¶ Create Agent from async def function.
It can be a regular async function:
@app.agent() async def my_agent(stream): async for number in stream: print(f'Received: {number!r}')
Or it can be an async iterator that yields values. These values can be used as the reply in an RPC-style call, or for sinks: callbacks that forward events to other agents/topics/statsd, and so on:
@app.agent(sink=[log_topic]) async def my_agent(requests): async for number in requests: yield number * 2
Return type: Callable
[[Callable
[[Union
[AsyncIterator
[+T_co],StreamT
[+T_co]]],Union
[Awaitable
[+T_co],AsyncIterable
[+T_co]]]],AgentT
[]]
-
task
(fun: Union[typing.Callable[[_ForwardRef('AppT')], typing.Awaitable], typing.Callable[[], typing.Awaitable]]) → Union[typing.Callable[[_ForwardRef('AppT')], typing.Awaitable], typing.Callable[[], typing.Awaitable]][source]¶ Define an async def function to be started with the app.
This is like
timer()
but a one-shot task only executed at worker startup (after recovery and the worker is fully ready for operation).The function may take zero, or one argument. If the target function takes an argument, the
app
argument is passed:>>> @app.task >>> async def on_startup(app): ... print('STARTING UP: %r' % (app,))
Nullary functions are also supported:
>>> @app.task >>> async def on_startup(): ... print('STARTING UP')
Return type: Union
[Callable
[[AppT
[]],Awaitable
[+T_co]],Callable
[[],Awaitable
[+T_co]]]
-
timer
(interval: Union[datetime.timedelta, float, str], on_leader: bool = False) → Callable[source]¶ Define an async def function to be run at periodic intervals.
Like
task()
, but executes periodically until the worker is shut down.This decorator takes an async function and adds it to a list of timers started with the app.
Parameters: - interval (Seconds) – How often the timer executes in seconds.
- on_leader (bool) – Should the timer only run on the leader?
Example
>>> @app.timer(interval=10.0) >>> async def every_10_seconds(): ... print('TEN SECONDS JUST PASSED')
>>> app.timer(interval=5.0, on_leader=True) >>> async def every_5_seconds(): ... print('FIVE SECONDS JUST PASSED. ALSO, I AM THE LEADER!')
Return type: Callable
-
service
(cls: Type[mode.types.services.ServiceT]) → Type[mode.types.services.ServiceT][source]¶ Decorate
mode.Service
to be started with the app.Examples
from mode import Service @app.service class Foo(Service): ...
Return type: Type
[ServiceT
[]]
-
stream
(channel: Union[typing.AsyncIterable, typing.Iterable], beacon: mode.utils.types.trees.NodeT = None, **kwargs) → faust.types.streams.StreamT[source]¶ Create new stream from channel/topic/iterable/async iterable.
Parameters: - channel (
Union
[AsyncIterable
[+T_co],Iterable
[+T_co]]) – Iterable to stream over (async or non-async). - kwargs (
Any
) – SeeStream
.
Return type: StreamT
[+T_co]Returns: to iterate over events in the stream.
Return type: - channel (
-
Table
(name: str, *, default: Callable[Any] = None, window: faust.types.windows.WindowT = None, partitions: int = None, help: str = None, **kwargs) → faust.types.tables.TableT[source]¶ Define new table.
Parameters: - name (
str
) – Name used for table, note that two tables living in the same application cannot have the same name. - default (
Optional
[Callable
[[],Any
]]) – A callable, or type that will return a default value for keys missing in this table. - window (
Optional
[WindowT
]) – A windowing strategy to wrap this window in.
Examples
>>> table = app.Table('user_to_amount', default=int) >>> table['George'] 0 >>> table['Elaine'] += 1 >>> table['Elaine'] += 1 >>> table['Elaine'] 2
Return type: TableT
[]- name (
-
page
(path: str, *, base: Type[faust.web.views.View] = <class 'faust.web.views.View'>) → Callable[Union[typing.Type[faust.types.web.View], typing.Callable[[faust.types.web.View, faust.types.web.Request], typing.Awaitable[faust.types.web.Response]]], Type[faust.web.views.Site]][source]¶ Return type: Callable
[[Union
[Type
[View
],Callable
[[View
,Request
],Awaitable
[Response
]]]],Type
[Site
]]
-
table_route
(table: faust.types.tables.CollectionT, shard_param: str) → Callable[Callable[[faust.types.web.View, faust.types.web.Request], Awaitable[faust.types.web.Response]], Callable[[faust.types.web.View, faust.types.web.Request], Awaitable[faust.types.web.Response]]][source]¶ Return type: Callable
[[Callable
[[View
,Request
],Awaitable
[Response
]]],Callable
[[View
,Request
],Awaitable
[Response
]]]
-
command
(*options, base: Union[typing.Type[faust.app.base.AppCommand], NoneType] = None, **kwargs) → Callable[Callable, Type[faust.app.base.AppCommand]][source]¶ Return type: Callable
[[Callable
],Type
[AppCommand
]]
-
FlowControlQueue
(maxsize: int = None, *, clear_on_resume: bool = False, loop: asyncio.events.AbstractEventLoop = None) → mode.utils.queues.ThrowableQueue[source]¶ Like
asyncio.Queue
, but can be suspended/resumed.Return type: ThrowableQueue
-
conf
¶
-
consumer
¶
-
transport
¶ Message transport. :rtype:
TransportT
-
coroutine
commit
(self, topics: AbstractSet[Union[str, faust.types.tuples.TP]]) → bool[source]¶ Commit offset for acked messages in specified topics’.
Warning
This will commit acked messages in all topics if the topics argument is passed in as
None
.Return type: bool
-
logger
= <Logger faust.app.base (WARNING)>¶
-
coroutine
maybe_start_client
(self) → None[source]¶ Start the app in Client-Only mode if not started as Server.
Return type: None
-
coroutine
on_stop
(self) → None[source]¶ Called every time before the service is stopped/restarted.
Return type: None
-
coroutine
send
(self, channel: Union[faust.types.channels.ChannelT, str], key: Union[bytes, faust.types.core.ModelT, typing.Any, NoneType] = None, value: Union[bytes, faust.types.core.ModelT, typing.Any] = None, partition: int = None, key_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, value_serializer: Union[faust.types.codecs.CodecT, str, NoneType] = None, callback: Callable[faust.types.tuples.FutureMessage, Union[NoneType, typing.Awaitable[NoneType]]] = None) → Awaitable[faust.types.tuples.RecordMetadata][source]¶ Send event to channel/topic.
Parameters: - channel (
Union
[ChannelT
[],str
]) – Channel/topic or the name of a topic to send event to. - key (
Union
[bytes
,ModelT
,Any
,None
]) – Message key. - value (
Union
[bytes
,ModelT
,Any
,None
]) – Message value. - partition (
Optional
[int
]) – Specific partition to send to. If not set the partition will be chosen by the partitioner. - key_serializer (
Union
[CodecT
,str
,None
]) – Serializer to use (if value is not model). - value_serializer (
Union
[CodecT
,str
,None
]) – Serializer to use (if value is not model). - callback (
Optional
[Callable
[[FutureMessage
[]],Union
[None
,Awaitable
[None
]]]]) –Called after the message is fully delivered to the channel, but not to the consumer. Signature must be unary as the
FutureMessage
future is passed to it.The resulting
faust.types.tuples.RecordMetadata
object is then available asfut.result()
.
Return type: - channel (
-
coroutine
start_client
(self) → None[source]¶ Start the app in Client-Only mode necessary for RPC requests.
Notes
Once started as a client the app cannot be restarted as Server.
Return type: None
-
topics
[source]¶ Topic Conductor.
This is the mediator that moves messages fetched by the Consumer into the streams.
It’s also a set of registered topics by string topic name, so you can check if a topic is being consumed from by doing
topic in app.topics
.
-
flow_control
[source]¶ Internal flow control.
This object controls flow into stream queues, and can also clear all buffers.
-
http_client
¶ HTTP Client Session. :rtype:
HttpClientT
-
router
[source]¶ Find the node partitioned data belongs to.
The router helps us route web requests to the wanted Faust node. If a topic is sharded by account_id, the router can send us to the Faust worker responsible for any account. Used by the
@app.table_route
decorator.
-
label
¶
-
shortlabel
¶
-