Metadata-Version: 2.5
Name: faker-events
Version: 2.0.0
Summary: Generate realistic, stateful event streams without production data.
Project-URL: Source, https://github.com/johnbrandborg/faker-events
Project-URL: Issues, https://github.com/johnbrandborg/faker-events/issues
Author: John Brandborg
License: MIT License
        
        Copyright (c) 2020 johnbrandborg
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: events,faker,streaming,synthetic-data,testing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: croniter>=2.0
Requires-Dist: faker>=25.0
Requires-Dist: orjson>=3.10
Requires-Dist: pydantic>=2.7
Requires-Dist: typer>=0.12
Provides-Extra: all
Requires-Dist: boto3>=1.34; extra == 'all'
Requires-Dist: confluent-kafka>=2.5; extra == 'all'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: ty>=0.0.1a25; extra == 'dev'
Provides-Extra: kafka
Requires-Dist: confluent-kafka>=2.5; extra == 'kafka'
Provides-Extra: kinesis
Requires-Dist: boto3>=1.34; extra == 'kinesis'
Description-Content-Type: text/markdown

# Faker Events

[![CI](https://github.com/johnbrandborg/faker-events/actions/workflows/python-app.yml/badge.svg)](https://github.com/johnbrandborg/faker-events/actions/workflows/python-app.yml)
[![PyPI](https://img.shields.io/pypi/v/faker-events.svg)](https://pypi.org/project/faker-events/)
[![Python](https://img.shields.io/pypi/pyversions/faker-events.svg)](https://pypi.org/project/faker-events/)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=johnbrandborg_faker-events&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=johnbrandborg_faker-events)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=johnbrandborg_faker-events&metric=coverage)](https://sonarcloud.io/summary/new_code?id=johnbrandborg_faker-events)
[![License](https://img.shields.io/pypi/l/faker-events.svg)](https://github.com/johnbrandborg/faker-events/blob/main/LICENSE)

Generate realistic, stateful event streams for development, demos, load tests,
and data-pipeline validation—without copying production data.

Version 2 is a ground-up rewrite for Python 3.11+. It provides isolated
generator state, deterministic runs, validated configuration, async delivery,
virtual-time batches, cron schedules, and fast JSON serialization.

## Install

```shell
pip install faker-events
```

Install only the stream adapters you need:

```shell
pip install "faker-events[kafka]"
pip install "faker-events[kinesis]"
```

## Try it

The built-in example writes JSON Lines to stdout and progress to stderr:

```shell
faker-events run --profiles 10 --max-events 100 --seed 42
```

Persist generated entities across runs:

```shell
faker-events run --profiles 100 --profile-file profiles.json
```

Generate a historical batch without sleeping:

```shell
faker-events run \
  --start 2026-01-01T00:00:00+00:00 \
  --end 2026-01-02T00:00:00+00:00
```

## Define a flow

Create `checkout.py`:

```python
from typing import Any

from faker_events import (
    Event,
    EventContext,
    EventGenerator,
    GeneratorConfig,
    Output,
    Profile,
)


def build(
    profiles: list[Profile],
    output: Output,
    *,
    seed: int | None = None,
    max_events: int | None = None,
) -> EventGenerator:
    template: dict[str, Any] = {
        "type": "",
        "event_id": 0,
        "event_time": "",
        "customer_id": "",
        "total": 0,
    }

    def created(context: EventContext, profile: Profile) -> dict[str, Any]:
        return {
            "type": "cart.created",
            "event_id": context.id,
            "event_time": context.time.isoformat(),
            "customer_id": profile.id,
        }

    def checked_out(context: EventContext, profile: Profile) -> dict[str, Any]:
        return {
            "type": "cart.checked_out",
            "event_id": context.id,
            "event_time": context.time.isoformat(),
            "total": 99,
        }

    cart = Event(template, created, rate=120)
    checkout = Event(template, checked_out, rate=30)
    cart >> checkout

    return EventGenerator(
        profiles,
        cart,
        output=output,
        config=GeneratorConfig(seed=seed, max_events=max_events),
    )
```

Run it:

```shell
faker-events run checkout.py --profiles 10
```

Transforms may update `context.data` directly, return a mapping to merge, or
return `SKIP` to suppress delivery. Data is stateful per event and profile.
Use `event >> next_event` for a sequence and `event >> [a, b]` to branch.
`limit=0` repeats indefinitely.

## Scheduled events

Cron events run alongside flow events:

```python
snapshot = Event(
    {"type": "account.snapshot"},
    schedule="*/5 * * * *",
    limit=0,
)

generator = EventGenerator(profiles, [cart, snapshot], output=output)
```

Schedules also work in virtual-time batches and are emitted in timestamp order.

## Outputs

```python
from faker_events import KafkaOutput, KinesisOutput

kafka = KafkaOutput("events", "localhost:9092")
kinesis = KinesisOutput("events", partition_key=lambda event: event["customer_id"])
```

Custom outputs implement three async methods:

```python
class Output:
    async def open(self) -> None: ...
    async def send(self, event: dict) -> None: ...
    async def close(self) -> None: ...
```

The included Kinesis adapter batches records. The Kafka adapter uses
`confluent-kafka`/librdkafka and verifies delivery.

## Migration from 1.x

Version 2 intentionally removes global configuration:

- Pass profiles, first events, output, and config to `EventGenerator`.
- Await `run_live()` or `run_batch()` instead of calling `start()`.
- Use `rate` instead of `epm`; variance is a fraction from `0` to `1`.
- Use `schedule` instead of `cron`.
- Use `ConsoleOutput`, `KafkaOutput`, or `KinesisOutput` instead of `Stream`.
- Return `SKIP` instead of the string `"skip"`.
- User scripts expose a `build(...)` function instead of mutating class state.

These changes allow multiple independent generators to run safely in one
process.
