Fields#

Fields are used to specify the data to generate, for example:

from synthwave import Event, field

class AccountCreated(Event):
   user_id = field.UUID()

   properties = field.Object(
      first_name=field.GivenName(),
      last_name=field.FamilyName(),
      age=field.Integer(13, 95),
      email_address=field.EmailAddress(),
      location=field.Location() | field.Null(0.2),
   )

Available Fields#

class synthwave.field.Array(field: Field, min_size=1, max_size=2)#

A field representing an an array of fields. Length of the generated array is random and controlled by the min_size and max_size parameters.

from synthwave import Event, field

class Example(Event):
    people = field.Array(
        field.Object(
            name=field.FullName(),
            age=field.Integer(0, 120)
        )
    )
    ids = field.Array(field.UUID())
Parameters:
  • field – Field to generate in the array

  • min_size – Minimum length of the generated array

  • max_size – Maximium length of the generated array

schema()#

Return a dictionary representing this fields schema

class synthwave.field.Decimal(low=0.0, high=100.0, precision='1.00', cast_to: type | None = None)#

Returns a random Decimal within a range low to high. Decimals are better able to represent values like prices compared to floats.

Defaults to return Decimals from 0 to 100

Parameters:
  • low – low bound for value, inclusive

  • high – high bound for value, inclusive

  • precision – string matching the precision you want for the decimal value

  • cast_to – a type (like str, float, etc.) for type casting

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.EmailAddress#

Returns a randomly chosen email address.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.FamilyName#

Returns random family name (“last name”, “surname”).

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Field#

Abstract base class for fields. Must implement a sample method to be included in event data.

abstract schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Float(low: float = 0.0, high: float = 100.0)#

Returns a random float within a range low to high.

Defaults to return floats from 0 to 100

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.FullName#

Returns a random full name.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.GivenName#

Returns a random given (“first”) name.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Integer(low: int = 0, high: int = 100)#

Returns a random integer within a range low to high.

Defaults to return integers from 0 to 100

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Location#

Returns a random city like "San Francisco, United States".

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Long(low: int = 0, high: int = 100)#

Returns a random integer within a range low to high, same as the Integer field, but designated as a ‘long’ type in the schema.

Defaults to return integers from 0 to 100

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Null(probability: float)#

A field representing None / Null values.

If used on its own, will always return None. Use with another field to sometimes return null values:

field.Location() | field.Null(0.2)

will return None as the field value 20% of the time.

schema()#

Returns a dictionary representing the field schema

class synthwave.field.Object(**kwargs)#

A field representing an object consisting of other fields.

from synthwave import Event, field

class Example(Event):
    properties = field.Object(
        prop1=field.Integer(),
        prop2=field.Float()
    )
schema()#

Returns a dictionary representing the field schema

class synthwave.field.OneOf(options: Sequence[OneOfType])#

Returns one of the options in the input sequence.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.SKU#

Returns a random string consisting of 8 alpha-numeric characters to be used as a SKU.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.Timestamp(start_time: datetime | None = None, end_time: datetime | None = None, as_datetime: bool = False, as_isoformat: bool = False)#

Returns a POSIX timestamp in UTC, as a float by default

Parameters:
  • start_time – (optional) datetime object designating the earliest time to be generated

  • end_time – (optional) datetime object designating the latest time to be generated

  • as_datetime – (optional) return the timestamp as a datetime object

If both start_time and end_time are left as None, the timestamp returned is the current time when generated.

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.URL(domain: str | None = None)#

Returns a random URL.

Parameters:

domain – Use to specify the URL domain

schema() dict#

Returns a dictionary representing the field schema

class synthwave.field.UUID(repeat_prob=0.0)#

Returns a UUID as a string.

Generated UUIDs are cached so they can be repeatedly returned. This is useful for simulating single users generating multiple events. The cache holds the 1000 most recently generated UUIDs.

Parameters:

repeat_prob – Probability to repeat a UUID.

schema() dict#

Returns a dictionary representing the field schema