This guide provides best practices for designing clean, maintainable, and user-friendly schemas.
🤖 AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
frompyvider.schemaimporta_str,a_num"port":a_num(required=True,validators=[lambdax:1<=x<=65535or"Port must be 1-65535"],description="Server port number")"email":a_str(required=True,validators=[lambdax:"@"inxor"Invalid email address"],description="Contact email address")
"ip_address":a_str(computed=True,description="Public IP address assigned by the provider after creation")"created_at":a_str(computed=True,description="ISO 8601 timestamp of resource creation")
# Strings for identifiers"id":a_str()"vpc_id":a_str()# Numbers for quantities"port":a_num()"timeout_seconds":a_num()"replica_count":a_num()# Booleans for flags"enabled":a_bool()"auto_scaling":a_bool()# Lists for ordered collections"availability_zones":a_list(a_str())# Maps for key-value pairs"tags":a_map(a_str())"environment_variables":a_map(a_str())
"size":a_str(required=True,description="Instance size. Changing this forces replacement of the resource.")"region":a_str(required=True,description="AWS region. Cannot be changed after creation - forces replacement.")
"cidr_block":a_str(required=True,description="CIDR block for the VPC (e.g., '10.0.0.0/16')")"schedule":a_str(required=True,description="Cron expression for schedule (e.g., '0 2 * * *' for daily at 2am)")
# Bad: Forces users to provide everythings_resource({"field1":a_str(required=True),"field2":a_str(required=True),"field3":a_str(required=True),# ... 20 more required fields})
deftest_server_schema():schema=Server.get_schema()# Test required fieldsassert"name"inschema.attributesassertschema.attributes["name"].required# Test defaultsassertschema.attributes["port"].default==8080# Test descriptionsassert"Server port"inschema.attributes["port"].description