Skip to main content

faker-events

Generates Events with formatted fake data for streams.

NOTE Don't use this software for anything but exploring use cases. It is not tested, it is not quality controlled, and subject to breaking changes.

Usage

Using Faker Events is a library, and doesn't come with a CLI. This is in part due to the Events you create being written in Python as objects.

This library utilises the Faker package to generate it's data on the profile. Understanding how Faker works is recommended and you can find the documentation for it here.

Installation with Streams

pip install faker-events[kafka, kinesis]

Starting a Stream

Create an Event Generator and start using Live Stream. By default only 10 profiles are created. Giving large numbers can take sometime to build so becareful.

Set the "Events Per Minute" on the live_stream method to change the maximum allowed, but subject to system performance also. The default is ~60 per minute, but they are random so expect potentially lower rates.

Console

import faker_events

eg = faker_events.EventGenerator(num_profiles=100)
eg.live_stream(epm=120)

Output

{"type": "example", "event_id": 1, "user_id": 1609288, "first_name": "David", "last_name": "Herrera"}
{"type": "example", "event_id": 2, "user_id": 1609288, "first_name": "David", "last_name": "Herrera"}
{"type": "example", "event_id": 3, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
{"type": "example", "event_id": 4, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
{"type": "example", "event_id": 5, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
{"type": "example", "event_id": 6, "user_id": 1609288, "first_name": "David", "last_name": "Herrera"}
{"type": "example", "event_id": 7, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
{"type": "example", "event_id": 8, "user_id": 1609288, "first_name": "David", "last_name": "Herrera"}
{"type": "example", "event_id": 9, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
{"type": "example", "event_id": 10, "user_id": 500, "first_name": "Samantha", "last_name": "Sanchez"}
^C
Stopping Event Stream

Using Stream Handlers

By default the JSON messages are only displayed on the standard output. You can however create a stream handler to send the JSON messages to Kakfa, or Kinesis.

Kafka

import faker_events

example = faker_events.Stream(stype='kafka', host='kafka:9092', name='example')
eg = faker_events.EventGenerator(stream=example)
eg.live_stream()

Kinesis

import faker_events

example = faker_events.Stream(stype='kinesis', name='example', key='key')
eg = faker_events.EventGenerator(stream=example)
eg.live_stream()

Starting a Batch

Create an Event Generator and use the batch method, with a start and finish datetime object, and the frequncy like on the live stream.

from datetime import datetime, timedelta

import faker_events

eg = faker_events.EventGenerator(num_profiles=1)

start = datetime(2019, 1, 1)  # No one wants to relive 2020...
finish = start + timedelta(seconds=10)

eg.batch(start, finish, epm=10)

Data Points

Event Data Points

The Event Type has some basic data points about the event that can be used within the profiled method. (Access the Attribute using self)

  • event_id - The id of the particular event
  • event_time - The time the event occured (ISO Format)

Profile Data Points

When you create the Event Generator, the profiles you will use in the events are created with a number of data points. Below is a list of attributes that can be used on the 'profile' object within the EventType Profiled method.

  • id
  • uuid
  • username
  • gender
  • first_name
  • last_name
  • prefix_name
  • suffix_name
  • birthdate
  • blood_group
  • email
  • employer
  • job
  • full_address1
  • building_number1
  • street_name1
  • street_suffix1
  • state1
  • postcode1
  • city1
  • phone1
  • full_address2
  • building_number2
  • street_name2
  • street_suffix2
  • state2
  • postcode2
  • city2
  • phone2
  • driver_license
  • license_plate

Creating a Custom Record

Create an Event Type that has an 'event' dictionary. If you want values to be processed for each event, create a function called 'profiled', and thats takes a dict and returns an updated dict.

The profile is a randomly selected profile from the profiles created by the Event Generator. You can use details from the profile to build our events that simulate customers, or entities.

import faker
import faker_events

fake = faker.Faker()

class NewEvent(faker_events.EventType):
    event = {
        'Fixed': 'Doesnt Change',
        'Once': fake.color(),
        'Always': '',
        'Profiled': '',
    }

    def profiled(self, profile):
        new_details = {
            'Always': fake.boolean(),
            'Profiled': profile.email,
        }
        self.event.update(new_details)

eg = faker_events.EventGenerator(num_profiles=2)
eg.first_event = NewEvent()
eg.live_stream()

Event Sequences

You can sequence the events by setting the next event to occur, and occurence on how many times it will happen. If no limit is set, the next Event Type will never be used.

import faker_events

eg = faker_events.EventGenerator(num_profiles=1)

class EventA(faker_events.EventType):
    event = {'Name': 'A'}

class EventB(faker_events.EventType):
    event = {'Name': 'B'}

class EventC(faker_events.EventType):
    event = {'Name': 'C'}

a = EventA(1)
b = EventB(2)
c = EventC(1)

a.next = b
b.next = c

eg.first_event = a
eg.live_stream()

Output

{"Name": "A"}
{"Name": "B"}
{"Name": "B"}
{"Name": "C"}
Event limited reached.  4 in total generated

Using the Profile for Event State

If you need to update the details of the profile, or add persistant data from the events you can do so within the Profiled method of the EventType instance. When using sequenced events, the profile can be used to retrieve the data from previous events.

import faker_events

eg = faker_events.EventGenerator(num_profiles=1)

class EventA(faker_events.EventType):
    event = {'Name': 'A', 'LastEvent': 'none'}

    def profiled(self, profile):
        profile.LastEvent = self.__class__.__name__

class EventB(faker_events.EventType):
    event = {'Name': 'B', 'LastEvent': 'none'}

    def profiled(self, profile):
        self.event['LastEvent'] = profile.LastEvent
        profile.LastEvent = self.__class__.__name__

class EventC(faker_events.EventType):
    event = {'Name': 'C', 'LastEvent': 'none'}

    def profiled(self, profile):
        self.event['LastEvent'] = profile.LastEvent

a = EventA(1)
b = EventB(1)
c = EventC(1)

a.next = b
b.next = c

eg.first_event = a
eg.live_stream()

Output

{"Name": "A", "LastEvent": "none"}
{"Name": "B", "LastEvent": "EventA"}
{"Name": "C", "LastEvent": "EventB"}
Event limit reached.  3 in total generated

License

Faker-Events is released under the MIT License. See the bundled LICENSE file for details.

Credits

Metadata

Release files for faker-events 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for faker-events 0.0.1
File Size Uploaded Provenance Actions
Faker-Events-0.0.1.tar.gz 8.9 kB Without provenance Details for Faker-Events-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for faker-events 0.0.1
File Interpreter ABI Platform Actions
Faker_Events-0.0.1-py3-none-any.whl Python 3 none any Details for Faker_Events-0.0.1-py3-none-any.whl

Total release size: 18.4 kB

Release files / Faker-Events-0.0.1.tar.gz

Download URL Faker-Events-0.0.1.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cb2040267b624076959ae2f338ab61bcf69385d6227f1a8b466abc1c67978862
BLAKE2b-256 checksum
How to use checksums
20fd809b4f8071c2dc70e45b58cb61d47ee199216061d24bdf46abcacfddedd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Release files / Faker_Events-0.0.1-py3-none-any.whl

Download URL Faker_Events-0.0.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1921e4960761b0afc88549dfc151b2423fd6c789564312e52099782aff35e142
BLAKE2b-256 checksum
How to use checksums
c5f2f921df1199e000ebfb9d117e91a046cc11d4a94307c95e7a65cc9edc6bf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

Security for faker-events 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page