fluidkit 0.1.0__tar.gz

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.
Files changed (33) hide show
  1. fluidkit-0.1.0/PKG-INFO +242 -0
  2. fluidkit-0.1.0/README.md +214 -0
  3. fluidkit-0.1.0/fluidkit/__init__.py +47 -0
  4. fluidkit-0.1.0/fluidkit/core/__init__.py +35 -0
  5. fluidkit-0.1.0/fluidkit/core/constants.py +32 -0
  6. fluidkit-0.1.0/fluidkit/core/integrator.py +299 -0
  7. fluidkit-0.1.0/fluidkit/core/schema.py +628 -0
  8. fluidkit-0.1.0/fluidkit/core/type_conversion.py +296 -0
  9. fluidkit-0.1.0/fluidkit/core/utils.py +363 -0
  10. fluidkit-0.1.0/fluidkit/generators/__init__.py +51 -0
  11. fluidkit-0.1.0/fluidkit/generators/javascript/__init__.py +0 -0
  12. fluidkit-0.1.0/fluidkit/generators/typescript/__init__.py +24 -0
  13. fluidkit-0.1.0/fluidkit/generators/typescript/clients.py +674 -0
  14. fluidkit-0.1.0/fluidkit/generators/typescript/imports.py +300 -0
  15. fluidkit-0.1.0/fluidkit/generators/typescript/interfaces.py +433 -0
  16. fluidkit-0.1.0/fluidkit/generators/typescript/pipeline.py +306 -0
  17. fluidkit-0.1.0/fluidkit/generators/zod/__init__.py +0 -0
  18. fluidkit-0.1.0/fluidkit/introspection/__init__.py +21 -0
  19. fluidkit-0.1.0/fluidkit/introspection/models.py +355 -0
  20. fluidkit-0.1.0/fluidkit/introspection/parameters.py +202 -0
  21. fluidkit-0.1.0/fluidkit/introspection/routes.py +61 -0
  22. fluidkit-0.1.0/fluidkit/introspection/security.py +60 -0
  23. fluidkit-0.1.0/fluidkit.egg-info/PKG-INFO +242 -0
  24. fluidkit-0.1.0/fluidkit.egg-info/SOURCES.txt +31 -0
  25. fluidkit-0.1.0/fluidkit.egg-info/dependency_links.txt +1 -0
  26. fluidkit-0.1.0/fluidkit.egg-info/requires.txt +5 -0
  27. fluidkit-0.1.0/fluidkit.egg-info/top_level.txt +1 -0
  28. fluidkit-0.1.0/pyproject.toml +48 -0
  29. fluidkit-0.1.0/setup.cfg +4 -0
  30. fluidkit-0.1.0/tests/test_core.py +129 -0
  31. fluidkit-0.1.0/tests/test_generators.py +231 -0
  32. fluidkit-0.1.0/tests/test_integration.py +144 -0
  33. fluidkit-0.1.0/tests/test_introspection.py +109 -0
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: fluidkit
3
+ Version: 0.1.0
4
+ Summary: Automatic TypeScript client generation for FastAPI through runtime introspection
5
+ Author-email: Aswanth Manoj <aswanthmanoj51@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AswanthManoj/Fluidkit
8
+ Project-URL: Repository, https://github.com/AswanthManoj/Fluidkit
9
+ Project-URL: Issues, https://github.com/AswanthManoj/Fluidkit/issues
10
+ Keywords: fastapi,typescript,code-generation,full-stack,type-safety,sveltekit,nextjs,nuxtjs
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Code Generators
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: dev
25
+ Requires-Dist: fastapi[standard]>=0.115.14; extra == "dev"
26
+ Requires-Dist: pydantic-extra-types>=2.10.5; extra == "dev"
27
+ Requires-Dist: pydantic[email]>=2.11.7; extra == "dev"
28
+
29
+ # FluidKit
30
+
31
+ **Automatic TypeScript client generation for FastAPI through runtime introspection. Get tRPC-like developer experience with full-stack type safety across Python and TypeScript.**
32
+
33
+ ## Overview
34
+
35
+ FluidKit bridges the gap between Python FastAPI backends and modern TypeScript frontends by automatically generating fully-typed clients from your existing FastAPI code. No configuration, no decorators, no manual type definitions.
36
+
37
+ ### 🔧 **Automatic Type-Safe Client Generation**
38
+
39
+ Write FastAPI, get TypeScript clients with full IDE support automatically:
40
+
41
+ ```python
42
+ # Your FastAPI code (unchanged)
43
+ from fastapi import FastAPI, Query
44
+ from pydantic import BaseModel
45
+
46
+ app = FastAPI()
47
+
48
+ class User(BaseModel):
49
+ id: int
50
+ name: str
51
+ email: str
52
+
53
+ @app.get("/users/{user_id}")
54
+ async def get_user(user_id: int, include_profile: bool = Query(False)) -> User:
55
+ return User(id=user_id, name="John", email="john@example.com")
56
+
57
+ # One line - automatic client generation
58
+ import fluidkit
59
+ fluidkit.integrate(app)
60
+ ```
61
+
62
+ ```typescript
63
+ // Auto-generated: Full type safety + IDE autocomplete
64
+ import { get_user } from './.fluidkit/main';
65
+
66
+ const result = await get_user(123, true);
67
+ // ^-- Full TypeScript inference, just like tRPC
68
+ // result.data is typed as User | undefined
69
+ // result.error is typed as string | undefined
70
+ ```
71
+
72
+ **IDE Experience:**
73
+ - ✅ **Full autocomplete** on function parameters and return types
74
+ - ✅ **Type checking** prevents runtime errors
75
+ - ✅ **Go-to-definition** jumps to Python code
76
+ - ✅ **Refactor safety** - rename Python functions, TypeScript updates automatically
77
+
78
+ ### 🚀 **FastAPI + Modern Meta-Frameworks**
79
+
80
+ FluidKit unlocks FastAPI for server-side rendering frameworks like SvelteKit, Next.js, and Nuxt:
81
+
82
+ ```typescript
83
+ // SvelteKit +page.server.ts - server-side rendering
84
+ export const load: PageServerLoad = async () => {
85
+ const users = await get_users({ status: "active", limit: 10 });
86
+ return { users: users.data };
87
+ };
88
+ ```
89
+
90
+ ```svelte
91
+ <!-- +page.svelte - reactive and type-safe -->
92
+ <script lang="ts">
93
+ export let data;
94
+
95
+ // Client-side interactions with full type safety
96
+ async function createUser() {
97
+ const result = await create_user({
98
+ name: userName,
99
+ email: userEmail
100
+ });
101
+
102
+ if (result.success) {
103
+ // result.data is fully typed as User
104
+ users = [...users, result.data];
105
+ }
106
+ }
107
+ </script>
108
+ ```
109
+
110
+ **Why This Matters:**
111
+ - **Python developers** can leverage modern frontend frameworks without becoming Node.js experts
112
+ - **Full-stack type safety** from database to UI components
113
+ - **Natural development flow** - write Python, get TypeScript benefits automatically
114
+ - **Server-side rendering** with FastAPI data, client-side interactions with the same API
115
+
116
+ ## Installation
117
+
118
+ ```bash
119
+ # Install directly from GitHub
120
+ pip install git+https://github.com/AswanthManoj/Fluidkit.git
121
+ ```
122
+
123
+ ## Quick Start
124
+
125
+ Add one line to your existing FastAPI app:
126
+
127
+ ```python
128
+ from fastapi import FastAPI
129
+ import fluidkit
130
+
131
+ app = FastAPI()
132
+
133
+ # Your existing routes...
134
+ @app.get("/users")
135
+ async def get_users():
136
+ return [{"id": 1, "name": "John"}]
137
+
138
+ # Generate TypeScript clients automatically
139
+ fluidkit.integrate(app)
140
+ ```
141
+
142
+ Run your FastAPI app normally:
143
+ ```bash
144
+ uvicorn main:app --reload
145
+ ```
146
+
147
+ FluidKit automatically:
148
+ - ✅ **Introspects your FastAPI app** using FastAPI's internal systems
149
+ - ✅ **Discovers all routes and models** through dependency analysis
150
+ - ✅ **Generates TypeScript clients** with perfect parameter classification
151
+ - ✅ **Updates on code changes** when FastAPI reloads
152
+
153
+ Generated files:
154
+ ```
155
+ project/
156
+ ├── main.py
157
+ └── .fluidkit/
158
+ ├── main.ts # TypeScript clients
159
+ └── runtime.ts # Fetch utilities
160
+ ```
161
+
162
+ Use the generated clients:
163
+ ```typescript
164
+ import { get_users } from './.fluidkit/main';
165
+
166
+ const result = await get_users();
167
+ if (result.success) {
168
+ console.log(result.data); // Fully typed!
169
+ }
170
+ ```
171
+
172
+ ## Key Features
173
+
174
+ ### Zero Configuration
175
+ - **No decorators** - works with existing FastAPI code
176
+ - **No config files** - automatic discovery and generation
177
+ - **No manual types** - inferred from Pydantic models
178
+
179
+ ### Perfect FastAPI Compliance
180
+ - **Uses FastAPI's internals** for 100% accurate parameter classification
181
+ - **Handles complex types** - generics, unions, optional fields
182
+ - **Supports all FastAPI features** - dependencies, security, multi-method routes
183
+
184
+ ### Production Ready
185
+ - **Environment-aware** - proxy in browser, direct connection on server
186
+ - **Error handling** - structured error responses with status codes
187
+ - **Import resolution** - automatic relative imports between generated files
188
+
189
+ ### Framework Integration
190
+ - **SvelteKit** - works with `+page.server.ts` and client-side code
191
+ - **Next.js** - compatible with App Router and Pages Router
192
+ - **Any TypeScript project** - just import and use
193
+
194
+ ## Development Workflow
195
+
196
+ FluidKit integrates seamlessly into your Python-first development workflow:
197
+
198
+ 1. **Write FastAPI normally** - routes, models, dependencies
199
+ 2. **Add `fluidkit.integrate(app)`** - one line in your app
200
+ 3. **Use TypeScript clients** - import generated functions anywhere
201
+ 4. **Iterate rapidly** - changes to Python automatically update TypeScript
202
+
203
+ **For Python developers:**
204
+ - Stay in Python for business logic
205
+ - Get modern frontend benefits automatically
206
+ - No Node.js configuration required
207
+ - Full-stack type safety without context switching
208
+
209
+ **For teams:**
210
+ - Backend and frontend stay in sync automatically
211
+ - Impossible to have type mismatches between API and UI
212
+ - Python changes immediately available in TypeScript
213
+ - No API documentation to maintain
214
+
215
+ ## Why FluidKit?
216
+
217
+ **Traditional full-stack development:**
218
+ ```
219
+ Python API ──┐
220
+ ├── Manual sync ──> TypeScript types
221
+ OpenAPI ─────┘ Frontend code
222
+ ```
223
+ *Brittle, error-prone, requires constant maintenance*
224
+
225
+ **FluidKit full-stack development:**
226
+ ```
227
+ Python API ──> FluidKit ──> Fully-typed TypeScript clients
228
+ ```
229
+ *Automatic, reliable, zero maintenance*
230
+
231
+ FluidKit brings the **tRPC developer experience** to Python developers, enabling modern full-stack development without abandoning the Python ecosystem.
232
+
233
+ ---
234
+
235
+ **Ready to eliminate the API integration gap?**
236
+ Add `fluidkit.integrate(app)` to your FastAPI app and experience full-stack type safety.
237
+
238
+ **Coming Soon:**
239
+ - 🚧 CLI tooling (`fluidkit init`, `fluidkit dev`)
240
+ - 🚧 Project templates and scaffolding
241
+ - 🚧 Watch mode for development
242
+ - 🚧 Additional language support (Python, Zod, JavaScript)
@@ -0,0 +1,214 @@
1
+ # FluidKit
2
+
3
+ **Automatic TypeScript client generation for FastAPI through runtime introspection. Get tRPC-like developer experience with full-stack type safety across Python and TypeScript.**
4
+
5
+ ## Overview
6
+
7
+ FluidKit bridges the gap between Python FastAPI backends and modern TypeScript frontends by automatically generating fully-typed clients from your existing FastAPI code. No configuration, no decorators, no manual type definitions.
8
+
9
+ ### 🔧 **Automatic Type-Safe Client Generation**
10
+
11
+ Write FastAPI, get TypeScript clients with full IDE support automatically:
12
+
13
+ ```python
14
+ # Your FastAPI code (unchanged)
15
+ from fastapi import FastAPI, Query
16
+ from pydantic import BaseModel
17
+
18
+ app = FastAPI()
19
+
20
+ class User(BaseModel):
21
+ id: int
22
+ name: str
23
+ email: str
24
+
25
+ @app.get("/users/{user_id}")
26
+ async def get_user(user_id: int, include_profile: bool = Query(False)) -> User:
27
+ return User(id=user_id, name="John", email="john@example.com")
28
+
29
+ # One line - automatic client generation
30
+ import fluidkit
31
+ fluidkit.integrate(app)
32
+ ```
33
+
34
+ ```typescript
35
+ // Auto-generated: Full type safety + IDE autocomplete
36
+ import { get_user } from './.fluidkit/main';
37
+
38
+ const result = await get_user(123, true);
39
+ // ^-- Full TypeScript inference, just like tRPC
40
+ // result.data is typed as User | undefined
41
+ // result.error is typed as string | undefined
42
+ ```
43
+
44
+ **IDE Experience:**
45
+ - ✅ **Full autocomplete** on function parameters and return types
46
+ - ✅ **Type checking** prevents runtime errors
47
+ - ✅ **Go-to-definition** jumps to Python code
48
+ - ✅ **Refactor safety** - rename Python functions, TypeScript updates automatically
49
+
50
+ ### 🚀 **FastAPI + Modern Meta-Frameworks**
51
+
52
+ FluidKit unlocks FastAPI for server-side rendering frameworks like SvelteKit, Next.js, and Nuxt:
53
+
54
+ ```typescript
55
+ // SvelteKit +page.server.ts - server-side rendering
56
+ export const load: PageServerLoad = async () => {
57
+ const users = await get_users({ status: "active", limit: 10 });
58
+ return { users: users.data };
59
+ };
60
+ ```
61
+
62
+ ```svelte
63
+ <!-- +page.svelte - reactive and type-safe -->
64
+ <script lang="ts">
65
+ export let data;
66
+
67
+ // Client-side interactions with full type safety
68
+ async function createUser() {
69
+ const result = await create_user({
70
+ name: userName,
71
+ email: userEmail
72
+ });
73
+
74
+ if (result.success) {
75
+ // result.data is fully typed as User
76
+ users = [...users, result.data];
77
+ }
78
+ }
79
+ </script>
80
+ ```
81
+
82
+ **Why This Matters:**
83
+ - **Python developers** can leverage modern frontend frameworks without becoming Node.js experts
84
+ - **Full-stack type safety** from database to UI components
85
+ - **Natural development flow** - write Python, get TypeScript benefits automatically
86
+ - **Server-side rendering** with FastAPI data, client-side interactions with the same API
87
+
88
+ ## Installation
89
+
90
+ ```bash
91
+ # Install directly from GitHub
92
+ pip install git+https://github.com/AswanthManoj/Fluidkit.git
93
+ ```
94
+
95
+ ## Quick Start
96
+
97
+ Add one line to your existing FastAPI app:
98
+
99
+ ```python
100
+ from fastapi import FastAPI
101
+ import fluidkit
102
+
103
+ app = FastAPI()
104
+
105
+ # Your existing routes...
106
+ @app.get("/users")
107
+ async def get_users():
108
+ return [{"id": 1, "name": "John"}]
109
+
110
+ # Generate TypeScript clients automatically
111
+ fluidkit.integrate(app)
112
+ ```
113
+
114
+ Run your FastAPI app normally:
115
+ ```bash
116
+ uvicorn main:app --reload
117
+ ```
118
+
119
+ FluidKit automatically:
120
+ - ✅ **Introspects your FastAPI app** using FastAPI's internal systems
121
+ - ✅ **Discovers all routes and models** through dependency analysis
122
+ - ✅ **Generates TypeScript clients** with perfect parameter classification
123
+ - ✅ **Updates on code changes** when FastAPI reloads
124
+
125
+ Generated files:
126
+ ```
127
+ project/
128
+ ├── main.py
129
+ └── .fluidkit/
130
+ ├── main.ts # TypeScript clients
131
+ └── runtime.ts # Fetch utilities
132
+ ```
133
+
134
+ Use the generated clients:
135
+ ```typescript
136
+ import { get_users } from './.fluidkit/main';
137
+
138
+ const result = await get_users();
139
+ if (result.success) {
140
+ console.log(result.data); // Fully typed!
141
+ }
142
+ ```
143
+
144
+ ## Key Features
145
+
146
+ ### Zero Configuration
147
+ - **No decorators** - works with existing FastAPI code
148
+ - **No config files** - automatic discovery and generation
149
+ - **No manual types** - inferred from Pydantic models
150
+
151
+ ### Perfect FastAPI Compliance
152
+ - **Uses FastAPI's internals** for 100% accurate parameter classification
153
+ - **Handles complex types** - generics, unions, optional fields
154
+ - **Supports all FastAPI features** - dependencies, security, multi-method routes
155
+
156
+ ### Production Ready
157
+ - **Environment-aware** - proxy in browser, direct connection on server
158
+ - **Error handling** - structured error responses with status codes
159
+ - **Import resolution** - automatic relative imports between generated files
160
+
161
+ ### Framework Integration
162
+ - **SvelteKit** - works with `+page.server.ts` and client-side code
163
+ - **Next.js** - compatible with App Router and Pages Router
164
+ - **Any TypeScript project** - just import and use
165
+
166
+ ## Development Workflow
167
+
168
+ FluidKit integrates seamlessly into your Python-first development workflow:
169
+
170
+ 1. **Write FastAPI normally** - routes, models, dependencies
171
+ 2. **Add `fluidkit.integrate(app)`** - one line in your app
172
+ 3. **Use TypeScript clients** - import generated functions anywhere
173
+ 4. **Iterate rapidly** - changes to Python automatically update TypeScript
174
+
175
+ **For Python developers:**
176
+ - Stay in Python for business logic
177
+ - Get modern frontend benefits automatically
178
+ - No Node.js configuration required
179
+ - Full-stack type safety without context switching
180
+
181
+ **For teams:**
182
+ - Backend and frontend stay in sync automatically
183
+ - Impossible to have type mismatches between API and UI
184
+ - Python changes immediately available in TypeScript
185
+ - No API documentation to maintain
186
+
187
+ ## Why FluidKit?
188
+
189
+ **Traditional full-stack development:**
190
+ ```
191
+ Python API ──┐
192
+ ├── Manual sync ──> TypeScript types
193
+ OpenAPI ─────┘ Frontend code
194
+ ```
195
+ *Brittle, error-prone, requires constant maintenance*
196
+
197
+ **FluidKit full-stack development:**
198
+ ```
199
+ Python API ──> FluidKit ──> Fully-typed TypeScript clients
200
+ ```
201
+ *Automatic, reliable, zero maintenance*
202
+
203
+ FluidKit brings the **tRPC developer experience** to Python developers, enabling modern full-stack development without abandoning the Python ecosystem.
204
+
205
+ ---
206
+
207
+ **Ready to eliminate the API integration gap?**
208
+ Add `fluidkit.integrate(app)` to your FastAPI app and experience full-stack type safety.
209
+
210
+ **Coming Soon:**
211
+ - 🚧 CLI tooling (`fluidkit init`, `fluidkit dev`)
212
+ - 🚧 Project templates and scaffolding
213
+ - 🚧 Watch mode for development
214
+ - 🚧 Additional language support (Python, Zod, JavaScript)
@@ -0,0 +1,47 @@
1
+ """
2
+ FluidKit - Automatic TypeScript client code generation for FastAPI
3
+ """
4
+
5
+ __version__ = "2.0.0"
6
+
7
+ def _check_dependencies():
8
+ """Check for required dependencies and provide helpful error messages"""
9
+ missing = []
10
+
11
+ try:
12
+ import fastapi
13
+ except ImportError:
14
+ missing.append("fastapi")
15
+
16
+ try:
17
+ import pydantic
18
+ except ImportError:
19
+ missing.append("pydantic")
20
+
21
+ if missing:
22
+ deps = " and ".join(missing)
23
+ raise ImportError(
24
+ f"FluidKit requires {deps} to be installed.\n"
25
+ f"Install with: pip install {' '.join(missing)}\n"
26
+ f"FluidKit works with your existing {deps} versions."
27
+ )
28
+
29
+ # Check dependencies on import
30
+ _check_dependencies()
31
+
32
+ # Import main API only after dependency check
33
+ from .core.schema import LanguageType
34
+ from .core.integrator import integrate, introspect_only, generate_only
35
+
36
+ __all__ = [
37
+ # Main functions
38
+ 'integrate',
39
+ 'introspect_only',
40
+ 'generate_only',
41
+
42
+ # Enums
43
+ 'LanguageType',
44
+
45
+ # Version
46
+ '__version__'
47
+ ]
@@ -0,0 +1,35 @@
1
+ """
2
+ Core FluidKit components - for advanced users and plugin developers
3
+ """
4
+
5
+ # Main data structures
6
+ from .schema import (
7
+ FluidKitApp,
8
+ RouteNode,
9
+ ModelNode,
10
+ Field,
11
+ FieldAnnotation,
12
+ FieldConstraints,
13
+ ModuleLocation,
14
+
15
+ # Enums
16
+ BaseType,
17
+ LanguageType,
18
+ ContainerType,
19
+ ParameterType,
20
+ )
21
+
22
+ # Main integration function
23
+ from .integrator import integrate, introspect_only, generate_only
24
+
25
+ __all__ = [
26
+ # Functions
27
+ 'integrate', 'introspect_only', 'generate_only',
28
+
29
+ # Data structures
30
+ 'FluidKitApp', 'RouteNode', 'ModelNode', 'Field',
31
+ 'FieldAnnotation', 'FieldConstraints', 'ModuleLocation',
32
+
33
+ # Enums
34
+ 'LanguageType', 'BaseType', 'ContainerType', 'ParameterType',
35
+ ]
@@ -0,0 +1,32 @@
1
+ """
2
+ FluidKit constants for runtime imports and code generation
3
+ """
4
+
5
+ class FluidKitRuntime:
6
+ """FluidKit runtime function and type names"""
7
+
8
+ # TypeScript runtime exports
9
+ API_RESULT_TYPE = "ApiResult"
10
+ GET_BASE_URL_FN = "getBaseUrl"
11
+ HANDLE_RESPONSE_FN = "handleResponse"
12
+
13
+ # Runtime file locations
14
+ RUNTIME_DIR = ".fluidkit"
15
+ RUNTIME_FILE = "runtime.ts"
16
+
17
+ @classmethod
18
+ def get_all_imports(cls) -> list[str]:
19
+ """Get all runtime imports for TypeScript"""
20
+ return [cls.API_RESULT_TYPE, cls.GET_BASE_URL_FN, cls.HANDLE_RESPONSE_FN]
21
+
22
+
23
+ class GenerationPaths:
24
+ """Standard paths for code generation"""
25
+
26
+ FLUIDKIT_DIR = ".fluidkit"
27
+ TYPESCRIPT_RUNTIME = "runtime.ts"
28
+
29
+ # Future language runtimes
30
+ PYTHON_RUNTIME = "runtime.py"
31
+ JAVASCRIPT_RUNTIME = "runtime.js"
32
+