Skip to main content

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

  1. Copy your cURL command to clipboard

  2. 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
    
  3. 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

  1. Clone the repository:

    git clone https://github.com/tadeasf/curl-to-context.git
    cd curl-to-context
    
  2. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Issues

If you find any bugs or have feature requests, please create an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curl_to_context-1.0.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curl_to_context-1.0.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file curl_to_context-1.0.0.tar.gz.

File metadata

  • Download URL: curl_to_context-1.0.0.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

Hashes for curl_to_context-1.0.0.tar.gz
Algorithm Hash digest
SHA256 98e5a300c4a0b6d7bd8d1da99c3793300917efb5484c1a240aabb4c7887b172e
MD5 085a4e27efe254eed3c6ed5af15dc3b9
BLAKE2b-256 f656e1823a316b42b7854ccf10d47efaa6b76b679e855aaf03191b087e57bdd2

See more details on using hashes here.

File details

Details for the file curl_to_context-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for curl_to_context-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce48f98454fe95c2d8e1c50587431510ddbc8bc2180f546d8caef6bd612d43d2
MD5 3a4906ec3795acb6d5f2a0bda096c9c9
BLAKE2b-256 ca129df24664aebd6ca7e49f9dd4a828d45d8155f54dd8a94b6112c4e9031203

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page