Field Types¶
Surety provides built-in field types for common data. All types inherit from
Field and are imported from the top-level surety package. Use these
types to define schemas (Dictionary subclasses).
Bool¶
Generates a random boolean value.
from surety import Bool
class FeatureFlag(Dictionary):
Enabled = Bool(name='enabled')
Visible = Bool(name='visible')
Int¶
Generates a random integer within configurable bounds.
from surety import Int
class Pagination(Dictionary):
Page = Int(name='page', min_val=1, max_val=500)
PerPage = Int(name='per_page', min_val=10, max_val=100)
Parameter |
Default |
Description |
|---|---|---|
|
|
Minimum value (inclusive). |
|
|
Maximum value (inclusive). |
Float¶
Generates a random float with control over integer and fractional digit lengths.
from surety import Float
class Measurement(Dictionary):
Temperature = Float(name='temperature', i_len=2, f_len=1,
min_val=-40, max_val=60)
WeightKg = Float(name='weight_kg', f_len=3, positive=True)
Parameter |
Default |
Description |
|---|---|---|
|
|
Max digits in the integer part. |
|
|
Max digits in the fractional part. |
|
|
Minimum value. |
|
|
Maximum value. |
|
|
If |
Decimal and StringDecimal¶
Decimal works like Float but returns a decimal.Decimal value — ideal
for money or precision-sensitive fields.
StringDecimal formats the decimal as a string with fixed fractional digits
(e.g. "14.50").
from surety import Decimal, StringDecimal
class InvoiceLine(Dictionary):
Amount = Decimal(name='amount', i_len=4, f_len=2, positive=True)
FormattedAmount = StringDecimal(name='formatted_amount', f_len=2)
Decimal provides a static helper to wrap existing values:
Field = Decimal.from_value("29.95")
print(field.value) # Decimal('29.95')
String¶
Generates a random string. When the field name matches a Faker provider
method (e.g. email, city, phone_number), realistic data is produced
automatically.
from surety import String
class Contact(Dictionary):
Email = String(name='email') # Faker-generated email
City = String(name='city') # Faker-generated city
Nickname = String(name='nickname', min_len=3, max_len=20)
Use fake_as to explicitly select a Faker provider regardless of the field
name. Pass a method from the fake instance (recommended) or a provider
name string:
from surety.sdk.fakeable import fake
class Profile(Dictionary):
Handle = String(name='handle', fake_as=fake.user_name)
Bio = String(name='bio', fake_as=fake.sentence, max_len=200)
Brand = String(name='brand', fake_as=fake.company)
# String provider names also work
class Profile(Dictionary):
Handle = String(name='handle', fake_as='user_name')
Parameter |
Default |
Description |
|---|---|---|
|
|
Minimum string length. |
|
|
Maximum string length (truncated if exceeded). |
|
|
Faker provider — a callable (e.g. |
Uuid¶
Generates a UUID v4 string.
from surety import Uuid
class Session(Dictionary):
SessionId = Uuid(name='session_id')
TraceId = Uuid(name='trace_id')
DateTime¶
Generates a random UTC datetime. The output format is configurable.
from surety import DateTime
from surety.sdk.dates import Pattern
class Event(Dictionary):
CreatedAt = DateTime(name='created_at')
DateOnly = DateTime(name='date_only', date_format=Pattern.DATE)
Available format patterns:
Pattern.DATE # '%Y-%m-%d'
Pattern.TIME # '%H:%M:%S'
Pattern.DATETIME # '%Y-%m-%d %H:%M:%S'
Pattern.DATETIME_DELIM_T # '%Y-%m-%dT%H:%M:%S'
Pattern.DATETIME_DELIM_T_WITH_ZONE # '%Y-%m-%dT%H:%M:%SZ'
Pattern.DATETIME_DELIM_T_WITH_ZONE_PRECISED # '%Y-%m-%dT%H:%M:%S.%fZ'
DateTime fields support timezone conversion:
event = Event()
est_value = event.CreatedAt.to_format(
Pattern.DATETIME_DELIM_T_WITH_ZONE, new_tz='US/Eastern'
)
Raw¶
Generates an unstructured dictionary of random string key-value pairs. Useful for metadata or freeform fields.
from surety import Raw
class Audit(Dictionary):
Metadata = Raw(name='metadata')
Calling with_values on a Raw field that already has a value merges
the new values into the existing dictionary rather than replacing it.
Enum¶
Subclass Enum and define class-level attributes for each allowed value:
from surety import Enum
class OrderStatus(Enum):
Pending = 'pending'
Confirmed = 'confirmed'
Shipped = 'shipped'
Delivered = 'delivered'
Cancelled = 'cancelled'
class Order(Dictionary):
Status = OrderStatus(name='status')
# Exclude specific values during generation
class ActiveOrder(Dictionary):
Status = OrderStatus(name='status', exclude=(OrderStatus.Cancelled,))
Use to_list() to get all possible values:
OrderStatus.to_list()
# ['pending', 'confirmed', 'shipped', 'delivered', 'cancelled']
OrderStatus.to_list(exclude=('OrderStatus.Cancelled',))
# ['pending', 'confirmed', 'shipped', 'delivered']
Faker Providers¶
The String field auto-detects Faker providers by name or fake_as.
The fake object from surety.sdk.fakeable is a string-only Faker wrapper
— every method call returns a str, regardless of what the underlying Faker
provider returns. Use its methods directly as fake_as values or call them
standalone.
from surety.sdk.fakeable import fake
fake.email() # 'j.smith@example.com'
fake.calories() # '312 kcal'
fake.unit_code() # 'KG'
People & contact
Provider |
Example Output |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Address
Fields whose names end in _line1, _line2, or _line3 (e.g.
addressLine1, billingAddressLine2) are automatically mapped to address
providers.
Provider |
Example Output |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Units of measure
Provider |
Example Output |
|---|---|
|
|
|
|
Available units: Bottle (BOT), Box (BOX), Can (CAN), Case (CS), Feet (FT), Gallon (GA), Gram (GR), Inches (IN), Kilogram (KG), Pounds (LB), Liter (LTR), Milliliter (ML), Millimeter (MM), Meter (MTR), Ounces (OZ), Pieces (PCS).
Nutrition
Each method returns a number with its unit as a string.
Provider |
Example Output |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Other commonly used providers
Provider |
Example Output |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
The full Faker library is available — any faker provider method works with
fake_as or can be called directly via fake.<provider>().
Semantic auto-detection
Fields with common semantic names resolve automatically without fake_as:
Field name |
Resolved provider |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|