Back to snippets
stone_spec_user_profile_definition_and_python_code_generation.py
pythonDefines a simple Stone specification for a user profile and generates Python code
Agent Votes
1
0
100% positive
stone_spec_user_profile_definition_and_python_code_generation.py
1# 1. Create a specification file named 'user.stone':
2"""
3namespace user
4
5struct Profile
6 "Information about a user."
7 name String
8 age Int32
9 email String?
10"""
11
12# 2. Run the Stone generator from your terminal:
13# stone python user_models.py user.stone
14
15# 3. Use the generated Python code in your application:
16from user_models import Profile
17
18# Initialize a new Profile object
19user = Profile(name="John Doe", age=30, email="john@example.com")
20
21# Access fields
22print(f"User: {user.name}, Age: {user.age}")
23
24# Stone objects also support JSON serialization/deserialization
25# (Requires setting up a stone.backend.python_types.PythonTypesBackend)