holoscript 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
holoscript/__init__.py ADDED
@@ -0,0 +1,48 @@
1
+ """
2
+ HoloScript Python Bindings
3
+
4
+ Parse, validate, generate, and render HoloScript code from Python.
5
+ Perfect for AI agents like Grok to build VR experiences.
6
+ """
7
+
8
+ from holoscript.client import HoloScript
9
+ from holoscript.parser import parse, parse_holo, parse_hsplus
10
+ from holoscript.validator import validate, ValidationResult, ValidationError
11
+ from holoscript.generator import generate, generate_object, generate_scene
12
+ from holoscript.renderer import render, RenderResult
13
+ from holoscript.sharer import share, ShareResult
14
+ from holoscript.traits import list_traits, explain_trait, suggest_traits
15
+
16
+ __version__ = "1.0.0"
17
+ __all__ = [
18
+ # Main client
19
+ "HoloScript",
20
+
21
+ # Parsing
22
+ "parse",
23
+ "parse_holo",
24
+ "parse_hsplus",
25
+
26
+ # Validation
27
+ "validate",
28
+ "ValidationResult",
29
+ "ValidationError",
30
+
31
+ # Generation
32
+ "generate",
33
+ "generate_object",
34
+ "generate_scene",
35
+
36
+ # Rendering
37
+ "render",
38
+ "RenderResult",
39
+
40
+ # Sharing
41
+ "share",
42
+ "ShareResult",
43
+
44
+ # Traits
45
+ "list_traits",
46
+ "explain_trait",
47
+ "suggest_traits",
48
+ ]
holoscript/client.py ADDED
@@ -0,0 +1,266 @@
1
+ """
2
+ HoloScript Client - Main interface for HoloScript operations.
3
+ """
4
+
5
+ from typing import Optional, Dict, Any, List
6
+ import requests
7
+
8
+ from holoscript.parser import parse, parse_holo, parse_hsplus, ParseResult
9
+ from holoscript.validator import validate, ValidationResult
10
+ from holoscript.generator import generate_object, generate_scene, GenerateResult
11
+ from holoscript.renderer import render, RenderResult
12
+ from holoscript.sharer import share, ShareResult
13
+ from holoscript.traits import list_traits, explain_trait, suggest_traits
14
+
15
+
16
+ class HoloScript:
17
+ """
18
+ Main HoloScript client for AI agents and Python applications.
19
+
20
+ Example:
21
+ >>> hs = HoloScript()
22
+ >>> scene = hs.generate("a glowing crystal in a dark cave")
23
+ >>> if hs.validate(scene.code).valid:
24
+ ... share = hs.share(scene.code, platform="x")
25
+ ... print(share.playground_url)
26
+ """
27
+
28
+ DEFAULT_API_URL = "https://api.holoscript.dev"
29
+
30
+ def __init__(
31
+ self,
32
+ api_key: Optional[str] = None,
33
+ api_url: Optional[str] = None,
34
+ local_mode: bool = False
35
+ ):
36
+ """
37
+ Initialize HoloScript client.
38
+
39
+ Args:
40
+ api_key: Optional API key for remote rendering/services
41
+ api_url: Custom API URL (defaults to https://api.holoscript.dev)
42
+ local_mode: If True, use local parsing only (no remote calls)
43
+ """
44
+ self.api_key = api_key
45
+ self.api_url = api_url or self.DEFAULT_API_URL
46
+ self.local_mode = local_mode
47
+
48
+ self._session = requests.Session()
49
+ if api_key:
50
+ self._session.headers["Authorization"] = f"Bearer {api_key}"
51
+
52
+ # === Parsing ===
53
+
54
+ def parse(self, code: str, format: str = "auto") -> ParseResult:
55
+ """
56
+ Parse HoloScript code into an AST.
57
+
58
+ Args:
59
+ code: HoloScript source code
60
+ format: Format hint - "hs", "hsplus", "holo", or "auto"
61
+
62
+ Returns:
63
+ ParseResult with AST and any errors
64
+ """
65
+ if format == "holo" or (format == "auto" and "composition" in code):
66
+ return parse_holo(code)
67
+ else:
68
+ return parse_hsplus(code)
69
+
70
+ # === Validation ===
71
+
72
+ def validate(
73
+ self,
74
+ code: str,
75
+ include_warnings: bool = True,
76
+ include_suggestions: bool = True
77
+ ) -> ValidationResult:
78
+ """
79
+ Validate HoloScript code for errors.
80
+
81
+ Args:
82
+ code: HoloScript source code or ParseResult
83
+ include_warnings: Include warnings in result
84
+ include_suggestions: Include fix suggestions
85
+
86
+ Returns:
87
+ ValidationResult with errors, warnings, and suggestions
88
+ """
89
+ return validate(
90
+ code,
91
+ include_warnings=include_warnings,
92
+ include_suggestions=include_suggestions
93
+ )
94
+
95
+ # === Generation ===
96
+
97
+ def generate(
98
+ self,
99
+ description: str,
100
+ format: str = "holo",
101
+ style: str = "detailed"
102
+ ) -> GenerateResult:
103
+ """
104
+ Generate HoloScript code from natural language.
105
+
106
+ Args:
107
+ description: Natural language description of the scene
108
+ format: Output format - "hs", "hsplus", or "holo"
109
+ style: Style - "minimal", "detailed", or "production"
110
+
111
+ Returns:
112
+ GenerateResult with code and metadata
113
+ """
114
+ return generate_scene(description, format=format, style=style)
115
+
116
+ def generate_object(
117
+ self,
118
+ description: str,
119
+ format: str = "hsplus"
120
+ ) -> GenerateResult:
121
+ """
122
+ Generate a single object from description.
123
+
124
+ Args:
125
+ description: Natural language description of the object
126
+ format: Output format
127
+
128
+ Returns:
129
+ GenerateResult with object code
130
+ """
131
+ return generate_object(description, format=format)
132
+
133
+ # === Rendering ===
134
+
135
+ def render(
136
+ self,
137
+ code: str,
138
+ format: str = "png",
139
+ resolution: tuple = (800, 600),
140
+ camera_position: tuple = (0, 2, 5),
141
+ duration: int = 3000,
142
+ quality: str = "preview"
143
+ ) -> RenderResult:
144
+ """
145
+ Render HoloScript code to an image or video.
146
+
147
+ Args:
148
+ code: HoloScript source code
149
+ format: Output format - "png", "gif", "mp4", "webp"
150
+ resolution: (width, height) tuple
151
+ camera_position: (x, y, z) camera position
152
+ duration: Animation duration in ms (for gif/mp4)
153
+ quality: "draft", "preview", or "production"
154
+
155
+ Returns:
156
+ RenderResult with URL or base64 data
157
+ """
158
+ return render(
159
+ code,
160
+ format=format,
161
+ resolution=resolution,
162
+ camera_position=camera_position,
163
+ duration=duration,
164
+ quality=quality,
165
+ api_url=self.api_url if not self.local_mode else None,
166
+ api_key=self.api_key
167
+ )
168
+
169
+ # === Sharing ===
170
+
171
+ def share(
172
+ self,
173
+ code: str,
174
+ title: str = "HoloScript Scene",
175
+ description: str = "Interactive 3D scene built with HoloScript",
176
+ platform: str = "x"
177
+ ) -> ShareResult:
178
+ """
179
+ Create shareable links for the code.
180
+
181
+ Args:
182
+ code: HoloScript source code
183
+ title: Scene title
184
+ description: Scene description
185
+ platform: Target platform - "x", "generic", "codesandbox", "stackblitz"
186
+
187
+ Returns:
188
+ ShareResult with URLs and embed codes
189
+ """
190
+ return share(
191
+ code,
192
+ title=title,
193
+ description=description,
194
+ platform=platform
195
+ )
196
+
197
+ # === Traits ===
198
+
199
+ def list_traits(self, category: Optional[str] = None) -> Dict[str, List[str]]:
200
+ """
201
+ List available VR traits.
202
+
203
+ Args:
204
+ category: Filter by category (interaction, physics, visual, etc.)
205
+
206
+ Returns:
207
+ Dictionary of traits by category
208
+ """
209
+ return list_traits(category)
210
+
211
+ def explain_trait(self, trait: str) -> Dict[str, Any]:
212
+ """
213
+ Get detailed documentation for a trait.
214
+
215
+ Args:
216
+ trait: Trait name (with or without @)
217
+
218
+ Returns:
219
+ Trait documentation dictionary
220
+ """
221
+ return explain_trait(trait)
222
+
223
+ def suggest_traits(
224
+ self,
225
+ description: str,
226
+ context: Optional[str] = None
227
+ ) -> Dict[str, Any]:
228
+ """
229
+ Suggest appropriate traits for an object.
230
+
231
+ Args:
232
+ description: Object description
233
+ context: Additional context
234
+
235
+ Returns:
236
+ Suggested traits with reasoning
237
+ """
238
+ return suggest_traits(description, context)
239
+
240
+ # === Utility ===
241
+
242
+ def quick_test(self, code: str) -> Dict[str, Any]:
243
+ """
244
+ Quick test: parse, validate, and return summary.
245
+
246
+ Args:
247
+ code: HoloScript source code
248
+
249
+ Returns:
250
+ Dictionary with parse result, validation, and stats
251
+ """
252
+ parse_result = self.parse(code)
253
+ validation = self.validate(code)
254
+
255
+ return {
256
+ "parsed": parse_result.success,
257
+ "valid": validation.valid,
258
+ "errors": validation.errors,
259
+ "warnings": validation.warnings,
260
+ "stats": {
261
+ "lines": len(code.split("\n")),
262
+ "characters": len(code),
263
+ "objects": len(parse_result.objects) if hasattr(parse_result, "objects") else 0,
264
+ "traits": len(parse_result.traits) if hasattr(parse_result, "traits") else 0,
265
+ }
266
+ }