Convert curl commands to Python code for Grab/Context frameworks
Project description
curl-to-context
A command-line tool to convert cURL commands into Python code for Grab or Context frameworks.
Installation
Install using pip:
pip install curl-to-context
Usage
Command Line
-
Copy your cURL command to clipboard
-
Run one of these commands:
Interactive mode - will ask you to choose framework curl-to-context Or specify framework directly curl-to-context -f grab # For Grab framework curl-to-context -f context # For Context framework
-
The converted Python code will be automatically copied to your clipboard
Example
Input (in clipboard):
bash
curl 'https://api.example.com/data' \
-H 'accept: application/json' \
-H 'cookie: session=abc123' \
-H 'user-agent: Mozilla/5.0'
Output (for Grab framework):
def method_name(self):
self.g.setup(cookies={
'session': 'abc123',
})
self.g.setup(headers={
'accept': 'application/json',
'user-agent': 'Mozilla/5.0',
})
# URL: https://api.example.com/data
Output (for Context framework):
def method_name(self):
self.context.cookies.update({
'session': 'abc123',
})
self.context.headers.update({
'accept': 'application/json',
'user-agent': 'Mozilla/5.0',
})
# URL: https://api.example.com/data
Features
- Converts cURL commands to Python code
- Supports both Grab and Context frameworks
- Extracts and formats:
- Cookies
- Headers
- URL
- POST data (if present)
- Uses clipboard for easy copy-paste workflow
- Interactive framework selection
Requirements
- Python 3.8 or higher
- pyperclip
Development
-
Clone the repository:
git clone https://github.com/tadeasf/curl-to-context.git cd curl-to-context
-
Install dependencies using Rye:
rye run convert
License
GPL 3.0
Author
tadeasf business@tadeasfort.com
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Issues
If you find any bugs or have feature requests, please create an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file curl_to_context-1.0.1.tar.gz.
File metadata
- Download URL: curl_to_context-1.0.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56557a62a1a0e11efc3a4c0ebe3c765fe33fd250b05d7f9391a28424e64b79ed
|
|
| MD5 |
ee77a3098da129581e4998bab07e8717
|
|
| BLAKE2b-256 |
8e60788011bbe087b55d74bfa7b521b1d688176887733de5ca40b5c281ccf144
|
File details
Details for the file curl_to_context-1.0.1-py3-none-any.whl.
File metadata
- Download URL: curl_to_context-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ce4b4ba02e23e78619b510a720feb022eeb8f8e855432034e00dc259d8e21e7
|
|
| MD5 |
51d626a434a0b64bbe209a53397b8cf8
|
|
| BLAKE2b-256 |
ef4e8dfec1d983b92ae0007b4da0bac4be89db9a9545497ba535eebbbeb5a25c
|