Skip to content

karpetrosyan/HTTPAlchemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HttpAlchemy is a Python library that provides a curl interface for interacting with Python HTTP client libraries like requests.

Install

$ pip install httpalchemy

Quick Start

>>> from httpalchemy import curl
>>> response = curl("http://google.com")
>>> response
<CurlResponse [301 Moved Permanently]>
>>> decoded_body = response.text
>>> raw_body = response.content
>>> response.encoding
'UTF-8'
>>> response.raw  # get raw response, `requests` library response by default
<Response [301]>

How to predict HTTPAlchemy syntax

HTTPAlchemy uses the curl syntax.

There are several rules to follow.

  • Options such as "-X" are converted to "_X"
  • Options such as "--header" are converted to "__header"

Examples

curl http://example.com -d "test_data"  # curl
curl("http://example.com", _d="test_data")  # HTTPAlchemy
curl http://example.com -d "{'test': 'test'}" -H 'Content-Type: application/json'  # curl
curl("http://example.com", _d="test_data", _H=["Content-Type: application/json"])  # HTTPAlchemy
curl ... -H "header1: value1" -H "header2: value2"
curl(..., _H=[("header1", "value1"), ("header2", "value2")])

HTTPAlchemy can accept headers in one of the following formats.

curl(_H={"header1": "value1", "header2": "value2"})
curl(_H=[("header1", "value1"), ("header2", "value2")])
curl(_H=["header1: value1", "header2: value2"])

Proxies

HTTPAlchemy provides proxy support via the http_proxy and https_proxy environment variables.

$ export http_proxy="http://example.com"
$ export https_proxy="https://example.com"
$ python script.py

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published