Package: nttai-faust-streaming
Python Stream Processing ForkInstallationpip install faust-streamingDocumentationintroduction:https://faust-streaming.github.io/faust/introduction.htmlquickstart:https://faust-streaming.github.io/faust/playbooks/quickstart.htmlUser Guide:https://faust-streaming.github.io/faust/userguide/index.htmlWhy the forkWe have decided to fork the originalFaustproject because there is a critical process of releasing new versions which causes uncertainty in the community. Everybody is welcome to contribute to thisfork, and you can be added as a maintainer.We want to:Ensure continues releaseCode qualityUse of latest versions of kafka drivers (for now onlyaiokafka)Support kafka transactionsUpdate the documentationand more...Usage# Python Streams# Forever scalable event processing & in-memory durable K/V store;# as a library w/ asyncio & static typing.importfaustFaustis a stream processing library, porting the ideas fromKafka Streamsto Python.It is used atRobinhoodto build high performance distributed systems
and real-time data pipelines that process billions of events every day.Faust provides bothstream processingandevent processing,
sharing similarity with tools such asKafka Streams,Apache Spark,Storm,Samza,Flink,It does not use a DSL, it's just Python!
This means you can use all your favorite Python libraries
when stream processing: NumPy, PyTorch, Pandas, NLTK, Django,
Flask, SQLAlchemy, ++Faust requires Python 3.6 or later for the newasync/await_ syntax,
and variable type annotations.Here's an example processing a stream of incoming orders:app=faust.App('myapp',broker='kafka://localhost')# Models describe how messages are serialized:# {"account_id": "3fae-...", amount": 3}classOrder(faust.Record):account_id:stramount:int@app.agent(value_type=Order)asyncdeforder(orders):asyncfororderinorders:# process infinite stream of orders.print(f'Order for{order.account_id}:{order.amount}')The Agent decorator defines a "stream processor" that essentially
consumes from a Kafka topic and does something for every event it receives.The agent is anasync deffunction, so can also perform
other operations asynchronously, such as web requests.This system can persist state, acting like a database.
Tables are named distributed key/value stores you can use
as regular Python dictionaries.Tables are stored locally on each machine using a super fast
embedded database written in C++, calledRocksDB.Tables can also store aggregate counts that are optionally "windowed"
so you can keep track
of "number of clicks from the last day," or
"number of clicks in the last hour." for example. LikeKafka Streams,
we support tumbling, hopping and sliding windows of time, and old windows
can be expired to stop data from filling up.For reliability, we use a Kafka topic as "write-ahead-log".
Whenever a key is changed we publish to the changelog.
Standby nodes consume from this changelog to keep an exact replica
of the data and enables instant recovery should any of the nodes fail.To the user a table is just a dictionary, but data is persisted between
restarts and replicated across nodes so on failover other nodes can take over
automatically.You can count page views by URL:# data sent to 'clicks' topic sharded by URL key.# e.g. key="http://example.com" value="1"click_topic=app.topic('clicks',key_type=str,value_type=int)# default value for missing URL will be 0 with `default=int`counts=app.Table('click_counts',default=int)@app.agent(click_topic)asyncdefcount_click(clicks):asyncforurl,countinclicks.items():counts[url]+=countThe data sent to the Kafka topic is partitioned, which means
the clicks will be sharded by URL in such a way that every count
for the same URL will be delivered to the same Faust worker instance.Faust supports any type of stream data: bytes, Unicode and serialized
structures, but also comes with "Models" that use modern Python
syntax to describe how keys and values in streams are serialized:# Order is a json serialized dictionary,# having these fields:classOrder(faust.Record):account_id:strproduct_id:strprice:floatquantity:float=1.0orders_topic=app.topic('orders',key_type=str,value_type=Order)@app.agent(orders_topic)asyncdefprocess_order(orders):asyncfororderinorders:# process each order using regular Pythontotal_price=order.price*order.quantityawaitsend_order_received_email(order.account_id,order)Faust is statically typed, using themypytype checker,
so you can take advantage of static types when writing applications.The Faust source code is small, well organized, and serves as a good
resource for learning the implementation ofKafka Streams.Learn more about Faust in theintroductionintroduction pageto read more about Faust, system requirements, installation instructions,
community resources, and more.or go directly to thequickstarttutorialto see Faust in action by programming a streaming application.then explore theUser Guidefor in-depth information organized by topic.Robinhood:http://robinhood.comasync/await:https://medium.freecodecamp.org/a-guide-to-asynchronous-programming-in-python-with-asyncio-232e2afa44f6Celery:http://celeryproject.orgKafka Streams:https://kafka.apache.org/documentation/streamsApache Spark:http://spark.apache.orgStorm:http://storm.apache.orgSamza:http://samza.apache.orgFlink:http://flink.apache.orgRocksDB:http://rocksdb.orgAerospike:https://www.aerospike.com/Apache Kafka:https://kafka.apache.orgLocal developmentClone the projectCreate a virtualenv:python3.7 -m venv venv && source venv/bin/activateInstall the requirements:./scripts/installRun lint:./scripts/lintRun tests:./scripts/testsFaust key pointsSimpleFaust is extremely easy to use. To get started using other stream processing
solutions you have complicated hello-world projects, and
infrastructure requirements.  Faust only requires Kafka,
the rest is just Python, so If you know Python you can already use Faust to do
stream processing, and it can integrate with just about anything.Here's one of the easier applications you can make::importfaustclassGreeting(faust.Record):from_name:strto_name:strapp=faust.App('hello-app',broker='kafka://localhost')topic=app.topic('hello-topic',value_type=Greeting)@app.agent(topic)asyncdefhello(greetings):asyncforgreetingingreetings:print(f'Hello from{greeting.from_name}to{greeting.to_name}')@app.timer(interval=1.0)asyncdefexample_sender(app):awaithello.send(value=Greeting(from_name='Faust',to_name='you'),)if__name__=='__main__':app.main()You're probably a bit intimidated by theasyncandawaitkeywords,
but you don't have to know howasyncioworks to use
Faust: just mimic the examples, and you'll be fine.The example application starts two tasks: one is processing a stream,
the other is a background thread sending events to that stream.
In a real-life application, your system will publish
events to Kafka topics that your processors can consume from,
and the background thread is only needed to feed data into our
example.Highly AvailableFaust is highly available and can survive network problems and server
crashes.  In the case of node failure, it can automatically recover,
and tables have standby nodes that will take over.DistributedStart more instances of your application as needed.FastA single-core Faust worker instance can already process tens of thousands
of events every second, and we are reasonably confident that throughput will
increase once we can support a more optimized Kafka client.FlexibleFaust is just Python, and a stream is an infinite asynchronous iterator.
If you know how to use Python, you already know how to use Faust,
and it works with your favorite Python libraries like Django, Flask,
SQLAlchemy, NTLK, NumPy, SciPy, TensorFlow, etc.BundlesFaust also defines a group ofsetuptoolsextensions that can be used
to install Faust and the dependencies for a given feature.You can specify these in your requirements or on thepipcommand-line by using brackets. Separate multiple bundles using the comma:pipinstall"faust[rocksdb]"pipinstall"faust[rocksdb,uvloop,fast,redis, aerospike]"The following bundles are available:Faust with extrasStorespip install faust[rocksdb]for usingRocksDBfor storing Faust table state.Recommended in production.pip install faust[aerospike]for usingAerospikefor storing Faust table state.Recommended if supportedAerospike ConfigurationAerospike can be enabled as the state store by specifyingstore="aerospike://"By default, all tables backed by Aerospike useuse_partitioner=Trueand generate changelog topic events similar
to a state store backed by RocksDB.
The following configuration options should be passed in as keys to the options parameter inTablenamespace: aerospike namespacettl: TTL for all KV's in the tableusername: username to connect to the Aerospike clusterpassword: password to connect to the Aerospike clusterhosts: the hosts parameter as specified in theaerospike clientpolicies: the different policies for read/write/scanspoliciesclient: a dict ofhostandpoliciesdefined aboveCachingfaust[redis]for usingRedisas a simple caching backend (Memcached-style).Codecsfaust[yaml]for using YAML and thePyYAMLlibrary in streams.Optimizationfaust[fast]for installing all the available C speedup extensions to Faust core.Sensorsfaust[datadog]for using theDatadogFaust monitor.faust[statsd]for using theStatsdFaust monitor.faust[prometheus]for using thePrometheusFaust monitor.Event Loopsfaust[uvloop]for using Faust withuvloop.faust[eventlet]for using Faust witheventletDebuggingfaust[debug]for usingaiomonitorto connect and debug a running Faust worker.faust[setproctitle]when thesetproctitlemodule is installed the Faust worker will use it to set a nicer process name inps/toplistings.vAlso installed with thefastanddebugbundles.Downloading and installing from sourceDownload the latest version of Faust fromhttps://pypi.org/project/faust-streaming/You can install it by doing:$tarxvfzfaust-streaming-0.0.0.tar.gz
$cdfaust-streaming-0.0.0
$pythonsetup.pybuild# python setup.py installThe last command must be executed as a privileged user if
you are not currently using a virtualenv.Using the development versionWith pipYou can install the latest snapshot of Faust using the followingpipcommand:pipinstallhttps://github.com/faust-streaming/faust/zipball/master#egg=faustFAQCan I use Faust with Django/Flask/etcYes! Useeventletas a bridge to integrate withasyncio.Using eventletThis approach works with any blocking Python library that can work witheventletUsingeventletrequires you to install thefaust-aioeventletmodule,
and you can install this as a bundle along with Faust:pipinstall-Ufaust[eventlet]Then to actually use eventlet as the event loop you have to either
use the-L <faust --loop>argument to thefaustprogram:faust-Leventlet-Amyprojworker-linfoor addimport mode.loop.eventletat the top of your entry point script:#!/usr/bin/env python3importmode.loop.eventlet# noqaIt's very important this is at the very top of the module,
and that it executes before you import libraries.Can I use Faust with TornadoYes! Use thetornado.platform.asynciobridgeCan I use Faust with TwistedYes! Use theasyncioreactor implementation:https://twistedmatrix.com/documents/current/api/twisted.internet.asyncioreactor.htmlWill you support Python 2.7 or Python 3.5No. Faust requires Python 3.7 or later, since it heavily uses features that were
introduced in Python 3.6 (async,await, variable type annotations).I get a maximum number of open files exceeded error by RocksDB when running a Faust app locally. How can I fix thisYou may need to increase the limit for the maximum number of open files.
On macOS and Linux you can use:ulimit -n max_open_filesto increase the open files limit to max_open_files.On docker, you can use the --ulimit flag:docker run --ulimit nofile=50000:100000 <image-tag>where 50000 is the soft limit, and 100000 is the hard limitSee the difference.What kafka versions faust supportsFaust supports kafka with version >= 0.10.Getting HelpSlackFor discussions about the usage, development, and future of Faust, please join thefauststreamSlack.https://fauststream.slack.comSign-up:https://join.slack.com/t/fauststream/shared_invite/enQtNDEzMTIyMTUyNzU2LTIyMjNjY2M2YzA2OWFhMDlmMzVkODk3YTBlYThlYmZiNTUwZDJlYWZiZTdkN2Q4ZGU4NWM4YWMyNTM5MGQ5OTgResourcesBug trackerIf you have any suggestions, bug reports, or annoyances please report them
to our issue tracker athttps://github.com/faust-streaming/faust/issues/LicenseThis software is licensed under theNew BSD License. See theLICENSEfile in the top distribution directory for the full license text.ContributingDevelopment ofFausthappens atGitHubYou're highly encouraged to participate in the development ofFaust.Code of ConductEveryone interacting in the project's code bases, issue trackers, chat rooms,
and mailing lists is expected to follow the Faust Code of Conduct.As contributors and maintainers of these projects, and in the interest of fostering
an open and welcoming community, we pledge to respect all people who contribute
through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.We are committed to making participation in these projects a harassment-free
experience for everyone, regardless of level of experience, gender,
gender identity and expression, sexual orientation, disability,
personal appearance, body size, race, ethnicity, age,
religion, or nationality.Examples of unacceptable behavior by participants include:The use of sexualized language or imageryPersonal attacksTrolling or insulting/derogatory commentsPublic or private harassmentPublishing other's private information, such as physical or electronic addresses, without explicit permissionOther unethical or unprofessional conduct.Project maintainers have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct. By adopting this Code of Conduct,
project maintainers commit themselves to fairly and consistently applying
these principles to every aspect of managing this project. Project maintainers
who do not follow or enforce the Code of Conduct may be permanently removed from
the project team.This code of conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project maintainers.