Skip to content

Instantly share code, notes, and snippets.

@Stiivi
Created March 20, 2012 18:37
Show Gist options
  • Save Stiivi/2139451 to your computer and use it in GitHub Desktop.
Save Stiivi/2139451 to your computer and use it in GitHub Desktop.
Generator Function Source Node in Brewery
"""
Data Brewery - http://databrewery.org
Example: How to use a generator function as a streaming data source.
"""
import brewery
import random
# Create a generator function
def generator(count=10, low=0, high=100):
for i in range(0, count):
yield [i, random.randint(low, high)]
# Create stream builder (HOM-based)
main = brewery.create_builder()
main.generator_function_source(generator, fields=brewery.FieldList(["i", "roll"]))
# Configure node with this:
# main.node.kwargs = {"count":100, "high":10}
# Uncomment this:
# fork = main.fork()
# fork.csv_target("random.csv")
main.formatted_printer()
main.stream.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment