Skip to main content
https://img.shields.io/pypi/v/trip.svg https://img.shields.io/pypi/l/trip.svg https://img.shields.io/pypi/pyversions/trip.svg https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg https://img.shields.io/badge/中文---%3E-yellow.svg

TRIP, Tornado & Requests In Pair, an async HTTP library for Python.

Simple as Requests, Trip let you get rid of annoying network blocking.

Coroutine in python 2.7+ can be this simple:

import trip

def main():
    r = yield trip.get('https://httpbin.org/get', auth=('user', 'pass'))
    print(r.content)

trip.run(main)

With Trip, you may finish one hundred requests in one piece of time.

Trip gets its name from two powerful site packages and aims to combine them together. Trip refers to ‘Tornado & Requests In Pair’, TRIP. To put them together, I reused much of their codes about structure and dealing. Actually I only made little effort to make a mixture. Thanks to Tornado and Requests.

Through using Trip, you may take full advantage of Requests, including: Sessions with Cookie persistence, browser-style SSL verification, automatic content decoding, basic/digest authentication, elegant key/value Cookies. Meanwhile, your requests are coroutine like using AsyncHTTPClient of Tornado, network blocking will not be a problem.

Found difficult optimizing spiders’ time consuming? Found tricky using asyncio http packages? Found heavy custimizing big spider framework? Try Trip, you will not regret!

Installation

Paste it into your console and enjoy:

$ python -m pip install trip

Documents

Documents are here: http://trip.readthedocs.io/

Advanced usage

Some of the advaced features are listed here:

Using async and await in python 3:

import trip

async def main():
    r = await trip.get('https://httpbin.org/get', auth=('user', 'pass'))
    print(r.content)

trip.run(main)

Sessions with Cookie persistence

import trip

def main():
    s = trip.Session()
    r = yield s.get(
        'https://httpbin.org/cookies/set',
        params={'name': 'value'},
        allow_redirects=False)
    r = yield s.get('https://httpbin.org/cookies')
    print(r.content)

trip.run(main)

Event hooks

import trip

def main():
    def print_url(r, *args, **kwargs):
        print(r.url)
    def record_hook(r, *args, **kwargs):
        r.hook_called = True
        return r
    url = 'http://httpbin.org/get'
    r = yield trip.get('http://httpbin.org', hooks={'response': [print_url, record_hook]})
    print(r.hook_called)

trip.run(main)

Timeouts

import trip

def main():
    r = yield trip.get('http://github.com', timeout=0.001)
    print(r)

trip.run(main)

Proxy

import trip

proxies = {
    'http': '127.0.0.1:8080',
    'https': '127.0.0.1:8081',
}

def main():
    r = yield trip.get('https://httpbin.org/get', proxies=proxies)
    print(r.content)

trip.run(main)

How to contribute

  1. You may open an issue to share your ideas with me.

  2. Or fork this project and do it your own on master branch.

  3. Please write demo codes of bugs or new features. You know, codes help.

  4. Finally if you finish your work and make a pull request, I will merge it in time after essential tests.

Metadata

Release files for trip 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trip 0.0.10
File Size Uploaded
trip-0.0.10.tar.gz 26.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trip 0.0.10
File Interpreter ABI Platform
trip-0.0.10-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 56.3 kB

Release files / trip-0.0.10.tar.gz

Download URL trip-0.0.10.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
61efa349f5b10b8b9b34a94897873543005b83c83e6ebf86edc906044015d008
BLAKE2b-256 checksum
How to use checksums
5025005d1e7eb79f59c8d900b53d81713d9a1f44a7bad5cc7223adea4b09134f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / trip-0.0.10-py2.py3-none-any.whl

Download URL trip-0.0.10-py2.py3-none-any.whl
Size 30.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c60a7d291d84ee37a7343ca00276e46aa2af5d430b5d227b40a847dcb43e2ef7
BLAKE2b-256 checksum
How to use checksums
d7e7604bf7e9a6460fd4f4c2d108762336da6eb4f54edf4e9e99c4754984a6fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

3 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page