Skip to main content

A flexible synthetic data generation service

Project description

GlassGen

GlassGen is a flexible synthetic data generation service that can generate data based on user-defined schemas and send it to various destinations.

Features

  • Generate synthetic data based on custom schemas
  • Multiple output formats (CSV, Kafka, Webhook)
  • Configurable generation rate
  • Extensible sink architecture
  • CLI and Python SDK interfaces

Installation

pip install glassgen

Local Development Installation

  1. Clone the repository:
git clone https://github.com/glassflow/glassgen.git
cd glassgen
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
  1. Install the package in development mode:
pip install -e .
  1. Install development dependencies:
pip install -r requirements-dev.txt

Usage

Basic Usage

import glassgen
import json

# Load configuration from file
with open("config.json") as f:
    config = json.load(f)

# Start the generator
glassgen.generate(config=config)

Configuration File Format

{
    "schema": {
        "field1": "$generator_type",
        "field2": "$generator_type(param1, param2)"
    },
    "sink": {
        "type": "csv|kafka.aiven|kafka.confluent|webhook|yield",
        "params": {
            // sink-specific parameters
        }
    },
    "generator": {
        "rps": 1000,  // records per second
        "num_records": 5000  // total number of records to generate
    }
}

Supported Sinks

CSV Sink

{
    "sink": {
        "type": "csv",
        "params": {
            "path": "output.csv"
        }
    }
}

WebHook Sink

{
    "sink": {
        "type": "webhook",
        "params": {
            "url": "https://your-webhook-url.com",
            "headers": {
                "Authorization": "Bearer your-token",
                "Custom-Header": "value"
            },
            "timeout": 30  // optional, defaults to 30 seconds
        }
    }
}

Kafka Sink

GlassGen supports multiple Kafka sink types:

  1. Confluent Cloud
{
    "sink": {
        "type": "kafka.confluent",
        "params": {
            "bootstrap_servers": "your-confluent-bootstrap-server",
            "topic": "topic_name",
            "security_protocol": "SASL_SSL",
            "sasl_mechanism": "PLAIN",
            "username": "your-api-key",
            "password": "your-api-secret"
        }
    }
}
  1. Aiven Kafka
{
    "sink": {
        "type": "kafka.aiven",
        "params": {
            "bootstrap_servers": "your-aiven-bootstrap-server",
            "topic": "topic_name",
            "security_protocol": "SASL_SSL",
            "sasl.mechanisms": "SCRAM-SHA-256",
            "username": "username",
            "password": "password",
            "ssl_cafile": "path/to/ca.pem"
        }
    }
}

Yield Sink

Yield sink returns an iterator for the generated events

{
    "sink" : {
        "type": "yield"
    }
}

Usage

config = {
    "schema": {
        "name": "$name",        
        "email": "$email"
    },
    "sink": {
        "type": "yield"
    },
    "generator": {
        "rps": 100,
        "num_records": 1000
    }
}  

import glassgen
gen = glassgen.generate(config=config)
for item in gen:
    print(item)

Custom Sink

You can create your own sink by extending the BaseSink class:

from glassgen import generate
from glassgen.sinks import BaseSink
from typing import List

class PrintSink(BaseSink):
    def publish(self, data: str):
        print(data)
    
    def publish_bulk(self, data: List[str]):
        for d in data:
            self.publish(d)
    
    def close(self):
        pass

# Use your custom sink
config = {
    "schema": {
        "name": "$name",
        "email": "$email",
        "country": "$country",
        "id": "$uuid",        
    },    
    "generator": {
        "rps": 10,
        "num_records": 1000        
    }
}
generate(config, sink=PrintSink())

Supported Schema Generators

Basic Types

  • $string: Random string
  • $int: Random integer
  • $intrange(min,max): Random integer within specified range (e.g., $intrange(1,100) for numbers between 1 and 100)
  • $choice(value1,value2,...): Randomly picks one value from the provided list (e.g., $choice(red,blue,green) or $choice(1,2,3,4,5))
  • $datetime(format): Current timestamp in specified format (e.g., $datetime("%Y-%m-%d %H:%M:%S")). Default format is ISO format (e.g., "2024-03-15T14:30:45.123456")
  • $timestamp: Current Unix timestamp in seconds since epoch (e.g., 1710503445)
  • $boolean: Random boolean value
  • $uuid: Random UUID
  • $uuid4: Random UUID4
  • $float: Random floating point number
  • $price: Random price value with 2 decimal places (e.g., 99.99)

Personal Information

  • $name: Random full name
  • $email: Random email address
  • $company_email: Random company email
  • $user_name: Random username
  • $password: Random password
  • $phone_number: Random phone number
  • $ssn: Random Social Security Number

Location

  • $country: Random country name
  • $city: Random city name
  • $address: Random street address
  • $zipcode: Random zip code

Business

  • $company: Random company name
  • $job: Random job title
  • $url: Random URL

Other

  • $text: Random text paragraph
  • $ipv4: Random IPv4 address
  • $currency_name: Random currency name
  • $color_name: Random color name

Pre Defined Schema

You can use of of the pre-defined schema:

import glassgen
from glassgen.schema.user_schema import UserSchema

config = {
    "sink": {
        "type": "csv",
        "params": {
            "path": "output.csv"
        }
    },
    "generator": {
        "rps": 50,
        "num_records": 100
    }
}
# use the pre-defined UserSchema
glassgen.generate(config=config, schema=UserSchema())

Example Configuration

{
    "schema": {
        "name": "$name",
        "email": "$email",
        "country": "$country",
        "id": "$uuid",
        "address": "$address",
        "phone": "$phone_number",
        "job": "$job",
        "company": "$company"
    },
    "sink": {
        "type": "webhook",
        "params": {
            "url": "https://api.example.com/webhook",
            "headers": {
                "Authorization": "Bearer your-token"
            }
        }
    },
    "generator": {
        "rps": 1500,
        "num_records": 5000,
        "event_options": {
            "duplication": {
                "enabled": true,
                "ratio": 0.1,
                "key_field": "email",
                "time_window": "1h"
            }
        }
    }
}

Event Options

Duplication

GlassGen supports controlled event duplication to simulate real-world scenarios where the same event might be processed multiple times.

"event_options": {
    "duplication": {
        "enabled": true,        // Enable/disable duplication
        "ratio": 0.1,          // Target ratio of duplicates (0.0 to 1.0)
        "key_field": "email",  // Field to use for duplicate detection
        "time_window": "1h"    // Time window for duplicate detection
    }
}
  • enabled: Boolean to turn duplication on/off
  • ratio: Decimal value (0.0 to 1.0) representing the percentage of events that should be duplicates
  • key_field: Field name from the schema to use for identifying duplicates
  • time_window: String representing the time window for duplicate detection (e.g., "1h" for 1 hour, "30m" for 30 minutes)

The duplication feature:

  • Maintains the specified ratio across all generated events
  • Only considers events within the configured time window for duplication
  • Uses the specified key_field to identify potential duplicates
  • Ensures memory efficiency by automatically cleaning up old events

Creating a New Release

To create a new release:

  1. Make sure you have the release script installed:
pip install -e .
  1. Run the release script with the new version:
./scripts/release.py release 0.1.1

This will:

  • Update the version in pyproject.toml
  • Create a git tag
  • Push the changes
  • Trigger the GitHub Actions workflow to:
    • Build the package
    • Publish to PyPI
    • Create a GitHub release

The version must follow semantic versioning (X.Y.Z format).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glassgen-0.1.11.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glassgen-0.1.11-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file glassgen-0.1.11.tar.gz.

File metadata

  • Download URL: glassgen-0.1.11.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for glassgen-0.1.11.tar.gz
Algorithm Hash digest
SHA256 4f2a03d51cc02e553fae59a8bda89c057b16ee14dc82e1b7a009fac22231222e
MD5 1c658b76b3fb53a94ed13999222dd2aa
BLAKE2b-256 67b78c685db030e27e355276a659c15e45d35f7bbbe08d545ff3466cb27c1793

See more details on using hashes here.

File details

Details for the file glassgen-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: glassgen-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for glassgen-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 01be2edf635808c68d0bd8e9b99e5b13f7b44f4c898dbf57f592dbfda960fd06
MD5 f7b4da9f8610bccadfb68100e3c9d6ed
BLAKE2b-256 161cad95dc5cbda5565528a54d71c59a8e0b02a4785b8a72ce50b1224121fdae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page