ask2api 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.4
2
+ Name: ask2api
3
+ Version: 0.1.0
4
+ Summary: A minimal CLI tool that turns natural language into instant APIs.
5
+ Project-URL: Homepage, https://github.com/atasoglu/ask2api
6
+ Project-URL: Repository, https://github.com/atasoglu/ask2api.git
7
+ Author-email: Ahmet Atasoglu <ahmetatasoglu98@gmail.com>
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.9
10
+ Requires-Dist: requests
11
+ Provides-Extra: dev
12
+ Requires-Dist: pre-commit; extra == 'dev'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # ask2api
16
+
17
+ [![CI](https://github.com/atasoglu/ask2api/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/atasoglu/ask2api/actions/workflows/pre-commit.yml)
18
+ [![PyPI version](https://badge.fury.io/py/ask2api.svg)](https://badge.fury.io/py/ask2api)
19
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
20
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
21
+
22
+ `ask2api` is a minimal Python CLI tool that turns natural language prompts into structured API-style JSON responses using LLM.
23
+
24
+ It allows you to define a JSON Schema and force the model to answer strictly in that format.
25
+
26
+ ## Why ask2api?
27
+
28
+ Because LLMs are no longer just chatbots, they are also programmable API engines.
29
+
30
+ `ask2api` lets you use them that way. 🚀
31
+
32
+ Key features:
33
+
34
+ - Minimal dependencies
35
+ - CLI first
36
+ - Prompt → API behavior
37
+ - No markdown, no explanations, only valid JSON
38
+ - Designed for automation pipelines and AI-driven backend workflows
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install ask2api
44
+ ```
45
+
46
+ Set your OpenAI key:
47
+
48
+ ```bash
49
+ export OPENAI_API_KEY="your_api_key"
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ Instead of asking:
55
+
56
+ > *“Where is the capital of France?”*
57
+
58
+ and receiving free-form text, you can do this:
59
+
60
+ ```bash
61
+ ask2api -p "Where is the capital of France?" -sf schema.json
62
+ ```
63
+
64
+ And get a structured API response:
65
+
66
+ ```json
67
+ {
68
+ "country": "France",
69
+ "city": "Paris"
70
+ }
71
+ ```
72
+
73
+ ## How it works
74
+
75
+ 1. You define the desired output structure using a JSON Schema.
76
+ 2. The schema is passed to the model using OpenAI’s `json_schema` structured output format.
77
+ 3. The system prompt enforces strict JSON-only responses.
78
+ 4. The CLI prints the API-ready JSON output.
79
+
80
+ The model is treated as a deterministic API function.
81
+
82
+ ## Example schema
83
+
84
+ Create a file named `schema.json`:
85
+
86
+ ```json
87
+ {
88
+ "type": "object",
89
+ "properties": {
90
+ "country": { "type": "string" },
91
+ "city": { "type": "string" }
92
+ },
93
+ "required": ["country", "city"]
94
+ }
95
+ ```
96
+
97
+ ## Contributing
98
+
99
+ Contributions are welcome! Please feel free to submit a Pull Request.
100
+
101
+ ## License
102
+
103
+ MIT
@@ -0,0 +1,6 @@
1
+ ask2api.py,sha256=MabDrMBi6ELowSbuM51Lw7bmfspY4lR-sglO3ur9RYg,1432
2
+ ask2api-0.1.0.dist-info/METADATA,sha256=DCJVZAR8wJHsT1VRg-WlrfRqqw5aMd9SqSBu5VXv1Zw,2585
3
+ ask2api-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ ask2api-0.1.0.dist-info/entry_points.txt,sha256=__s21I8FDMqz0E7zrmwD3mIFPICVj0jNPIp9UWC9A0o,41
5
+ ask2api-0.1.0.dist-info/licenses/LICENSE,sha256=THtz5cxVhBW1uaP1MuBSwc9wCLXGWQfzXFXtIpC1kHA,1062
6
+ ask2api-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ask2api = ask2api:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ahmet
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.
ask2api.py ADDED
@@ -0,0 +1,52 @@
1
+ import argparse
2
+ import json
3
+ import os
4
+ import requests
5
+
6
+ API_KEY = os.getenv("OPENAI_API_KEY")
7
+ OPENAI_URL = "https://api.openai.com/v1/chat/completions"
8
+
9
+
10
+ def main():
11
+ parser = argparse.ArgumentParser()
12
+ parser.add_argument("-p", "--prompt", required=True)
13
+ parser.add_argument("-sf", "--schema-file", required=True)
14
+ args = parser.parse_args()
15
+
16
+ with open(args.schema_file, "r", encoding="utf-8") as f:
17
+ schema = json.load(f)
18
+
19
+ system_prompt = """
20
+ You are a JSON API engine.
21
+
22
+ You must answer every user request as a valid API response that strictly
23
+ follows the given JSON schema.
24
+
25
+ Never return markdown, comments or extra text.
26
+ """
27
+
28
+ payload = {
29
+ "model": "gpt-4.1",
30
+ "messages": [
31
+ {"role": "system", "content": system_prompt},
32
+ {"role": "user", "content": args.prompt},
33
+ ],
34
+ "response_format": {
35
+ "type": "json_schema",
36
+ "json_schema": {"name": "ask2api_schema", "schema": schema},
37
+ },
38
+ "temperature": 0,
39
+ }
40
+
41
+ headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
42
+
43
+ r = requests.post(OPENAI_URL, headers=headers, json=payload)
44
+ r.raise_for_status()
45
+
46
+ result = r.json()["choices"][0]["message"]["content"]
47
+ parsed_result = json.loads(result)
48
+ print(json.dumps(parsed_result, indent=2, ensure_ascii=False))
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()