curl2python 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.
@@ -0,0 +1,3 @@
1
+ MIT License
2
+ Copyright (c) 2026 Ayush Thakkar
3
+ Permission is hereby granted...
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: curl2python
3
+ Version: 0.1.0
4
+ Summary: Convert curl commands to Python requests code
5
+ Author: Ayush Thakkar
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: requests
11
+ Dynamic: license-file
12
+
13
+ # curl-converter
14
+
15
+ Convert curl commands into Python requests code.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install curl-converter
@@ -0,0 +1,8 @@
1
+ # curl-converter
2
+
3
+ Convert curl commands into Python requests code.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install curl-converter
@@ -0,0 +1,27 @@
1
+
2
+
3
+ [project]
4
+ name = "curl2python"
5
+ version = "0.1.0"
6
+ description = "Convert curl commands to Python requests code"
7
+ readme = "README.md"
8
+ authors = [{name="Ayush Thakkar"}]
9
+ license = {text = "MIT"}
10
+ requires-python = ">=3.8"
11
+
12
+ dependencies = [
13
+ "requests"
14
+ ]
15
+
16
+ [project.scripts]
17
+ curl-converter = "curl_converter.cli:main"
18
+
19
+ [build-system]
20
+ requires = ["setuptools", "wheel"]
21
+ build-backend = "setuptools.build_meta"
22
+
23
+ [tool.setuptools]
24
+ package-dir = {"" = "src"}
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: curl2python
3
+ Version: 0.1.0
4
+ Summary: Convert curl commands to Python requests code
5
+ Author: Ayush Thakkar
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: requests
11
+ Dynamic: license-file
12
+
13
+ # curl-converter
14
+
15
+ Convert curl commands into Python requests code.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install curl-converter
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/curl2python.egg-info/PKG-INFO
5
+ src/curl2python.egg-info/SOURCES.txt
6
+ src/curl2python.egg-info/dependency_links.txt
7
+ src/curl2python.egg-info/entry_points.txt
8
+ src/curl2python.egg-info/requires.txt
9
+ src/curl2python.egg-info/top_level.txt
10
+ src/curl_converter/__init__.py
11
+ src/curl_converter/cli.py
12
+ src/curl_converter/extract_configs.py
13
+ src/curl_converter/using_playwright.py
14
+ tests/test_converter.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ curl-converter = curl_converter.cli:main
@@ -0,0 +1 @@
1
+ requests
@@ -0,0 +1 @@
1
+ curl_converter
@@ -0,0 +1,3 @@
1
+ from .extract_configs import get_configs
2
+
3
+ __all__ = ["get_configs"]
@@ -0,0 +1,15 @@
1
+ import argparse
2
+ from .extract_configs import get_configs
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(description="Convert curl to Python requests")
6
+ parser.add_argument("curl", help="curl command")
7
+
8
+ args = parser.parse_args()
9
+
10
+ result = get_configs(args.curl)
11
+
12
+ print(result)
13
+
14
+ if __name__ == "__main__":
15
+ main()
@@ -0,0 +1,65 @@
1
+ import ast
2
+ from using_playwright import curl_to_python
3
+ def extract_request_details(code):
4
+ tree = ast.parse(code)
5
+
6
+ result = {
7
+ "method": None,
8
+ "url": None,
9
+ "headers": None,
10
+ "cookies": None,
11
+ "params": None,
12
+ "data": None,
13
+ "json": None,
14
+ "files": None
15
+ }
16
+
17
+ variables = {}
18
+
19
+ class Visitor(ast.NodeVisitor):
20
+ def visit_Assign(self, node):
21
+ if isinstance(node.targets[0], ast.Name):
22
+ name = node.targets[0].id
23
+ try:
24
+ variables[name] = ast.literal_eval(node.value)
25
+ except:
26
+ pass
27
+ self.generic_visit(node)
28
+
29
+ def visit_Call(self, node):
30
+ if isinstance(node.func, ast.Attribute):
31
+
32
+ if node.func.attr in [
33
+ "get", "post", "put", "delete", "patch", "request"
34
+ ]:
35
+ result["method"] = node.func.attr.upper()
36
+
37
+ if node.args:
38
+ result["url"] = ast.literal_eval(node.args[0])
39
+
40
+ for kw in node.keywords:
41
+ key = kw.arg
42
+
43
+ try:
44
+ value = ast.literal_eval(kw.value)
45
+ except:
46
+ if isinstance(kw.value, ast.Name):
47
+ value = variables.get(kw.value.id)
48
+ else:
49
+ value = None
50
+
51
+ if key in result:
52
+ result[key] = value
53
+
54
+ self.generic_visit(node)
55
+
56
+ Visitor().visit(tree)
57
+ return result
58
+
59
+ def get_configs(curl_text):
60
+ # Example usage
61
+ code = curl_to_python(curl_text)
62
+
63
+ details = extract_request_details(code)
64
+
65
+ return details
@@ -0,0 +1,16 @@
1
+ from playwright.sync_api import sync_playwright
2
+
3
+ def curl_to_python(curl_text):
4
+ with sync_playwright() as p:
5
+ browser = p.chromium.launch(headless=True) # must be False
6
+ context = browser.new_context(permissions=["clipboard-read", "clipboard-write"])
7
+ page = context.new_page()
8
+
9
+ page.goto("https://curlconverter.com/")
10
+
11
+ page.fill("#curl-code", curl_text)
12
+
13
+ page.click("#copy-to-clipboard a")
14
+
15
+ copied = page.evaluate("navigator.clipboard.readText()")
16
+ return copied
File without changes