Skip to main content

Convert curl commands to Python code for Grab/Context frameworks

Project description

curlpyconvert

A command-line tool to convert cURL commands into Python code for Grab or Context frameworks.

Installation

Install using pip:

pip install curlpyconvert

Or install from source:

git clone https://github.com/tadeasf/curlpyconvert.git
cd curlpyconvert
rye sync

Usage

Command Line

  1. Copy your cURL command to clipboard

  2. Run one of these commands:

    # Interactive mode - will ask you to choose framework
    curlpyconvert
    
    # Or specify framework directly
    curlpyconvert -f grab    # For Grab framework
    curlpyconvert -f context # For Context framework
    
    # Show output instead of copying to clipboard
    curlpyconvert -f grab -s
    
  3. The converted Python code will be automatically copied to your clipboard (unless -s flag is used)

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
  • Rich terminal output with syntax highlighting

Requirements

  • Python 3.10 or higher
  • Dependencies (automatically installed):
    • pyperclip
    • typer
    • rich
    • six

Development

  1. Clone the repository:

    git clone https://github.com/tadeasf/curlpyconvert.git
    cd curlpyconvert
    
  2. Install development dependencies:

    rye sync  # or: pip install -e ".[dev]"
    
  3. Run tests:

    rye run pytest  # or: pytest
    
  4. Build the package:

    rye build  # Creates dist/ directory with wheel and tar.gz
    
  5. Publish to PyPI:

    rye publish  # Uploads to PyPI
    

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.

Test

From project root: rye run pytest # If using Rye pytest # If installed in development mode with pip

  • With coverage:

rye run pytest --cov=curlpyconvert

  • Specific test file: pytest src/curlpyconvert/test/test_curl_parser.py

  • Build rye build # Creates dist/ directory with wheel and tar.gz

  • Publish to PyPI rye publish

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

curlpyconvert-4.0.7.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

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

curlpyconvert-4.0.7-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file curlpyconvert-4.0.7.tar.gz.

File metadata

  • Download URL: curlpyconvert-4.0.7.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for curlpyconvert-4.0.7.tar.gz
Algorithm Hash digest
SHA256 b959d8b24e52d4f3a1f9c0e16cefd2551fd443c1f2d5711cee60c6510bcbc4f6
MD5 8f0b2ae8d44bacd02b324089ca3c0d89
BLAKE2b-256 bee886ff0dea5c3f32e9b67133c9db66500b8b81f51bab319987c102a21d4d43

See more details on using hashes here.

File details

Details for the file curlpyconvert-4.0.7-py3-none-any.whl.

File metadata

  • Download URL: curlpyconvert-4.0.7-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for curlpyconvert-4.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 076674bad6120bf2efa0b79c0340918a976e0a38e71c102abb336f29816f0b5c
MD5 7abb44397f3c129916ff26b32636d63e
BLAKE2b-256 87a9ae49e640c52ab6c38a3f582697fe3cf6643559e7ca6c6c6ed0da7d3a2e9c

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