Python API Reference¶
This page documents the main public Python API exposed by SpecStar.
Use it as a practical map of the stable entry points and supported imports. The generated API browser below is useful as a deeper lookup once you know which symbol family you need.
How to use this page¶
If you are new to the library, start with the summary sections below and treat them as the preferred public surface.
In general:
- import from
specstarwhen possible for onboarding-friendly entry points - import exception families from
specstar.errors - prefer the names listed on this page over internal implementation modules
- use the autogenerated section as a detailed lookup tool after you understand the high-level groups
Recommended entry points¶
Most applications start with one of these two patterns:
Global instance pattern¶
from fastapi import FastAPI
from specstar import spec
app = FastAPI()
spec.add_model(User)
spec.apply(app)
Use this when you want a simple application-wide SpecStar instance.
Manual instance pattern¶
Use this when you want separate instances with different configuration.
Public API groups¶
Core setup¶
SpecStar— main entry point for model registration and route generationspec— pre-created global instance for simple usageLoadStats— summary information returned by bulk load operations
Schema and model conversion¶
Schema— declare schema versions, migration steps, and validatorspydantic_to_struct— convert Pydantic models into SpecStar-compatible struct typesstruct_to_pydantic— convert SpecStar struct types to Pydantic models when needed
Relationships and lifecycle helpers¶
Ref,RefRevision,RefType— declare resource relationshipsUnique— declare unique fields or constraintsOnDelete— configure deletion behavior for referenced resourcesOnDuplicate— define how import or bulk load handles duplicatesDisplayName— provide readable labels for resources or fields
Search and operations¶
QB— high-level query builder for indexed fields and metadataSearchedResource— typed search result container
Interfaces¶
IConstraintChecker— custom constraint hook interfaceIValidator— custom validation interface
Public exceptions¶
Import these from specstar.errors rather than relying on internal modules.
ValidationError— custom validator or business-rule failureUniqueConstraintError— unique-field collisionDuplicateResourceError— duplicate during load or import flowRevisionNotMigratedError— revision/schema mismatch when switching historyMissingOperationContextError— write methods were called without requireduserornowcontext
Async and blob-related types¶
BackgroundTaskAccepted— response type for background task submissionBlobUploadSession— upload-session metadata for blob workflowsJob— typed job payload model for async queue workflowsTaskStatus— enum for polling async job state such as pending, processing, completed, and failedJobRedirectInfo— redirect payload for job-style async actions
Curated advanced namespaces¶
specstar.resource_manager— ResourceManager, ResourceOps, storage factories, encoding, and storage interfacesspecstar.permission— permission helpers, checkers, and action enumsspecstar.events— event hook interfaces and builder helpersspecstar.errors— canonical public exception families for cleaner error handling
Where to go next¶
- For usage patterns, start with the quickstart guides.
- For API shape and endpoints, inspect your generated OpenAPI docs.
- For route behavior, see the behavior and constraints references.
Auto-generated reference¶
specstar¶
specstar
¶
Attributes¶
__all__
module-attribute
¶
__all__ = [
"BackendBinding",
"BackendConfig",
"BackendDefaults",
"BackgroundTaskAccepted",
"BlobUploadSession",
"ConnectionProfile",
"DisplayName",
"IConstraintChecker",
"IValidator",
"Job",
"JobRedirectInfo",
"LoadStats",
"OnDelete",
"OnDuplicate",
"QB",
"Ref",
"RefRevision",
"RefType",
"Schema",
"SearchedResource",
"SpecStar",
"TaskStatus",
"Unique",
"spec",
"register_backend_provider",
"pydantic_to_struct",
"struct_to_pydantic",
]
Classes¶
BackendBinding
¶
Bases: Struct
Map one backend role to either a named connection or an inline provider.
Bindings are used for the four SpecStar backend concerns: metadata, structured resource payloads, blob storage, and the message queue.
Source code in specstar/backend.py
Attributes¶
BackendConfig
¶
Bases: Struct
Schema-first unified backend configuration for SpecStar.
This higher-level API lets you configure metadata, resource, blob, and message-queue backends together through one typed object, a plain mapping, or a JSON file.
Source code in specstar/backend.py
Attributes¶
defaults
class-attribute
instance-attribute
¶
defaults: BackendDefaults = field(
default_factory=BackendDefaults
)
connections
class-attribute
instance-attribute
¶
connections: dict[str, ConnectionProfile] = field(
default_factory=dict
)
meta
class-attribute
instance-attribute
¶
meta: BackendBinding = field(
default_factory=lambda: BackendBinding(type="memory")
)
resource
class-attribute
instance-attribute
¶
resource: BackendBinding = field(
default_factory=lambda: BackendBinding(type="memory")
)
blob
class-attribute
instance-attribute
¶
blob: BackendBinding = field(
default_factory=lambda: BackendBinding(type="memory")
)
Functions¶
from_json_file
classmethod
¶
from_value
classmethod
¶
Source code in specstar/backend.py
BackendDefaults
¶
Bases: Struct
Shared defaults applied across unified backend configuration.
These values provide the common baseline for backend providers created
through BackendConfig. Individual connection profiles or role bindings
may still supply provider-specific options to override the shared defaults
when needed.
Source code in specstar/backend.py
ConnectionProfile
¶
Bases: Struct
Reusable named backend connection.
A connection profile defines a backend type plus its provider-specific
options once, then lets multiple backend roles reuse that definition by
referring to it from BackendBinding(use=...).
Source code in specstar/backend.py
LoadStats
¶
Per-model statistics returned by :meth:SpecStar.load.
Source code in specstar/crud/core.py
SpecStar
¶
High-level entry point for registering resource models and generating CRUD routes.
SpecStar manages a set of per-resource ResourceManagers and applies a set of
route templates to a FastAPI APIRouter (or FastAPI app) to generate endpoints.
Typical setup:
from fastapi import FastAPI
from specstar import spec # global instance
app = FastAPI()
# configure once at startup (optional)
spec.configure(model_naming="kebab")
# register models/schemas
spec.add_model(User)
spec.add_model(Post)
# generate routes
spec.apply(app)
Notes:
- Call configure() / add_model() during application startup, before serving requests.
- apply() installs route templates, custom create/update actions, ref routes, and backup routes.
- openapi() customizes OpenAPI schema to include SpecStar-specific schemas and extensions.
| PARAMETER | DESCRIPTION |
|---|---|
model_naming
|
How model names are converted to resource names (URL paths). Either one of:
TYPE:
|
route_templates
|
Route templates to apply. When
TYPE:
|
backend
|
Higher-level unified backend configuration. Accepts a typed config object, a plain dict, or a JSON file path. This is the easiest way to configure metadata, resource, blob, and message-queue backends together.
TYPE:
|
storage_factory
|
Lower-level storage factory for models that don't specify
TYPE:
|
message_queue_factory
|
Lower-level message queue factory used for Job models (when enabled).
TYPE:
|
admin
|
If provided and
TYPE:
|
permission_checker
|
Permission checker used by default for models that don't override it.
TYPE:
|
dependency_provider
|
Dependency injection provider passed to route templates (when using defaults).
TYPE:
|
event_handlers
|
Global event handlers used by default for models that don't override it.
TYPE:
|
encoding
|
Default encoding for stored payloads (e.g. json/msgpack).
TYPE:
|
default_user
|
Default user (or factory) used when user is not specified.
When set, the
TYPE:
|
default_now
|
Default timestamp function used when time is not specified.
TYPE:
|
default_status
|
Default revision status applied when registering models via
:meth:
TYPE:
|
strict_operation_context
|
When
TYPE:
|
See also
Schema: declare schema/validation/migration for a resource.Ref,RefRevision: reference types used across APIs and OpenAPI schema.dump(),load(): export/import utilities for backups.- Routes: docs/howto/routes.md
- Behavior & lifecycle: docs/reference/behavior.md
- Performance notes: docs/guides/performance.md
Source code in specstar/crud/core.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 | |
Attributes¶
resource_managers
instance-attribute
¶
message_queues
instance-attribute
¶
Functions¶
configure
¶
configure(
*,
model_naming: Literal[
"same", "pascal", "camel", "snake", "kebab"
]
| Callable[[type], str]
| UnsetType = UNSET,
route_templates: list[IRouteTemplate]
| dict[type, dict[str, Any]]
| UnsetType = UNSET,
backend: BackendConfig
| dict[str, Any]
| str
| Path
| None
| UnsetType = UNSET,
storage_factory: IStorageFactory
| None
| UnsetType = UNSET,
message_queue_factory: IMessageQueueFactory
| None
| UnsetType = UNSET,
admin: str | None | UnsetType = UNSET,
permission_checker: IPermissionChecker
| UnsetType = UNSET,
dependency_provider: DependencyProvider
| UnsetType = UNSET,
event_handlers: Sequence[IEventHandler]
| UnsetType = UNSET,
encoding: Encoding | UnsetType = UNSET,
default_user: str
| Callable[[], str]
| UnsetType = UNSET,
default_now: Callable[[], datetime] | UnsetType = UNSET,
default_status: RevisionStatus | UnsetType = UNSET,
strict_operation_context: bool | UnsetType = UNSET,
) -> None
Configure the SpecStar instance dynamically.
This method allows you to reconfigure an existing SpecStar instance, useful for the global instance pattern where you import a pre-created instance and configure it later in your application startup.
Warning
This method should only be called during application initialization, before any models are registered or routes are applied. Calling this after models have been registered may lead to inconsistent behavior.
| PARAMETER | DESCRIPTION |
|---|---|
model_naming
|
Controls how model names are converted to URL paths.
TYPE:
|
route_templates
|
Custom list of route templates or configuration dict.
TYPE:
|
backend
|
Unified backend configuration. Accepts a typed config object, a plain dict, or a JSON file path.
TYPE:
|
storage_factory
|
Lower-level storage backend to use for all models.
This path offers more direct control than the unified
TYPE:
|
message_queue_factory
|
Lower-level message queue factory for async job processing.
TYPE:
|
admin
|
Admin user for RBAC permission system.
TYPE:
|
permission_checker
|
Custom permission checker implementation.
TYPE:
|
dependency_provider
|
Dependency injection provider for routes.
TYPE:
|
event_handlers
|
List of event handlers for lifecycle hooks.
TYPE:
|
encoding
|
Default encoding format (json/msgpack).
TYPE:
|
default_user
|
Default user for operations when not specified. When set,
the
TYPE:
|
default_now
|
Default timestamp function for operations.
TYPE:
|
default_status
|
Default revision status applied when registering models
via :meth:
TYPE:
|
strict_operation_context
|
When
TYPE:
|
Example
from specstar import BackendBinding, BackendConfig, ConnectionProfile, spec
# Configure the global instance with the higher-level backend API
spec.configure(
backend=BackendConfig(
connections={
"local": ConnectionProfile(
type="disk",
options={"rootdir": "./data"},
)
},
meta=BackendBinding(use="local"),
resource=BackendBinding(use="local"),
blob=BackendBinding(use="local"),
),
model_naming="snake",
admin="root@example.com",
)
# Now register models
spec.add_model(User)
Source code in specstar/crud/core.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
get_resource_manager
¶
Get the resource manager for a registered model.
This method allows you to access the underlying ResourceManager for a specific model. The ResourceManager provides low-level access to storage, events, and other internal components for that model.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The model class or its registered resource name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
IResourceManager[T]
|
The IResourceManager instance associated with the model. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the model is not registered. |
ValueError
|
If the model class is registered with multiple names (ambiguous). |
Example
Source code in specstar/crud/core.py
add_route_template
¶
Add a custom route template to extend the API with additional endpoints.
Route templates define how to generate specific API endpoints for models. By adding custom templates, you can extend the default CRUD functionality with specialized endpoints for your use cases.
If a template of the same type already exists (e.g. added by the
default configure()), it is replaced rather than duplicated.
This prevents Duplicate Operation ID warnings for templates that
mount global routes such as BlobRouteTemplate and
GraphQLRouteTemplate.
| PARAMETER | DESCRIPTION |
|---|---|
template
|
A custom route template implementing IRouteTemplate interface.
TYPE:
|
Example
class CustomSearchTemplate(BaseRouteTemplate):
def apply(self, model_name, resource_manager, router):
@router.get(f"/{model_name}/search")
async def search_resources(query: str):
# Custom search logic
pass
specstar = SpecStar()
specstar.add_route_template(CustomSearchTemplate())
specstar.add_model(User)
Note
Templates are sorted by their order property before being applied. Add templates before calling add_model() or apply() for best results.
Source code in specstar/crud/core.py
create_action
¶
create_action(
resource_name: str,
*,
path: str | None = None,
label: str | None = None,
async_mode: Literal["job", "background"] | None = None,
job_name: str | None = None,
) -> Callable
Decorator to register a custom create action for a resource.
The decorated function is a standard FastAPI endpoint handler — all input
parsing (Body, Query, Path, Depends, etc.) is handled by
FastAPI. If the handler returns a resource-type object, SpecStar will
automatically call resource_manager.create() and respond with
RevisionInfo. If it returns None, no automatic creation occurs.
When async_mode='job' is set, the framework automatically:
- Generates a
Jobmodel with the handler's body type as payload. - Registers the Job model with a message queue.
- On POST, creates a Job instance (PENDING) and enqueues it.
- Returns HTTP 202 with :class:
~specstar.types.JobRedirectInfo. - In the background, executes the handler with the payload.
- If the handler returns a resource object, auto-creates it and
stores the
RevisionInfoas the Job's artifact.
When async_mode='background' is set, the framework:
- On POST, schedules the handler via FastAPI
BackgroundTasks. - Returns HTTP 202 with :class:
~specstar.types.BackgroundTaskAcceptedimmediately. - The handler runs in the background; if it returns a resource object,
resource_manager.create()is called automatically. - No Job model is created — the task is fire-and-forget.
- Errors are logged but not surfaced to the client.
This mode is suitable for tasks that take a few seconds to complete and do not require progress tracking.
| PARAMETER | DESCRIPTION |
|---|---|
resource_name
|
The name of the resource this action belongs to.
TYPE:
|
path
|
URL path suffix (e.g.
TYPE:
|
label
|
Human-friendly label shown in the UI. If
TYPE:
|
async_mode
|
Execution mode for the action.
TYPE:
|
job_name
|
Custom resource name for the auto-generated Job model
(e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A decorator that registers the handler and returns it unchanged. |
Example
class ImportFromUrl(Struct):
url: str
@spec.create_action("article", label="Import from URL")
async def import_from_url(body: ImportFromUrl = Body(...)):
content = await fetch_and_parse(body.url)
return Article(content=content) # auto-created
class GenerateRequest(Struct):
prompt: str
@spec.create_action("article", async_mode="job", label="Generate")
def generate_article(payload: GenerateRequest = Body(...)) -> Article:
content = call_llm(payload.prompt) # long-running
return Article(content=content) # auto-created in background
Note
This decorator is lazy — it stores metadata without registering any
route. Routes are created when apply() is called, so the
decorator can be used before or after add_model().
Source code in specstar/crud/core.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
update_action
¶
update_action(
resource_name: str,
*,
path: str | None = None,
label: str | None = None,
mode: Literal["update", "modify"] = "update",
existing_param: str = "existing",
info_param: str = "info",
meta_param: str = "meta",
async_mode: Literal["job", "background"] | None = None,
job_name: str | None = None,
) -> Callable
Decorator to register a custom update action for a resource.
The decorated function receives the existing resource data (auto-injected)
and any custom input parameters. If the handler returns a resource-type
object, SpecStar will automatically call resource_manager.update() (or
resource_manager.modify() when mode='modify') and respond with
RevisionInfo. If it returns None, no update occurs.
The existing resource data is automatically fetched via
resource_manager.get(resource_id) and injected into the handler
parameter named by existing_param (default "existing").
Similarly, the handler may declare parameters named info_param
(default "info") and meta_param (default "meta") to
receive the existing resource's RevisionInfo and ResourceMeta
respectively. Like existing_param, these are detected by
parameter name and only injected when the handler declares them.
When async_mode='job' is set, the framework automatically:
- Generates a
Jobmodel with the handler's body type as payload (plus an auto-injectedresource_idfield). - Registers the Job model with a message queue.
- On POST, creates a Job instance (PENDING) and enqueues it.
- Returns HTTP 202 with :class:
~specstar.types.JobRedirectInfo. - In the background, fetches existing resource (lazy), executes the handler with the payload and existing data.
- If the handler returns a resource object, auto-updates it and
stores the
RevisionInfoas the Job's artifact.
When async_mode='background' is set, the framework:
- On POST, schedules the handler via FastAPI
BackgroundTasks. - Returns HTTP 202 with :class:
~specstar.types.BackgroundTaskAcceptedimmediately. - The handler runs in the background; if it returns a resource object,
resource_manager.update()(ormodify()) is called automatically. - No Job model is created — the task is fire-and-forget.
- Errors are logged but not surfaced to the client.
| PARAMETER | DESCRIPTION |
|---|---|
resource_name
|
The name of the resource this action belongs to.
TYPE:
|
path
|
URL path suffix (e.g.
TYPE:
|
label
|
Human-friendly label shown in the UI. If
TYPE:
|
mode
|
Update mode.
TYPE:
|
existing_param
|
The handler parameter name into which the
existing resource data will be injected. Defaults to
TYPE:
|
info_param
|
The handler parameter name into which the
existing resource's
TYPE:
|
meta_param
|
The handler parameter name into which the
existing resource's
TYPE:
|
async_mode
|
Execution mode for the action.
TYPE:
|
job_name
|
Custom resource name for the auto-generated Job model
(e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A decorator that registers the handler and returns it unchanged. |
Example
class LevelUpInput(Struct):
levels: int = 1
@spec.update_action("character", label="Level Up")
def level_up(
existing: Character,
body: LevelUpInput = Body(...),
) -> Character:
return Character(
name=existing.name,
level=existing.level + body.levels,
)
@spec.update_action(
"character",
label="Train",
async_mode="job",
)
def train(
existing: Character,
body: LevelUpInput = Body(...),
) -> Character:
import time
time.sleep(10) # long-running training
return Character(
name=existing.name,
level=existing.level + body.levels,
)
@spec.update_action(
"character",
label="Background Heal",
async_mode="background",
)
def bg_heal(existing: Character) -> Character:
import time
time.sleep(5)
return Character(name=existing.name, level=existing.level + 1)
Note
This decorator is lazy — it stores metadata without registering any
route. Routes are created when apply() is called.
The route is POST /{resource_name}/{resource_id}/{action_path}.
Source code in specstar/crud/core.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
add_model
¶
add_model(
model: "type[T] | Schema[T]",
*,
name: str | None = None,
id_generator: Callable[[], str] | None = None,
storage: IStorage | None = None,
migration: "IMigration | Schema | None" = None,
indexed_fields: list[
str | tuple[str, type] | IndexableField
]
| None = None,
event_handlers: Sequence[IEventHandler] | None = None,
permission_checker: IPermissionChecker | None = None,
encoding: Encoding | None = None,
default_status: RevisionStatus | UnsetType = UNSET,
default_user: str
| Callable[[], str]
| UnsetType = UNSET,
default_now: Callable[[], datetime] | UnsetType = UNSET,
message_queue_factory: IMessageQueueFactory
| None
| UnsetType = UNSET,
job_handler: Callable[[Resource[Job[T]]], None]
| None = None,
job_handler_factory: Callable[
[], Callable[[Resource[Job[T]]], None]
]
| None = None,
validator: "Callable[[T], None] | IValidator | type | None" = None,
constraint_checkers: "Sequence[IConstraintChecker | Callable[[ResourceManager], IConstraintChecker]] | None" = None,
) -> None
Register a resource model (or Schema) and create its ResourceManager.
After a model is registered, calling apply(router) will generate FastAPI routes for it
using the configured route templates.
You can register either:
- a plain model type: add_model(User)
- a Schema: add_model(Schema(User, version=...))
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Resource type or
TYPE:
|
name
|
Resource name (used as route base path). If
TYPE:
|
id_generator
|
Custom ID generator for created resources. If
TYPE:
|
storage
|
Storage instance for this resource. If
TYPE:
|
migration
|
Schema/migration configuration.
- If
TYPE:
|
indexed_fields
|
Fields to index for search/query. Each element can be:
-
TYPE:
|
event_handlers
|
Per-model event handlers. If
TYPE:
|
permission_checker
|
Per-model permission checker. If
TYPE:
|
encoding
|
Encoding for stored payloads. If
TYPE:
|
default_status
|
Per-model default revision status. If
TYPE:
|
default_user
|
Per-model default user (or factory). If
TYPE:
|
default_now
|
Per-model default timestamp function. If
TYPE:
|
message_queue_factory
|
Overrides message queue behavior for Job models:
-
TYPE:
|
job_handler
|
Handler for Job resources (when the model is detected as a Job subclass).
TYPE:
|
job_handler_factory
|
Lazy factory producing a job handler. If provided, it is wrapped as a lazy handler.
TYPE:
|
validator
|
Validation hook(s). When the model is a Pydantic
TYPE:
|
constraint_checkers
|
Extra constraint checkers for this resource. Each element can be an instance or a
factory callable that receives the
TYPE:
|
Behavior
- If
modelis aSchema, it must declareresource_type; schema-level migration/validator should be provided on theSchemaitself. - If the model is a Pydantic type, it is converted to a struct for storage and the Pydantic model can be used for validation.
- Ref relationships are collected from
Ref/RefRevisionannotations for later route and referential integrity setup. - Ref fields (resource_id refs only) are auto-indexed for searchability.
- For Job models with a message queue enabled,
statusandretriesare auto-indexed (if not already present inindexed_fields).
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
TypeError
|
|
Examples:
Basic registration:
Custom resource name:
Provide explicit storage:
# storage is per-model; if you want a default for all models, pass `storage_factory=...`
# when constructing SpecStar / calling configure().
model_name = "people"
st = specstar.storage_factory.build(model_name)
specstar.add_model(User, name=model_name, storage=st)
Using Schema as the first argument:
Source code in specstar/crud/core.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 | |
openapi
¶
Generate and register the OpenAPI schema for the FastAPI application.
This method customizes the OpenAPI schema generation to include all the SpecStar-specific types, models, and response schemas. It ensures that the generated API documentation (Swagger UI / ReDoc) correctly reflects the structure of your resources and their endpoints.
| PARAMETER | DESCRIPTION |
|---|---|
app
|
The FastAPI application instance.
TYPE:
|
structs
|
Optional list of additional msgspec Structs to include in the schema.
TYPE:
|
Note
When :meth:apply is called with a FastAPI instance as the
first argument, this method is called automatically at the end of
apply(). You only need to call it manually if you passed a
bare APIRouter to apply() or need to customise the
structs parameter separately.
Source code in specstar/crud/core.py
apply
¶
apply(
app: FastAPI | APIRouter,
*,
router: APIRouter | None = None,
structs: list[type] | None = None,
auto_include: bool = True,
) -> APIRouter
Apply all route templates to generate API endpoints.
This method generates all the CRUD endpoints for all registered models.
When app is a :class:~fastapi.FastAPI instance, the OpenAPI schema
is automatically customised via :meth:openapi after route generation.
| PARAMETER | DESCRIPTION |
|---|---|
app
|
The FastAPI application or an APIRouter to attach routes to.
When a
TYPE:
|
router
|
Optional sub-router. When provided, routes are generated
on this router instead of directly on
TYPE:
|
structs
|
Additional
TYPE:
|
auto_include
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
APIRouter
|
The router that routes were generated on — either |
APIRouter
|
(if provided) or |
Example
from fastapi import FastAPI, APIRouter
from specstar import SpecStar
app = FastAPI()
specstar = SpecStar()
specstar.add_model(User)
specstar.add_model(Post)
# 1. Simplest — routes on app, auto OpenAPI
specstar.apply(app)
# 2. With a sub-router — auto include + auto OpenAPI
api_router = APIRouter(prefix="/api/v1")
specstar.apply(app, router=api_router)
# 3. Manual include (e.g. already included elsewhere)
api_router = APIRouter(prefix="/api/v1")
specstar.apply(app, router=api_router, auto_include=False)
app.include_router(api_router)
specstar.openapi(app)
# 4. Pure APIRouter (no FastAPI, no OpenAPI)
api_router = APIRouter(prefix="/api/v1")
specstar.apply(api_router)
Note
- Call this method after adding all models and custom route templates.
- When
appis a bareAPIRouter, OpenAPI customisation is skipped (APIRouterhas no OpenAPI schema). structsis ignored whenappis not aFastAPIinstance.
Source code in specstar/crud/core.py
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 | |
dump
¶
dump(
bio: IO[bytes],
model_queries: dict[
str, Query | ResourceMetaSearchQuery | None
]
| None = None,
) -> None
Export resources to a streaming msgpack archive.
| PARAMETER | DESCRIPTION |
|---|---|
bio
|
Binary I/O stream to write to.
TYPE:
|
model_queries
|
Optional
TYPE:
|
Example::
# Dump everything
with open("backup.acbak", "wb") as f:
specstar.dump(f)
# Dump only User resources where name == "Alice"
from specstar.query import QB
with open("backup.acbak", "wb") as f:
specstar.dump(f, model_queries={"user": QB.name == "Alice"})
Source code in specstar/crud/core.py
load
¶
Import resources from a streaming msgpack archive.
| PARAMETER | DESCRIPTION |
|---|---|
bio
|
Binary I/O stream to read from.
TYPE:
|
on_duplicate
|
Strategy for duplicate resource IDs.
Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, 'LoadStats']
|
Per-model load statistics: |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the archive format is invalid or contains unknown models. |
Source code in specstar/crud/core.py
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 | |
QB
¶
Source code in specstar/query.py
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 | |
Functions¶
resource_id
staticmethod
¶
resource_id() -> Field
Resource unique identifier.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for resource_id |
Example
QB.resource_id().eq("abc-123") QB.resource_id() << ["id1", "id2", "id3"]
Source code in specstar/query.py
current_revision_id
staticmethod
¶
current_revision_id() -> Field
Current revision identifier.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for current_revision_id |
Example
QB.current_revision_id().eq("rev-456")
created_time
staticmethod
¶
created_time() -> Field
Resource creation timestamp.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for created_time |
Example
QB.created_time() >= datetime(2024, 1, 1) QB.created_time().today() QB.created_time().last_n_days(7)
Source code in specstar/query.py
updated_time
staticmethod
¶
updated_time() -> Field
Resource last update timestamp.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for updated_time |
Example
QB.updated_time().this_week() QB.updated_time() >= datetime(2024, 1, 1)
Source code in specstar/query.py
created_by
staticmethod
¶
created_by() -> Field
User who created the resource.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for created_by |
Example
QB.created_by().eq("admin") QB.created_by() << ["user1", "user2"]
Source code in specstar/query.py
updated_by
staticmethod
¶
updated_by() -> Field
User who last updated the resource.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for updated_by |
Example
QB.updated_by().eq("system") QB.updated_by().ne("guest")
is_deleted
staticmethod
¶
is_deleted() -> Field
Resource deletion status.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for is_deleted |
Example
QB.is_deleted().eq(False) QB.is_deleted() == False
schema_version
staticmethod
¶
schema_version() -> Field
Resource schema version.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for schema_version |
Example
QB.schema_version().eq("v2")
total_revision_count
staticmethod
¶
total_revision_count() -> Field
Total number of revisions for the resource.
| RETURNS | DESCRIPTION |
|---|---|
Field
|
Field for total_revision_count |
Example
QB.total_revision_count() > 5
Source code in specstar/query.py
rev_status
staticmethod
¶
rev_status() -> Field
Status of the resource's current revision.
Example
QB.rev_status().eq("draft")
rev_created_by
staticmethod
¶
rev_created_by() -> Field
User who created the resource's current revision.
Example
QB.rev_created_by().eq("alice") QB.rev_created_by() << ["alice", "bob"]
rev_updated_by
staticmethod
¶
rev_updated_by() -> Field
User who last updated the resource's current revision.
Example
QB.rev_updated_by().eq("alice")
rev_created_time
staticmethod
¶
rev_created_time() -> Field
Creation timestamp of the resource's current revision.
Example
QB.rev_created_time() >= datetime(2024, 1, 1)
rev_updated_time
staticmethod
¶
rev_updated_time() -> Field
Last-update timestamp of the resource's current revision.
Example
QB.rev_updated_time().this_week()
all
staticmethod
¶
all(*conditions: ConditionBuilder) -> ConditionBuilder
Combine multiple conditions with AND logic.
| PARAMETER | DESCRIPTION |
|---|---|
*conditions
|
Variable number of ConditionBuilder instances. If empty, returns a query with no conditions (matches all resources).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ConditionBuilder
|
ConditionBuilder with AND group, or no conditions if empty |
Example
QB.all(QB["age"] > 18, QB["status"] == "active", QB["score"] >= 80)
Equivalent to: (QB["age"] > 18) & (QB["status"] == "active") & (QB["score"] >= 80)¶
QB.all() # No conditions - matches all resources
Source code in specstar/query.py
any
staticmethod
¶
any(*conditions: ConditionBuilder) -> ConditionBuilder
Combine multiple conditions with OR logic.
| PARAMETER | DESCRIPTION |
|---|---|
*conditions
|
Variable number of ConditionBuilder instances
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ConditionBuilder
|
ConditionBuilder with OR group |
Example
any(QB.status == "draft", QB.status == "pending", QB.status == "review")
Equivalent to: (QB.status == "draft") | (QB.status == "pending") | (QB.status == "review")¶
Source code in specstar/query.py
Schema
¶
Bases: Generic[T]
Unified migration + validation descriptor.
Parameters¶
resource_type : type[T]
The data model class (msgspec Struct or Pydantic BaseModel).
version : str
The target schema version.
validator : Callable | IValidator | type | None
Optional validator (same types accepted by the old validator=
parameter on add_model).
Examples¶
Simple reindex (version bump, no data change)::
Schema(User, "v2")
Single-step migration::
Schema(User, "v2").step("v1", migrate_v1_to_v2)
Chain migration with auto-inferred to::
Schema(User, "v3").step("v1", fn1).step("v2", fn2)
# fn1: v1 → v2 (inferred from next step's from_ver)
# fn2: v2 → v3 (inferred from Schema target version)
Parallel paths::
Schema(User, "v3").step("v1", fn1).step("v2", fn2).plus("v1", fn_shortcut)
# fn_shortcut: v1 → v3 (last in chain, inferred from target)
With validation::
Schema(User, "v2", validator=my_validator).step("v1", fn)
Source code in specstar/schema.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |
Attributes¶
raw_validator
property
¶
The original validator argument (before normalization).
resource_type
property
¶
The resource type this Schema is bound to.
Returns None for schemas created via from_legacy().
has_migration
property
¶
Whether this schema defines any migration steps (or wraps legacy).
Functions¶
set_encoding
¶
Set the serialization format for intermediate migration results.
Parameters¶
encoding : str
"json" (default) or "msgpack".
This is called automatically by ResourceManager so that
multi-step migrations re-encode intermediate results in the
same format as the stored data.
Source code in specstar/schema.py
step
¶
step(
from_ver: str | Pattern[str],
fn: Callable,
*,
to: str | None = None,
source_type: type | None = None,
) -> Schema[T]
Append a migration step to the current chain.
Parameters¶
from_ver : str | re.Pattern[str]
Source version that this step handles. Can be a compiled regex
pattern (re.compile(...)), in which case the step creates
edges from every known version that matches the pattern.
fn : Callable[[IO[bytes]], Any] | Callable[[source_type], Any]
Transform function. When source_type is None (default),
the function receives IO[bytes] (legacy behaviour). When
source_type is provided, the function receives an already-decoded
instance of that type.
to : str | None
Explicit target version. If None it is auto-inferred:
* Middle step → next step's from_ver (must be a literal string).
* Last step in a chain → Schema.version.
source_type : type | None
When provided, the framework automatically decodes the raw bytes
into source_type before calling fn. This removes the
boilerplate of msgspec.json.decode(data.read(), type=...)
inside every migration function. In multi-step chains, if the
previous step already returned the expected type, the object is
passed directly without re-encoding/decoding.
Examples¶
Legacy (IO[bytes]) style::
def migrate_v1_to_v2(data: IO[bytes]) -> V2:
obj = msgspec.json.decode(data.read(), type=V1)
return V2(name=obj.name, extra="new")
Schema(V2, "v2").step("v1", migrate_v1_to_v2)
Typed style (recommended)::
def migrate_v1_to_v2(data: V1) -> V2:
return V2(name=data.name, extra="new")
Schema(V2, "v2").step("v1", migrate_v1_to_v2, source_type=V1)
Source code in specstar/schema.py
plus
¶
plus(
from_ver: str | Pattern[str],
fn: Callable,
*,
to: str | None = None,
source_type: type | None = None,
) -> Schema[T]
Start a new parallel chain with the given first step.
Same semantics as .step() but the previous chain is flushed first
so that its to versions get resolved independently.
Parameters¶
from_ver : str | re.Pattern[str]
Source version (same as .step()).
fn : Callable
Transform function (same as .step()).
to : str | None
Explicit target version (same as .step()).
source_type : type | None
Typed source (same as .step()). See .step() for details.
Source code in specstar/schema.py
migrate
¶
Migrate data from schema_version to the target version.
If a legacy IMigration is wrapped, delegates to it directly.
Otherwise uses graph-based BFS path finding and executes the
transform chain.
Compatible with the IMigration.migrate() signature so that
ResourceManager can use Schema as a drop-in replacement.
Source code in specstar/schema.py
validate
¶
Run the attached validator, if any.
Source code in specstar/schema.py
from_legacy
classmethod
¶
from_legacy(migration: Any) -> Schema[T]
Wrap an existing IMigration instance as a Schema.
The resulting Schema delegates .migrate() calls directly
to the wrapped IMigration.
Note: the returned Schema has resource_type = None because
IMigration does not carry type information.
Source code in specstar/schema.py
BackgroundTaskAccepted
¶
Bases: Struct
Response body returned by background create actions (HTTP 202).
When a custom create action uses async_mode='background', the
endpoint returns this struct immediately while the handler continues
executing in a FastAPI BackgroundTasks worker. Unlike
async_mode='job', no Job model is created and the task cannot be
tracked from the frontend.
| ATTRIBUTE | DESCRIPTION |
|---|---|
message |
A human-readable acceptance message.
TYPE:
|
Source code in specstar/types.py
BlobUploadSession
¶
Bases: Struct
Represents an active or completed blob upload session.
Lifecycle (single upload)::
pending → uploaded → finalized (or → aborted)
Lifecycle (chunked upload)::
pending → uploading → … → uploading → finalized (or → aborted)
upload_method indicates how the client should deliver file bytes:
"proxy": PUT bytes to/blobs/upload-sessions/{upload_id}/content. May be called multiple times for chunked uploads."single_put": upload directly toupload_url(e.g. S3 presigned PUT)
Source code in specstar/types.py
Attributes¶
file_id
instance-attribute
¶
Pre-allocated file ID (may be a placeholder until finalize).
status
class-attribute
instance-attribute
¶
Current lifecycle state of the session.
upload_method
class-attribute
instance-attribute
¶
How the client should deliver file bytes.
upload_url
class-attribute
instance-attribute
¶
URL for the client to upload bytes (only relevant for single_put).
content_type
class-attribute
instance-attribute
¶
MIME type of the content being uploaded.
size
class-attribute
instance-attribute
¶
Expected size of the content in bytes (None if unknown).
uploaded_size
class-attribute
instance-attribute
¶
Number of bytes already uploaded (useful for progress tracking).
total_parts
class-attribute
instance-attribute
¶
Expected number of parts for parallel chunked upload (None if unknown).
parts_received
class-attribute
instance-attribute
¶
Sorted list of 1-based part numbers that have been received so far.
expires_at
class-attribute
instance-attribute
¶
When this upload session expires (None for no expiry).
DisplayName
¶
Annotation marker designating a str field as the display name.
Usage::
class Character(Struct):
name: Annotated[str, DisplayName()] # ← this field is the display name
level: int = 1
The SpecStar framework will inject x-display-name-field into the
OpenAPI schema so the web frontend can show a friendly name instead of
just the resource ID.
Source code in specstar/types.py
IConstraintChecker
¶
Bases: ABC
Interface for custom constraint checkers.
Implement this to define reusable data constraints that are automatically enforced during create, update, modify, switch and restore operations. The framework handles all event lifecycle (before / on_success) and compensation (rollback) logic — you only need to implement the check.
Example::
class NoDuplicateEmailChecker(IConstraintChecker):
def __init__(self, rm: ResourceManager) -> None:
self.rm = rm
def check(
self, data: Any, *, exclude_resource_id: str | None = None
) -> None:
email = getattr(data, "email", None)
if email and self._email_exists(email, exclude_resource_id):
raise ValueError(f"Email {email!r} already in use")
# Pass a factory callable (receives ResourceManager):
spec.add_model(User, constraint_checkers=[NoDuplicateEmailChecker])
# Or a lambda factory:
spec.add_model(
User, constraint_checkers=[lambda rm: NoDuplicateEmailChecker(rm)]
)
Source code in specstar/types.py
Functions¶
check
abstractmethod
¶
Validate that data satisfies this constraint.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The resource data (msgspec Struct instance).
TYPE:
|
exclude_resource_id
|
When updating an existing resource, pass its ID so the checker can allow the resource to keep its own values.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Raised by the checker to signal a constraint violation. The framework catches it, executes compensation, and re-raises it. |
Source code in specstar/types.py
data_relevant_changed
¶
Return whether the fields relevant to this constraint changed.
Called during modify to skip unnecessary checks when the
constrained fields are unchanged. The default implementation
returns True (always re-check). Override for optimisation.
Source code in specstar/types.py
IValidator
¶
Bases: ABC
Interface for custom data validators.
Implement this to create reusable validators that can be attached via
add_model(validator=...) or Schema(..., validator=...).
Example::
class PriceValidator(IValidator):
def validate(self, data) -> None:
if data.price < 0:
raise ValueError("Price must be non-negative")
spec.add_model(Item, validator=PriceValidator())
Source code in specstar/types.py
Job
¶
Bases: Struct, Generic[T, D]
A job wrapping a payload T with optional artifact type D.
The second type parameter D defaults to None so existing
Job[T] usage is fully backward-compatible.
| ATTRIBUTE | DESCRIPTION |
|---|---|
payload |
The input data for the job.
TYPE:
|
status |
Current processing status.
TYPE:
|
errmsg |
Error or result message after processing.
TYPE:
|
artifact |
Optional typed output produced by the job handler.
TYPE:
|
retries |
Number of times the job has been retried.
TYPE:
|
Source code in specstar/types.py
Attributes¶
errmsg
class-attribute
instance-attribute
¶
Result or error message after processing.
artifact
class-attribute
instance-attribute
¶
Optional typed output produced by the job handler.
This field stores the result/artifact of job execution.
The type D defaults to None, so Job[T] is equivalent
to Job[T, None] and artifact is simply None.
retries
class-attribute
instance-attribute
¶
Number of times the job has been retried.
max_retries
class-attribute
instance-attribute
¶
Per-job maximum retry count. If None (default), the queue-level
max_retries setting is used. When set, this value takes precedence
over the queue default. For Celery queues the effective value is
min(job.max_retries, queue.max_retries) because the Celery task
decorator imposes a hard upper bound.
periodic_interval_seconds
class-attribute
instance-attribute
¶
If set, the job will be re-enqueued every N seconds after completion.
periodic_max_runs
class-attribute
instance-attribute
¶
Maximum number of times to run the periodic job. None means run indefinitely.
periodic_runs
class-attribute
instance-attribute
¶
Number of times this periodic job has been executed.
periodic_initial_delay_seconds
class-attribute
instance-attribute
¶
Delay in seconds before the first execution. If None, executes immediately.
last_heartbeat_at
class-attribute
instance-attribute
¶
Timestamp of the last heartbeat. Used to detect dead workers.
JobRedirectInfo
¶
Bases: Struct
Response body returned by async create actions (HTTP 202).
When a custom create action uses async_mode='job', the endpoint
returns this struct instead of RevisionInfo so the client can
navigate to the auto-generated Job resource to track progress.
| ATTRIBUTE | DESCRIPTION |
|---|---|
job_resource_name |
The registered name of the auto-generated Job resource.
TYPE:
|
job_resource_id |
The resource ID of the newly created Job instance.
TYPE:
|
redirect_url |
A URL path to the Job detail endpoint.
TYPE:
|
Source code in specstar/types.py
OnDelete
¶
Bases: StrEnum
Defines the referential action when the referenced resource is deleted.
Source code in specstar/types.py
Attributes¶
dangling
class-attribute
instance-attribute
¶
No action taken. The reference becomes dangling. (default)
set_null
class-attribute
instance-attribute
¶
Set the referencing field to null. Requires the field to be Optional.
cascade
class-attribute
instance-attribute
¶
Delete the referencing resource as well.
OnDuplicate
¶
Bases: StrEnum
Strategy for handling duplicate resource IDs during incremental load.
Source code in specstar/types.py
Ref
¶
Metadata marker for a field that references another SpecStar resource.
Use with Annotated to annotate a str field that holds a reference
to another SpecStar resource.
By default ref_type is RefType.resource_id, meaning the field
stores a resource_id and participates in referential integrity.
Set ref_type=RefType.revision_id for version-aware references where
the field may store either a revision_id (pinned) or a resource_id
(meaning latest). Revision refs are always on_delete=dangling.
Example::
class Monster(Struct):
zone_id: Annotated[str, Ref("zone")]
guild_id: Annotated[
str | None, Ref("guild", on_delete=OnDelete.set_null)
] = None
owner_id: Annotated[str, Ref("character", on_delete=OnDelete.cascade)]
zone_snapshot_id: Annotated[str, Ref("zone", ref_type=RefType.revision_id)]
Source code in specstar/types.py
RefRevision
¶
Metadata marker for a field that references another resource's revision_id.
.. deprecated:: 0.9.0
Use Ref(resource, ref_type=RefType.revision_id) instead.
Example::
class Monster(Struct):
zone_revision_id: Annotated[str, RefRevision("zone")]
Source code in specstar/types.py
RefType
¶
Bases: StrEnum
Defines the type of reference a field holds.
Source code in specstar/types.py
Attributes¶
resource_id
class-attribute
instance-attribute
¶
The field stores a resource_id. The reference targets the resource as a whole and participates in referential integrity (on_delete), auto-indexing, and referrers queries.
revision_id
class-attribute
instance-attribute
¶
The field stores a version-aware reference: either a revision_id
(pinned to a specific revision) or a resource_id (meaning latest).
Revision refs are always on_delete=dangling, are not auto-indexed,
and are excluded from referrers queries.
SearchedResource
¶
Bases: Struct, Generic[T]
A resource item returned by list_resources.
Each field may be the full type, a partial Struct (when partial fields are requested), or UNSET (when excluded via the returns parameter).
Source code in specstar/types.py
TaskStatus
¶
Bases: StrEnum
Source code in specstar/types.py
Unique
¶
Annotation marker that enforces uniqueness of a field.
Use with Annotated to mark a field as unique among non-deleted
resources of the same type.
Semantics:
- Soft-deleted resources are ignored.
- None values are ignored (None may repeat).
SpecStar ensures the field is indexed and checks uniqueness on write operations (create/update/modify/patch) when the unique-relevant value changes.
Usage::
class User(Struct):
username: Annotated[str, Unique()]
email: Annotated[str, Unique()]
nickname: Annotated[str | None, Unique()] = None # None can repeat
| RAISES | DESCRIPTION |
|---|---|
|
exc: |
Source code in specstar/types.py
Functions¶
register_backend_provider
¶
pydantic_to_struct
¶
Auto-generate a msgspec Struct from a Pydantic BaseModel.
This allows users to pass a Pydantic model to add_model()
and have the system auto-generate the internal Struct type while
using Pydantic only for validation.
Handles common types: str, int, float, bool, datetime, Optional, list, dict. Nested Pydantic BaseModel fields are recursively converted to Structs. Pydantic discriminated unions are converted to msgspec tagged unions.
Source code in specstar/resource_manager/pydantic_converter.py
struct_to_pydantic
¶
Convert a msgspec Struct class to a Pydantic BaseModel class.
This is the reverse of pydantic_to_struct. It allows using a
Struct-based type as a FastAPI request body parameter by generating an
equivalent Pydantic model that FastAPI can introspect for OpenAPI schema
generation and validation.
Usage::
@app.post("/action")
async def my_action(body: struct_to_pydantic(MyStruct) = Body(...)): ...
Handles:
- Simple scalar types (str, int, float, bool, datetime …)
- Optional[X]
- Enum types
- list[X], dict[K, V]
- Nested Structs (recursively converted)
- Tagged unions (A | B where both have tag) → Pydantic
discriminated unions with Literal discriminator field
- Annotated metadata is stripped (SpecStar-specific markers
like Ref, DisplayName, Unique are not meaningful for
Pydantic).