Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Latest commit

 

History

History
73 lines (48 loc) · 1.89 KB

README.md

File metadata and controls

73 lines (48 loc) · 1.89 KB

requests-connection

Split requests via requests onto two stages:

  1. Connect to server (establish TCP and TLS connections).
  2. Make HTTP request.

It is very useful for all cases when you can prepare your request to server and later you must send request as fast as possible. For example, high frequency trading.

Usage

Make requests

from requests_connection import Session, Connection

# connect (establish TCP and TLS connections)
connection = Connection.https('ya.ru')

# make requests session
session = Session(connection)

# make http request
response = session.get('https://ya.ru/')

You can make only one request via one connection. Reconnect before new request:

connection = Connection.https('ya.ru')
session.connect(connection)
response = session.get('https://ya.ru/')

If connection has been closed, new connection will be created on request automatically:

response = session.get('https://ya.ru/')
response = session.get('https://ya.ru/news/')

Requests to other host or port bypass created connection:

response = session.get('http://ya.ru/')
response = session.get('https://google.com/')

Make connection

Connection class help you to create connection. It supports 3 constructors:

Benchmarks

Results:

Requests: 0.362 ± 0.2106
Patched:  0.229 ± 0.03791

Running:

pipenv install --dev
pipenv run python benchmark.py