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

orsinium-archive/requests-connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

requests for high frequency trading

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages