https://github.com/simpx/gale
Sugar for Tornado Asynchrous HTTP Client
https://github.com/simpx/gale
Last synced: 5 months ago
JSON representation
Sugar for Tornado Asynchrous HTTP Client
- Host: GitHub
- URL: https://github.com/simpx/gale
- Owner: simpx
- Created: 2012-09-23T15:50:13.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-09-28T09:59:52.000Z (over 13 years ago)
- Last Synced: 2025-11-12T20:04:12.682Z (8 months ago)
- Language: Python
- Size: 141 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Gale
=========
Gale is just Tornado
Installation
---------
$ pip install gale
Asynchrous HTTP Request
----------
###Get
import gale
def handle(response):
print response.body
gale.stop()
gale.get('http://httpbin.org/ip', callback=handle)
gale.start()
###Post
gale.post('http://httpbin.org/post', data={'a':1}, callback=handle)
gale.start()
###Proxy and Cookies
gale.get('http://httpbin.org/get',
params={'a':1, 'b':2},
proxy='user:pass@8.8.8.8:80',
cookies={'token': 'asdfgh'}, callback=handle)
gale.start()
###Sleep
def do_after_3_seconds():
print 'hello'
gale.stop()
gale.sleep(3, callback=do_after_3_second)
gale.start()
Task
----------
def all_done():
print 'all requests complete!'
gale.stop()
task = gale.Task()
task.add(gale.get, 'http://httpbin.org/ip', callback=handle)
task.add(gale.get, 'http://httpbin.org/get', callback=handle)
task.add(gale.post, 'http://httpbin.org/post', data={'a': 1},
callback=handle)
#or you can patch the gale.get function
#get = task.patch(gale.get)
#get('http://httpbin.org/ip', callback=handle)
#get('http://httpbin.org/get', callback=handle)
#get('http://httpbin.org/post', data={'a': 1},
# callback=handle)
task.run(all_done)
gale.start()