https://github.com/karpetrosyan/httpalchemy
https://github.com/karpetrosyan/httpalchemy
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/karpetrosyan/httpalchemy
- Owner: karpetrosyan
- License: mit
- Created: 2023-03-27T04:40:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-28T08:35:15.000Z (about 2 years ago)
- Last Synced: 2025-03-10T18:16:20.210Z (3 months ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
_HttpAlchemy_ is a Python library that provides a [curl](https://github.com/curl/curl) interface for interacting with Python HTTP client libraries like requests.
# Install
``` shell
$ pip install httpalchemy
```# Quick Start
``` python
>>> from httpalchemy import curl
>>> response = curl("http://google.com")
>>> response>>> decoded_body = response.text
>>> raw_body = response.content
>>> response.encoding
'UTF-8'
>>> response.raw # get raw response, `requests` library response by default```
## How to predict `HTTPAlchemy` syntax
HTTPAlchemy uses the [curl](https://github.com/curl/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
``` python
curl http://example.com -d "test_data" # curl
curl("http://example.com", _d="test_data") # HTTPAlchemy
`````` python
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
`````` shell
curl ... -H "header1: value1" -H "header2: value2"
curl(..., _H=[("header1", "value1"), ("header2", "value2")])
```HTTPAlchemy can accept headers in one of the following formats.
``` python
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.
``` shell
$ export http_proxy="http://example.com"
$ export https_proxy="https://example.com"
$ python script.py
```