agentr 0.1.5__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
agentr/utils/openapi.py CHANGED
@@ -1,185 +1,186 @@
1
- import json
2
- import yaml
3
- from pathlib import Path
4
-
5
- def load_schema(path: Path):
6
- if path.suffix == '.yaml':
7
- type = 'yaml'
8
- else:
9
- type = 'json'
10
- with open(path, 'r') as f:
11
- if type == 'yaml':
12
- return yaml.safe_load(f)
13
- else:
14
- return json.load(f)
15
-
16
- def generate_api_client(schema):
17
- """
18
- Generate a Python API client class from an OpenAPI schema.
19
-
20
- Args:
21
- schema (dict): The OpenAPI schema as a dictionary.
22
-
23
- Returns:
24
- str: A string containing the Python code for the API client class.
25
- """
26
- methods = []
27
-
28
- # Iterate over paths and their operations
29
- for path, path_info in schema.get('paths', {}).items():
30
- for method in path_info:
31
- if method in ['get', 'post', 'put', 'delete', 'patch', 'options', 'head']:
32
- operation = path_info[method]
33
- method_code = generate_method_code(path, method, operation)
34
- methods.append(method_code)
35
-
36
- # Construct the class code
37
- class_code = (
38
- "import requests\n\n"
39
- "class APIClient:\n"
40
- " def __init__(self, base_url):\n"
41
- " self.base_url = base_url\n\n" +
42
- '\n\n'.join(methods)
43
- )
44
- return class_code
45
-
46
- def generate_method_code(path, method, operation):
47
- """
48
- Generate the code for a single API method.
49
-
50
- Args:
51
- path (str): The API path (e.g., '/users/{user_id}').
52
- method (str): The HTTP method (e.g., 'get').
53
- operation (dict): The operation details from the schema.
54
-
55
- Returns:
56
- str: The Python code for the method.
57
- """
58
- # Determine function name
59
- if 'operationId' in operation:
60
- func_name = operation['operationId']
61
- else:
62
- # Generate name from path and method
63
- path_parts = path.strip('/').split('/')
64
- name_parts = [method]
65
- for part in path_parts:
66
- if part.startswith('{') and part.endswith('}'):
67
- name_parts.append('by_' + part[1:-1])
68
- else:
69
- name_parts.append(part)
70
- func_name = '_'.join(name_parts).replace('-', '_').lower()
71
-
72
- # Get parameters and request body
73
- parameters = operation.get('parameters', [])
74
- has_body = 'requestBody' in operation
75
- body_required = has_body and operation['requestBody'].get('required', False)
76
-
77
- # Build function arguments
78
- args = []
79
- for param in parameters:
80
- if param.get('required', False):
81
- args.append(param['name'])
82
- else:
83
- args.append(f"{param['name']}=None")
84
- if has_body:
85
- args.append('body' if body_required else 'body=None')
86
- signature = f"def {func_name}(self, {', '.join(args)}):"
87
-
88
- # Build method body
89
- body_lines = []
90
-
91
- # Path parameters
92
- path_params = [p for p in parameters if p['in'] == 'path']
93
- path_params_dict = ', '.join([f"'{p['name']}': {p['name']}" for p in path_params])
94
- body_lines.append(f" path_params = {{{path_params_dict}}}")
95
-
96
- # Query parameters
97
- query_params = [p for p in parameters if p['in'] == 'query']
98
- query_params_items = ', '.join([f"('{p['name']}', {p['name']})" for p in query_params])
99
- body_lines.append(
100
- f" query_params = {{k: v for k, v in [{query_params_items}] if v is not None}}"
101
- )
102
-
103
- # Format URL
104
- body_lines.append(f" url = f\"{{self.base_url}}{path}\".format_map(path_params)")
105
-
106
- # Make HTTP request
107
- method_func = method.lower()
108
- if has_body:
109
- body_lines.append(" if body is not None:")
110
- body_lines.append(f" response = requests.{method_func}(url, params=query_params, json=body)")
111
- body_lines.append(" else:")
112
- body_lines.append(f" response = requests.{method_func}(url, params=query_params)")
113
- else:
114
- body_lines.append(f" response = requests.{method_func}(url, params=query_params)")
115
-
116
- # Handle response
117
- body_lines.append(" response.raise_for_status()")
118
- body_lines.append(" return response.json()")
119
-
120
- return signature + '\n' + '\n'.join(body_lines)
121
-
122
- # Example usage
123
- if __name__ == "__main__":
124
- # Sample OpenAPI schema
125
- schema = {
126
- "paths": {
127
- "/users": {
128
- "get": {
129
- "summary": "Get a list of users",
130
- "parameters": [
131
- {
132
- "name": "limit",
133
- "in": "query",
134
- "required": False,
135
- "schema": {"type": "integer"}
136
- }
137
- ],
138
- "responses": {
139
- "200": {
140
- "description": "A list of users",
141
- "content": {"application/json": {"schema": {"type": "array"}}}
142
- }
143
- }
144
- },
145
- "post": {
146
- "summary": "Create a user",
147
- "requestBody": {
148
- "required": True,
149
- "content": {
150
- "application/json": {
151
- "schema": {
152
- "type": "object",
153
- "properties": {"name": {"type": "string"}}
154
- }
155
- }
156
- }
157
- },
158
- "responses": {
159
- "201": {"description": "User created"}
160
- }
161
- }
162
- },
163
- "/users/{user_id}": {
164
- "get": {
165
- "summary": "Get a user by ID",
166
- "parameters": [
167
- {
168
- "name": "user_id",
169
- "in": "path",
170
- "required": True,
171
- "schema": {"type": "string"}
172
- }
173
- ],
174
- "responses": {
175
- "200": {"description": "User details"}
176
- }
177
- }
178
- }
179
- }
180
- }
181
-
182
-
183
- schema = load_schema('openapi.yaml')
184
- code = generate_api_client(schema)
1
+ import json
2
+ import yaml
3
+ from pathlib import Path
4
+
5
+
6
+ def load_schema(path: Path):
7
+ if path.suffix == '.yaml':
8
+ type = 'yaml'
9
+ else:
10
+ type = 'json'
11
+ with open(path, 'r') as f:
12
+ if type == 'yaml':
13
+ return yaml.safe_load(f)
14
+ else:
15
+ return json.load(f)
16
+
17
+ def generate_api_client(schema):
18
+ """
19
+ Generate a Python API client class from an OpenAPI schema.
20
+
21
+ Args:
22
+ schema (dict): The OpenAPI schema as a dictionary.
23
+
24
+ Returns:
25
+ str: A string containing the Python code for the API client class.
26
+ """
27
+ methods = []
28
+
29
+ # Iterate over paths and their operations
30
+ for path, path_info in schema.get('paths', {}).items():
31
+ for method in path_info:
32
+ if method in ['get', 'post', 'put', 'delete', 'patch', 'options', 'head']:
33
+ operation = path_info[method]
34
+ method_code = generate_method_code(path, method, operation)
35
+ methods.append(method_code)
36
+
37
+ # Construct the class code
38
+ class_code = (
39
+ "import requests\n\n"
40
+ "class APIClient:\n"
41
+ " def __init__(self, base_url):\n"
42
+ " self.base_url = base_url\n\n" +
43
+ '\n\n'.join(methods)
44
+ )
45
+ return class_code
46
+
47
+ def generate_method_code(path, method, operation):
48
+ """
49
+ Generate the code for a single API method.
50
+
51
+ Args:
52
+ path (str): The API path (e.g., '/users/{user_id}').
53
+ method (str): The HTTP method (e.g., 'get').
54
+ operation (dict): The operation details from the schema.
55
+
56
+ Returns:
57
+ str: The Python code for the method.
58
+ """
59
+ # Determine function name
60
+ if 'operationId' in operation:
61
+ func_name = operation['operationId']
62
+ else:
63
+ # Generate name from path and method
64
+ path_parts = path.strip('/').split('/')
65
+ name_parts = [method]
66
+ for part in path_parts:
67
+ if part.startswith('{') and part.endswith('}'):
68
+ name_parts.append('by_' + part[1:-1])
69
+ else:
70
+ name_parts.append(part)
71
+ func_name = '_'.join(name_parts).replace('-', '_').lower()
72
+
73
+ # Get parameters and request body
74
+ parameters = operation.get('parameters', [])
75
+ has_body = 'requestBody' in operation
76
+ body_required = has_body and operation['requestBody'].get('required', False)
77
+
78
+ # Build function arguments
79
+ args = []
80
+ for param in parameters:
81
+ if param.get('required', False):
82
+ args.append(param['name'])
83
+ else:
84
+ args.append(f"{param['name']}=None")
85
+ if has_body:
86
+ args.append('body' if body_required else 'body=None')
87
+ signature = f"def {func_name}(self, {', '.join(args)}):"
88
+
89
+ # Build method body
90
+ body_lines = []
91
+
92
+ # Path parameters
93
+ path_params = [p for p in parameters if p['in'] == 'path']
94
+ path_params_dict = ', '.join([f"'{p['name']}': {p['name']}" for p in path_params])
95
+ body_lines.append(f" path_params = {{{path_params_dict}}}")
96
+
97
+ # Query parameters
98
+ query_params = [p for p in parameters if p['in'] == 'query']
99
+ query_params_items = ', '.join([f"('{p['name']}', {p['name']})" for p in query_params])
100
+ body_lines.append(
101
+ f" query_params = {{k: v for k, v in [{query_params_items}] if v is not None}}"
102
+ )
103
+
104
+ # Format URL
105
+ body_lines.append(f" url = f\"{{self.base_url}}{path}\".format_map(path_params)")
106
+
107
+ # Make HTTP request
108
+ method_func = method.lower()
109
+ if has_body:
110
+ body_lines.append(" if body is not None:")
111
+ body_lines.append(f" response = requests.{method_func}(url, params=query_params, json=body)")
112
+ body_lines.append(" else:")
113
+ body_lines.append(f" response = requests.{method_func}(url, params=query_params)")
114
+ else:
115
+ body_lines.append(f" response = requests.{method_func}(url, params=query_params)")
116
+
117
+ # Handle response
118
+ body_lines.append(" response.raise_for_status()")
119
+ body_lines.append(" return response.json()")
120
+
121
+ return signature + '\n' + '\n'.join(body_lines)
122
+
123
+ # Example usage
124
+ if __name__ == "__main__":
125
+ # Sample OpenAPI schema
126
+ schema = {
127
+ "paths": {
128
+ "/users": {
129
+ "get": {
130
+ "summary": "Get a list of users",
131
+ "parameters": [
132
+ {
133
+ "name": "limit",
134
+ "in": "query",
135
+ "required": False,
136
+ "schema": {"type": "integer"}
137
+ }
138
+ ],
139
+ "responses": {
140
+ "200": {
141
+ "description": "A list of users",
142
+ "content": {"application/json": {"schema": {"type": "array"}}}
143
+ }
144
+ }
145
+ },
146
+ "post": {
147
+ "summary": "Create a user",
148
+ "requestBody": {
149
+ "required": True,
150
+ "content": {
151
+ "application/json": {
152
+ "schema": {
153
+ "type": "object",
154
+ "properties": {"name": {"type": "string"}}
155
+ }
156
+ }
157
+ }
158
+ },
159
+ "responses": {
160
+ "201": {"description": "User created"}
161
+ }
162
+ }
163
+ },
164
+ "/users/{user_id}": {
165
+ "get": {
166
+ "summary": "Get a user by ID",
167
+ "parameters": [
168
+ {
169
+ "name": "user_id",
170
+ "in": "path",
171
+ "required": True,
172
+ "schema": {"type": "string"}
173
+ }
174
+ ],
175
+ "responses": {
176
+ "200": {"description": "User details"}
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+
184
+ schema = load_schema('openapi.yaml')
185
+ code = generate_api_client(schema)
185
186
  print(code)
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentr
3
- Version: 0.1.5
4
- Summary: AgentR is a Python framework for building MCP servers to serve agentic applications and LLM clients
3
+ Version: 0.1.7
4
+ Summary: A python framework to build MCP servers
5
5
  Author-email: Manoj Bajaj <manojbajaj95@gmail.com>
6
6
  License-File: LICENSE
7
7
  Requires-Python: >=3.11
@@ -9,6 +9,9 @@ Requires-Dist: loguru>=0.7.3
9
9
  Requires-Dist: mcp>=1.5.0
10
10
  Requires-Dist: pyyaml>=6.0.2
11
11
  Requires-Dist: typer>=0.15.2
12
+ Provides-Extra: test
13
+ Requires-Dist: pytest-asyncio>=0.26.0; extra == 'test'
14
+ Requires-Dist: pytest>=8.3.5; extra == 'test'
12
15
  Description-Content-Type: text/markdown
13
16
 
14
17
  # AgentR
@@ -0,0 +1,25 @@
1
+ agentr/__init__.py,sha256=LOWhgQayrQV7f5ro4rlBJ_6WevhbWIbjAOHnqP7b_-4,30
2
+ agentr/application.py,sha256=r2o4PP0uDBFTkziseuOh7AobcVqnEWDoYJxN_UA7UVo,2932
3
+ agentr/cli.py,sha256=z0QOdyiBcypNE_npN2lYIkEcYZXG8Ji0027IcEuhDTs,2880
4
+ agentr/config.py,sha256=YTygfFJPUuL-epRuILvt5tc5ACzByWIFFNhpFwHlDCE,387
5
+ agentr/exceptions.py,sha256=hHlyXUZBjG4DfUurvqd0ZiruHC67gbpT6EHKxifwUhg,271
6
+ agentr/integration.py,sha256=BmtPpn2lXV7i6k6Uqu5g-LWpD9wRiMz7R3SgztLAktc,2663
7
+ agentr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ agentr/server.py,sha256=vg9YlApxlLvxcIn9h_Rz2IgatXv7aBj0pTTb6XWMRN4,4279
9
+ agentr/store.py,sha256=fB3uAaobnWf2ILcDBmg3ToDaqAIPYlLtmHBdpmkcGcI,1585
10
+ agentr/test.py,sha256=wtupsEMrn-Q9Ocjlhelk4YrVSrWMM5vwMBhnvepEaHo,917
11
+ agentr/applications/__init__.py,sha256=huqhhfMkSMjcc3eqVAprW03Drr98OHbH2Rh0GwGQHjs,942
12
+ agentr/applications/github/app.py,sha256=N-f9TX5btcUDr19H-eTG7NlFlb25fGENLZ07fFfQBg4,17301
13
+ agentr/applications/google_calendar/app.py,sha256=3mpqP0MsTYsJyZDF2Skgs1VLfLRr6E7OSOhbcAQ_L3E,25710
14
+ agentr/applications/google_mail/app.py,sha256=GWmJwgdpBKyNufsrHp2PkYzXNzyCb7XOHxZPYw6XaBA,23710
15
+ agentr/applications/reddit/app.py,sha256=iNkSRVGScj7Mae3e8N-Mkov_hvZrvH5NynbpO8mKToQ,842
16
+ agentr/applications/resend/app.py,sha256=ihRzP65bwoNIq3EzBqIghxgLZRxvy-LbHy-rER20ODo,1428
17
+ agentr/applications/tavily/app.py,sha256=D4FOhm2yxNbuTVHTo3T8ZsuE5AgwK874YutfYx2Njcw,1805
18
+ agentr/applications/zenquotes/app.py,sha256=4LjYeWdERI8ZMzkajOsDgy9IRTA9plUKem-rW4M03sA,607
19
+ agentr/utils/bridge.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ agentr/utils/openapi.py,sha256=DT4jcWue_Fx0J-wg7T53w3uMb5CIzn4u2QswmtpSFVU,6280
21
+ agentr-0.1.7.dist-info/METADATA,sha256=BUoooDf1WgcRVE-rVBD3W78W-FrhSGnvAmhbYbuV-TY,4388
22
+ agentr-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
+ agentr-0.1.7.dist-info/entry_points.txt,sha256=13fGFeVhgF6_8T-VFiIkNxYO7gDQaUwwTcUNWdvaLQg,42
24
+ agentr-0.1.7.dist-info/licenses/LICENSE,sha256=CPslwL9mT3MH-lEljRJQHKe646096G-szURVmOD18Lc,1063
25
+ agentr-0.1.7.dist-info/RECORD,,
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 AgentR
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AgentR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,23 +0,0 @@
1
- agentr/__init__.py,sha256=oESTO4raGTykM5npHqhuwinRY-zxPtdmeOzXV-se_Bo,31
2
- agentr/application.py,sha256=jDcYk8DArOJuE-HEn6_aCUtMn_ckrFpJuoAv4qzyr6c,1607
3
- agentr/cli.py,sha256=UndJFUcJ7MCZzlhQB3W70j1oi1a-aYb1pZyKODNtdX8,2872
4
- agentr/exceptions.py,sha256=7VusZ_ltcYK3pRcew_Kc8rSllQoxi2RvmxdntJgufqM,275
5
- agentr/integration.py,sha256=Btd7VwKb1T94s9ZKApMDAEFv7tlK4oxHfBvIYRAmUe8,3657
6
- agentr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- agentr/server.py,sha256=WB98K-BrSt77pp_wGTUnJa7Sjeyj_hFbbaB3hS9qnRA,4325
8
- agentr/store.py,sha256=IlCGsYjFIzVLsBnse5cuzS4egOn7osPr3zSUt3FwPvA,1655
9
- agentr/test.py,sha256=ijzm58aoCSJDAN-ObK2HludNMr2bbvPMURC7ah8wcu4,920
10
- agentr/applications/github/app.py,sha256=7ZOPDq95IaYza7IhNkB4zkeZmGDRxffhtRju6asUwLg,2005
11
- agentr/applications/google_calendar/app.py,sha256=9PFV_p0KbyuJslcaFnhDmqR6p3G7BR-3Ij5KIaPomTc,2914
12
- agentr/applications/google_mail/app.py,sha256=Pf_u0HE1Im7J9xe77RbknfaOmnspHRrKY40CpL270zU,2401
13
- agentr/applications/reddit/app.py,sha256=NLBPS0sAqUt5EVHeqcnAn4s6XD-KoapJjlLhSnsUgaY,871
14
- agentr/applications/resend/app.py,sha256=FWomwUKrrOHMptXO0P1wbe40JDyBvq_CC7Hrk0qcyWE,1471
15
- agentr/applications/tavily/app.py,sha256=WgnEqD0bROiDpliGEUSTww4vH5drRsHTBBGf8WRZacU,1862
16
- agentr/applications/zenquotes/app.py,sha256=WRK96H8cTWXRV-Z42QnOa1qfqzs6xmYTpxj1MJooYZM,627
17
- agentr/utils/bridge.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- agentr/utils/openapi.py,sha256=S9MyxrxAs87-WTYgzfKVWhroxIB98_nBG1Ksac0x_pU,6463
19
- agentr-0.1.5.dist-info/METADATA,sha256=ymYJ5lo3pwpumAAyyIzqX7p1MZtUaGi5s99Wgi4k2zU,4326
20
- agentr-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
- agentr-0.1.5.dist-info/entry_points.txt,sha256=13fGFeVhgF6_8T-VFiIkNxYO7gDQaUwwTcUNWdvaLQg,42
22
- agentr-0.1.5.dist-info/licenses/LICENSE,sha256=vXWvmZhTURz0cuRxzRypSABVSncu9X8-XhwdC1yo6J0,1084
23
- agentr-0.1.5.dist-info/RECORD,,
File without changes