V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
guyskk0x0
V2EX  ›  Python

Curio + Requests: Async HTTP for Humans 和 Requests 一样的味道

  •  
  •   guyskk0x0 ·
    guyskk · 2017-10-29 21:35:05 +08:00 · 3559 次点击
    这是一个创建于 2341 天前的主题,其中的信息可能已经有所发展或是发生改变。

    $ pip install curequests

    from curio import run
    from curequests import get, post
    
    async def main():
        r = await get('https://httpbin.org/get')
        print(r.json())
        r = await post('https://httpbin.org/post', json={'hello': 'world'})
        print(r.json())
    
    run(main)
    

    和 Requests 一样的味道,请参考 Requests 文档 食用!
    Github: https://github.com/guyskk/curequests

    11 条回复    2017-11-08 13:50:29 +08:00
    czheo
        1
    czheo  
       2017-10-29 21:48:15 +08:00
    Nice
    hl
        2
    hl  
       2017-10-29 22:29:46 +08:00
    为啥不 aiohttp
    guyskk0x0
        3
    guyskk0x0  
    OP
       2017-10-29 22:36:40 +08:00
    @hl #2 asyncio 太复杂了,curio + requests 学习成本接近 0,并且 API 非常好用
    EricCartman
        4
    EricCartman  
       2017-10-29 22:49:03 +08:00 via Android
    果然不支持 Python 2,现在生产环境还是 Python 2 + Tornado httpclient,
    相比 requests 还是蛮难用的
    Kilerd
        5
    Kilerd  
       2017-10-29 22:50:30 +08:00
    又是你,这个偏爱 curio 的家伙
    chenqh
        6
    chenqh  
       2017-10-29 22:51:45 +08:00 via iPhone
    @EricCartman 我也是
    czheo
        7
    czheo  
       2017-10-29 23:02:21 +08:00
    @Kilerd curio 确实比较好用,我被 beazley 说服了。
    Kilerd
        8
    Kilerd  
       2017-10-29 23:15:32 +08:00
    @czheo 我离不开 uvloop,不然我也不想用 asyncio
    czheo
        9
    czheo  
       2017-10-30 22:46:04 +08:00   ❤️ 1
    看到 curio 的作者推了你的包。
    https://twitter.com/dabeaz/status/924756107117125632
    guyskk0x0
        10
    guyskk0x0  
    OP
       2017-10-31 09:21:07 +08:00 via Android
    @czheo 惊喜,哈哈
    dstwhk
        11
    dstwhk  
       2017-11-08 13:50:29 +08:00
    很好用的样子
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.