@hey-api/openapi-python 0.0.0-next-20260621204633 → 0.0.0-next-20260624063741

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.
package/README.md CHANGED
@@ -61,25 +61,6 @@ Partners behind the future of API tooling. [Become a sponsor](https://github.com
61
61
 
62
62
  <table align="center">
63
63
  <tbody>
64
- <tr>
65
- <td align="center" width="50%">
66
- <p></p>
67
- <p>
68
- <a href="https://kutt.to/pkEZyc" target="_blank">
69
- <picture height="50px">
70
- <source media="(prefers-color-scheme: dark)" srcset="https://heyapi.dev/assets/.gen/stainless-logo-wordmark-480w.jpeg">
71
- <img alt="Stainless logo" height="50px" src="https://heyapi.dev/assets/.gen/stainless-logo-wordmark-480w.jpeg">
72
- </picture>
73
- </a>
74
- <br/>
75
- Best-in-class developer interfaces for your API.
76
- <br/>
77
- <a href="https://kutt.to/pkEZyc" style="text-decoration:none;" target="_blank">
78
- stainless.com
79
- </a>
80
- </p>
81
- <p></p>
82
- </td>
83
64
  <td align="center" width="50%">
84
65
  <p></p>
85
66
  <p>
package/bin/run.js CHANGED
@@ -1,18 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
2
 
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
- const target = path.join(__dirname, '..', 'dist', 'run.mjs');
9
-
10
- if (!fs.existsSync(target)) {
11
- console.error('openapi-python not built (expect dist/run.mjs)');
12
- process.exit(1);
3
+ try {
4
+ await import('../dist/run.mjs');
5
+ } catch (error) {
6
+ if (error.code === 'ERR_MODULE_NOT_FOUND') {
7
+ console.error('openapi-python not built (expected dist/run.mjs)');
8
+ process.exit(1);
9
+ }
10
+ throw error;
13
11
  }
14
-
15
- const res = spawnSync(process.execPath, [target, ...process.argv.slice(2)], {
16
- stdio: 'inherit',
17
- });
18
- process.exit(res.status ?? 0);
@@ -0,0 +1,3 @@
1
+ from .client import Client, build_client_params, create_client
2
+
3
+ __all__ = ["Client", "build_client_params", "create_client"]
@@ -0,0 +1,128 @@
1
+ from typing import Any, Optional
2
+ import httpx
3
+
4
+
5
+ EXTRA_PREFIXES_MAP = {
6
+ "$body_": "json",
7
+ "$headers_": "headers",
8
+ "$path_": "path",
9
+ "$query_": "params",
10
+ }
11
+
12
+
13
+ def build_client_params(fields: list[dict[str, Any]], **kwargs) -> dict[str, Any]:
14
+ """Build client parameters from flat keyword arguments.
15
+
16
+ Args:
17
+ fields: List of field configurations with 'in', 'key', and optional 'map'.
18
+ **kwargs: Flat parameters passed to the SDK method.
19
+
20
+ Returns:
21
+ Dict suitable for httpx client methods: {params: {...}, headers: {...}, json: Any}
22
+ """
23
+ result: dict[str, Any] = {}
24
+
25
+ key_map = {}
26
+ for field in fields:
27
+ key = field.get("key")
28
+ if key:
29
+ key_map[key] = {
30
+ "in": field.get("in"),
31
+ "map": field.get("map", key),
32
+ }
33
+
34
+ for key, value in kwargs.items():
35
+ if value is None:
36
+ continue
37
+
38
+ field = key_map.get(key)
39
+
40
+ if field:
41
+ in_slot = field["in"]
42
+ map_key = field["map"]
43
+ slot = "json" if in_slot == "body" else in_slot
44
+
45
+ if in_slot == "body":
46
+ result[slot] = value
47
+ else:
48
+ if slot not in result:
49
+ result[slot] = {}
50
+ result[slot][map_key] = value
51
+ else:
52
+ for prefix, slot in EXTRA_PREFIXES_MAP.items():
53
+ if key.startswith(prefix):
54
+ actual_key = key[len(prefix) :]
55
+ if slot not in result:
56
+ result[slot] = {}
57
+ result[slot][actual_key] = value
58
+ break
59
+ else:
60
+ if "params" not in result:
61
+ result["params"] = {}
62
+ result["params"][key] = value
63
+
64
+ for slot in list(result.keys()):
65
+ if not result[slot]:
66
+ del result[slot]
67
+
68
+ return result
69
+
70
+
71
+ class BaseClient:
72
+ """Base HTTP client using httpx that SDK classes extend."""
73
+
74
+ def __init__(self, client: Optional[httpx.Client] = None, base_url: Optional[str] = None, **kwargs):
75
+ if client is not None:
76
+ self._client = client
77
+ else:
78
+ self._client = httpx.Client(base_url=base_url or "", **kwargs)
79
+
80
+ @property
81
+ def client(self) -> httpx.Client:
82
+ """Get the httpx client instance."""
83
+ return self._client
84
+
85
+ def request(self, method: str, url: str, **kwargs) -> httpx.Response:
86
+ """Make an HTTP request."""
87
+ return self._client.request(method, url, **kwargs)
88
+
89
+ def get(self, url: str, **kwargs) -> httpx.Response:
90
+ """Make a GET request."""
91
+ return self._client.get(url, **kwargs)
92
+
93
+ def post(self, url: str, **kwargs) -> httpx.Response:
94
+ """Make a POST request."""
95
+ return self._client.post(url, **kwargs)
96
+
97
+ def put(self, url: str, **kwargs) -> httpx.Response:
98
+ """Make a PUT request."""
99
+ return self._client.put(url, **kwargs)
100
+
101
+ def patch(self, url: str, **kwargs) -> httpx.Response:
102
+ """Make a PATCH request."""
103
+ return self._client.patch(url, **kwargs)
104
+
105
+ def delete(self, url: str, **kwargs) -> httpx.Response:
106
+ """Make a DELETE request."""
107
+ return self._client.delete(url, **kwargs)
108
+
109
+ def close(self):
110
+ """Close the client."""
111
+ self._client.close()
112
+
113
+ def __enter__(self):
114
+ return self
115
+
116
+ def __exit__(self, *args):
117
+ self.close()
118
+
119
+
120
+ class Client(BaseClient):
121
+ """HTTP client using httpx (alias for BaseClient)."""
122
+
123
+ pass
124
+
125
+
126
+ def create_client(base_url: Optional[str] = None, **kwargs) -> Client:
127
+ """Create a new HTTP client instance."""
128
+ return Client(base_url=base_url, **kwargs)
@@ -0,0 +1,3 @@
1
+ from .client import Client, build_client_params, create_client
2
+
3
+ __all__ = ["Client", "build_client_params", "create_client"]
@@ -0,0 +1,128 @@
1
+ from typing import Any, Optional
2
+ import httpx
3
+
4
+
5
+ EXTRA_PREFIXES_MAP = {
6
+ "$body_": "json",
7
+ "$headers_": "headers",
8
+ "$path_": "path",
9
+ "$query_": "params",
10
+ }
11
+
12
+
13
+ def build_client_params(fields: list[dict[str, Any]], **kwargs) -> dict[str, Any]:
14
+ """Build client parameters from flat keyword arguments.
15
+
16
+ Args:
17
+ fields: List of field configurations with 'in', 'key', and optional 'map'.
18
+ **kwargs: Flat parameters passed to the SDK method.
19
+
20
+ Returns:
21
+ Dict suitable for httpx client methods: {params: {...}, headers: {...}, json: Any}
22
+ """
23
+ result: dict[str, Any] = {}
24
+
25
+ key_map = {}
26
+ for field in fields:
27
+ key = field.get("key")
28
+ if key:
29
+ key_map[key] = {
30
+ "in": field.get("in"),
31
+ "map": field.get("map", key),
32
+ }
33
+
34
+ for key, value in kwargs.items():
35
+ if value is None:
36
+ continue
37
+
38
+ field = key_map.get(key)
39
+
40
+ if field:
41
+ in_slot = field["in"]
42
+ map_key = field["map"]
43
+ slot = "json" if in_slot == "body" else in_slot
44
+
45
+ if in_slot == "body":
46
+ result[slot] = value
47
+ else:
48
+ if slot not in result:
49
+ result[slot] = {}
50
+ result[slot][map_key] = value
51
+ else:
52
+ for prefix, slot in EXTRA_PREFIXES_MAP.items():
53
+ if key.startswith(prefix):
54
+ actual_key = key[len(prefix) :]
55
+ if slot not in result:
56
+ result[slot] = {}
57
+ result[slot][actual_key] = value
58
+ break
59
+ else:
60
+ if "params" not in result:
61
+ result["params"] = {}
62
+ result["params"][key] = value
63
+
64
+ for slot in list(result.keys()):
65
+ if not result[slot]:
66
+ del result[slot]
67
+
68
+ return result
69
+
70
+
71
+ class BaseClient:
72
+ """Base HTTP client using httpx that SDK classes extend."""
73
+
74
+ def __init__(self, client: Optional[httpx.Client] = None, base_url: Optional[str] = None, **kwargs):
75
+ if client is not None:
76
+ self._client = client
77
+ else:
78
+ self._client = httpx.Client(base_url=base_url or "", **kwargs)
79
+
80
+ @property
81
+ def client(self) -> httpx.Client:
82
+ """Get the httpx client instance."""
83
+ return self._client
84
+
85
+ def request(self, method: str, url: str, **kwargs) -> httpx.Response:
86
+ """Make an HTTP request."""
87
+ return self._client.request(method, url, **kwargs)
88
+
89
+ def get(self, url: str, **kwargs) -> httpx.Response:
90
+ """Make a GET request."""
91
+ return self._client.get(url, **kwargs)
92
+
93
+ def post(self, url: str, **kwargs) -> httpx.Response:
94
+ """Make a POST request."""
95
+ return self._client.post(url, **kwargs)
96
+
97
+ def put(self, url: str, **kwargs) -> httpx.Response:
98
+ """Make a PUT request."""
99
+ return self._client.put(url, **kwargs)
100
+
101
+ def patch(self, url: str, **kwargs) -> httpx.Response:
102
+ """Make a PATCH request."""
103
+ return self._client.patch(url, **kwargs)
104
+
105
+ def delete(self, url: str, **kwargs) -> httpx.Response:
106
+ """Make a DELETE request."""
107
+ return self._client.delete(url, **kwargs)
108
+
109
+ def close(self):
110
+ """Close the client."""
111
+ self._client.close()
112
+
113
+ def __enter__(self):
114
+ return self
115
+
116
+ def __exit__(self, *args):
117
+ self.close()
118
+
119
+
120
+ class Client(BaseClient):
121
+ """HTTP client using httpx (alias for BaseClient)."""
122
+
123
+ pass
124
+
125
+
126
+ def create_client(base_url: Optional[str] = None, **kwargs) -> Client:
127
+ """Create a new HTTP client instance."""
128
+ return Client(base_url=base_url, **kwargs)
@@ -0,0 +1,3 @@
1
+ from .client import Client, build_client_params, create_client
2
+
3
+ __all__ = ["Client", "build_client_params", "create_client"]
@@ -0,0 +1,128 @@
1
+ from typing import Any, Optional
2
+ import httpx
3
+
4
+
5
+ EXTRA_PREFIXES_MAP = {
6
+ "$body_": "json",
7
+ "$headers_": "headers",
8
+ "$path_": "path",
9
+ "$query_": "params",
10
+ }
11
+
12
+
13
+ def build_client_params(fields: list[dict[str, Any]], **kwargs) -> dict[str, Any]:
14
+ """Build client parameters from flat keyword arguments.
15
+
16
+ Args:
17
+ fields: List of field configurations with 'in', 'key', and optional 'map'.
18
+ **kwargs: Flat parameters passed to the SDK method.
19
+
20
+ Returns:
21
+ Dict suitable for httpx client methods: {params: {...}, headers: {...}, json: Any}
22
+ """
23
+ result: dict[str, Any] = {}
24
+
25
+ key_map = {}
26
+ for field in fields:
27
+ key = field.get("key")
28
+ if key:
29
+ key_map[key] = {
30
+ "in": field.get("in"),
31
+ "map": field.get("map", key),
32
+ }
33
+
34
+ for key, value in kwargs.items():
35
+ if value is None:
36
+ continue
37
+
38
+ field = key_map.get(key)
39
+
40
+ if field:
41
+ in_slot = field["in"]
42
+ map_key = field["map"]
43
+ slot = "json" if in_slot == "body" else in_slot
44
+
45
+ if in_slot == "body":
46
+ result[slot] = value
47
+ else:
48
+ if slot not in result:
49
+ result[slot] = {}
50
+ result[slot][map_key] = value
51
+ else:
52
+ for prefix, slot in EXTRA_PREFIXES_MAP.items():
53
+ if key.startswith(prefix):
54
+ actual_key = key[len(prefix) :]
55
+ if slot not in result:
56
+ result[slot] = {}
57
+ result[slot][actual_key] = value
58
+ break
59
+ else:
60
+ if "params" not in result:
61
+ result["params"] = {}
62
+ result["params"][key] = value
63
+
64
+ for slot in list(result.keys()):
65
+ if not result[slot]:
66
+ del result[slot]
67
+
68
+ return result
69
+
70
+
71
+ class BaseClient:
72
+ """Base HTTP client using httpx that SDK classes extend."""
73
+
74
+ def __init__(self, client: Optional[httpx.Client] = None, base_url: Optional[str] = None, **kwargs):
75
+ if client is not None:
76
+ self._client = client
77
+ else:
78
+ self._client = httpx.Client(base_url=base_url or "", **kwargs)
79
+
80
+ @property
81
+ def client(self) -> httpx.Client:
82
+ """Get the httpx client instance."""
83
+ return self._client
84
+
85
+ def request(self, method: str, url: str, **kwargs) -> httpx.Response:
86
+ """Make an HTTP request."""
87
+ return self._client.request(method, url, **kwargs)
88
+
89
+ def get(self, url: str, **kwargs) -> httpx.Response:
90
+ """Make a GET request."""
91
+ return self._client.get(url, **kwargs)
92
+
93
+ def post(self, url: str, **kwargs) -> httpx.Response:
94
+ """Make a POST request."""
95
+ return self._client.post(url, **kwargs)
96
+
97
+ def put(self, url: str, **kwargs) -> httpx.Response:
98
+ """Make a PUT request."""
99
+ return self._client.put(url, **kwargs)
100
+
101
+ def patch(self, url: str, **kwargs) -> httpx.Response:
102
+ """Make a PATCH request."""
103
+ return self._client.patch(url, **kwargs)
104
+
105
+ def delete(self, url: str, **kwargs) -> httpx.Response:
106
+ """Make a DELETE request."""
107
+ return self._client.delete(url, **kwargs)
108
+
109
+ def close(self):
110
+ """Close the client."""
111
+ self._client.close()
112
+
113
+ def __enter__(self):
114
+ return self
115
+
116
+ def __exit__(self, *args):
117
+ self.close()
118
+
119
+
120
+ class Client(BaseClient):
121
+ """HTTP client using httpx (alias for BaseClient)."""
122
+
123
+ pass
124
+
125
+
126
+ def create_client(base_url: Optional[str] = None, **kwargs) -> Client:
127
+ """Create a new HTTP client instance."""
128
+ return Client(base_url=base_url, **kwargs)