Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
muslashwhy committed Jan 29, 2023
1 parent dfea92e commit 4e5d41a
Show file tree
Hide file tree
Showing 16 changed files with 748 additions and 421 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish to Prod PyPi

on:
release:
types: [created]

jobs:
publish-to-pypi:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.10" ]
poetry-version: [ 1.3.1 ]

steps:
- uses: actions/checkout@v3
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install system dependencies
shell: bash
run: sudo apt install libcurl4-openssl-dev libssl-dev

- name: Install poetry ${{ matrix.poetry-version }}
run: python -m pip install poetry==${{ matrix.poetry-version }}

- name: Install dependencies
shell: bash
run: poetry install

- name: Configure PyPi
run: |
python -m poetry config pypi-token.pypi ${{ secrets.PYPI_PROD }}
- name: Build package
run: poetry build

- name: Publish package
run: poetry publish


40 changes: 40 additions & 0 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test, Lint

on: [push]

jobs:
test-and-lint:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
poetry-version: [ 1.3.1 ]

steps:
- uses: actions/checkout@v3
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install system dependencies
shell: bash
run: sudo apt install libcurl4-openssl-dev libssl-dev

- name: Install poetry ${{ matrix.poetry-version }}
run: python -m pip install poetry==${{ matrix.poetry-version }}

- name: Install dependencies
shell: bash
run: poetry install

- name: Lint
shell: bash
run: poetry run black --check request_curl tests

- name: Test
shell: bash
run: make test


21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Ennis Blank, Mauritz Uphoff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lint:
poetry run black request_curl tests

test:
poetry run pytest tests
111 changes: 67 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Request Curl

User-friendly wrapper for pycurl
A user-friendly wrapper for pycurl that simplifies HTTP requests.

## Installation
Use the package manager
Expand All @@ -11,48 +11,61 @@ to install request_curl.
pip install request_curl
```

## HTTP2
HTTP2 is disabled by default.
# Quickstart
A request_curl session manages cookies, connection pooling, and configurations.

Basic Usage:
```python
import request_curl
s = request_curl.Session(http2=True)
r = s.get("https://www.example.com")
s = request_curl.Session()
s.get('https://httpbin.org/get') # returns <Response [200]>
s.request('GET', 'https://httpbin.org/get') # returns <Response [200]>
```

## Proxy Support
Proxy has to be formatted as a string.
Using a Context Manager
```python
import request_curl
with request_curl.Session() as session:
session.get('https://httpbin.org/get') # returns <Response [200]>
```

# Features

## Response Object

The response object is similar to that of the [requests](https://pypi.org/project/requests/) library.

```python
import request_curl
s = request_curl.Session()
r = s.get("https://www.example.com", proxies="ip:port:user:password")
r = s.get("https://httpbin.org/get")

print(r) # prints response object
print(r.status_code) # prints status code
print(r.content) # prints response content in bytes
print(r.text) # prints response content as text
print(r.json) # prints response content as JSON
print(r.url) # prints response URL
print(r.headers) # prints response URL
```

## Content Decoding
## Proxy Support
Format the proxy as a string.

```python
import request_curl
s = request_curl.Session(accept_encoding="br, gzip, deflate")
r = s.get("https://www.example.com", debug=True)
s = request_curl.Session()
# supports authentication: r = s.get("https://httpbin.org/get", proxies="ip:port:user:password")
r = s.get("https://httpbin.org/get", proxies="ip:port")
```

## Response Object

The response object behaves
similar to the one of the requests library.
## HTTP2
HTTP2 is disabled by default.

```python
import request_curl
s = request_curl.Session()
r = s.get("https://www.example.com")

print(r)
print(r.status_code)
print(r.content)
print(r.text)
print(r.json)
print(r.url)
print(r.history)
s = request_curl.Session(http2=True)
r = s.get("https://httpbin.org/get")
```

## Cipher Suites
Expand All @@ -68,42 +81,52 @@ cipher_suite = [
"AES256-GCM-SHA384"
]
s = request_curl.Session(cipher_suite=cipher_suite)
r = s.get("https://www.example.com")
r = s.get("https://httpbin.org/get")
```

## Debug Request
If debug is set to True the raw input
and output headers will bre printed out.
Set debug to True to print raw input and output headers.

```python
import request_curl
s = request_curl.Session()
r = s.get("https://www.example.com", debug=True)
r = s.get("https://httpbin.org/get", debug=True)
```

## Custom Header
You can specify custom a customer header
as a dictionary.
## Custom Headers
Specify custom headers as a dictionary.

```python
import request_curl
s = request_curl.Session()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
}
r = s.get("https://www.example.com", headers=headers)
r = s.get("https://httpbin.org/get", headers=headers)
```

## Install with Curl-Impersonate
- https://github.com/lwthiker/curl-impersonate/blob/main/INSTALL.md
- sudo apt install build-essential pkg-config cmake ninja-build curl autoconf automake libtool
- ``sudo apt install -y libbrotli-dev golang build-essential libnghttp2-dev cmake libunwind-dev libssl-dev git python3-dev``
- git clone https://github.com/pycurl/pycurl.git
- sudo python3 setup.py install --curl-config=/usr/local/bin/curl-impersonate-chrome-config
## Data

```python
import pycurl
pycurl.version_info()
# (9, '7.84.0', 480256, 'x86_64-pc-linux-gnu', 1370063517, 'BoringSSL', 0, '1.2.11', ('dict', 'file', 'ftp', 'ftps', 'gopher', 'gophers', 'http', 'https', 'imap', 'imaps', 'mqtt', 'pop3', 'pop3s', 'rtsp', 'smb', 'smbs', 'smtp', 'smtps', 'telnet', 'tftp'), None, 0, None)
quit()
```
import request_curl
s = request_curl.Session()

# sending form data
form_data = {"key": "value"}
response = s.post("https://httpbin.org/post", data=form_data)

# sending json data
json_data = {"key": "value"}
response = s.post("https://httpbin.org/post", json=json_data)
```

# Contributing

We welcome contributions through pull requests.
Before making major changes, please open an issue to discuss your intended changes.
Also, ensure to update relevant tests.

# License
Ennis Blank <Ennis.Blank@fau.de>, Mauritz Uphoff <Mauritz.Uphoff@hs-osnabrueck.de>

[MIT](LICENSE)
Loading

0 comments on commit 4e5d41a

Please sign in to comment.