Skip to main content

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

Or install from source:

git clone https://github.com/tadeasf/curl-to-context.git
cd curl-to-context
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
    curl-to-context
    
    # Or specify framework directly
    curl-to-context -f grab    # For Grab framework
    curl-to-context -f context # For Context framework
    
    # Show output instead of copying to clipboard
    curl-to-context -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/curl-to-context.git
    cd curl-to-context
    
  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=curl_to_context

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

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

  • Publish to PyPI rye publish

Metadata

Release files for curl-to-context 3.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for curl-to-context 3.2.7
File Size Uploaded Provenance
curl_to_context-3.2.7.tar.gz 22.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for curl-to-context 3.2.7
File Interpreter ABI Platform
curl_to_context-3.2.7-py3-none-any.whl Python 3 none any Details

Total release size: 49.0 kB

Release files / curl_to_context-3.2.7.tar.gz

Download URL curl_to_context-3.2.7.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cfe355347a1cfe8bab3c6a69fe3fc99acde90c70c5e2a38f9e1e51bc807c8c06
BLAKE2b-256 checksum
How to use checksums
8e22c0a25b986534f4f74875b1d4544e66bd4f950bea0c5a1e36c2692bb07fe2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / curl_to_context-3.2.7-py3-none-any.whl

Download URL curl_to_context-3.2.7-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcabc071df5c642a2cdfcf2f8d96fa68b2632a83c8d15247f0633a658afbb455
BLAKE2b-256 checksum
How to use checksums
bc7279ee89e163ecc6be18e5f7a8cce3386ce6836fcd887712a380f0d1fba41e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Security for curl-to-context 3.2.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page