<jupyter_start><jupyter_text>Consult this table of supported annotations:CollectionRecognized AnnotationsListList[ModelT]Sequence[ModelT]MutableSequence[ModelT]SetAbstractSet[ModelT]Set[ModelT]MutableSet[ModelT]TupleTuple[ModelT, ...]Tuple[ModelT, ModelT, str]MappingDict[KT, ModelT]Dict[ModelT, ModelT]Mapping[KT, ModelT]MutableMapping[KT, ModelT]<jupyter_code>from typing import List
import faust

class User(faust.Record):
    accounts: List[Account]
from typing import Mapping
import faust

class User(faust.Record):
    accounts: Mapping[str, Account]
# The best practice when creating model instances is to use keyword arguments, 
# but positional arguments are also supported!
import faust

class Point(faust.Record):
    x: int
    y: int

class XYZPoint(Point):
    z: int

point = XYZPoint(10, 20, 30)
assert (point.x, point.y, point.z) == (10, 20, 30)
from decimal import Decimal

class Asset(faust.Record):
    url: str
    type: str

class ImageAsset(Asset):
    type = 'image'

class VideoAsset(Asset):
    runtime_seconds: float
    type = 'video'

class Article(faust.Record, polymorphic_fields=True):
    assets: List[Asset]

class User(faust.Record):
    id: str
    first_name: str
    last_name: str

class Account(faust.Record):
    user: User
    balance: Decimal
        
user = User(
   id='07ecaebf-48c4-4c9e-92ad-d16d2f4a9a19',
   first_name='Franz',
   last_name='Kafka',
)
account = Account(
   user=user,
   balance='12.3',
)

from pprint import pprint
pprint(account.to_representation())
account.dumps(serializer='json')
account.asdict()
class Person(faust.Record):
    age: int
    name: str

p = Person(age="<NAME>", name="32")
p.validate()
import json
json.loads("""{"price": 30.0, "quantity":2.0, "user_id": "foo"}""")
from faust.models.fields import StringField


class Order(faust.Record):
    price: float
    quantity: float
    # when serializing the order, the field will be excluded
    user_id: str = StringField(required=True, exclude=True)
    
order2 = Order.loads(
    """{"price": 30.0, "quantity":2.0, "user_id": "foo"}""",
    serializer='json',
)
print(order2.user_id)
order = Order(price=30.0, quantity=2.0, user_id='foo')
print(order.user_id)
Order.from_data({"price": 30.0, "quantity":2.0, "user_id": "foo"})
order.dumps(serializer='json')
order.asdict()
from sanic.response import json
json(order.asdict())
import ujson
ujson.dumps(order.asdict())
from typing import Text, Any, List, Optional, Union, Dict
from sagas.listings.co_data import CoResult, CoData
from sagas.listings.co_intf import BaseConf, BaseCo
from datetime import datetime

class SimpleConf(BaseConf):
    id: int
    prefix = 'translate English to German'
    signup_ts: Optional[datetime] = None
    friends: List[int] = []
conf=SimpleConf(type='中文', id=1)
co=CoResult(code='ok', data=CoData(data=conf.json()))
print(co)
# ujson.dumps(co.dumps(serializer='json'))
ujson.dumps({'code':co.code, 'data':co.data.asdict()}, ensure_ascii=False)
co.dumps(serializer='json')
isinstance(co, dict)
from mode.utils.compat import want_bytes, want_str
want_str(co.dumps(serializer='json'))
dumps=lambda c: want_str(c.dumps(serializer='json'))
dumps(co)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13909774436090225, 'fraction_numerical': 0.017543859649122806, 'mean_word_length': 5.411646586345381, 'pattern_counts': {'":': 9, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '258447', 'license': 'Apache-2.0', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1114, 'n_words': 258, 'path': 'notebook/procs-faust-record.ipynb', 'repo_name': 'samlet/stack', 'size': '3198'}