METADATA 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Metadata-Version: 2.1
  2. Name: h11
  3. Version: 0.13.0
  4. Summary: A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
  5. Home-page: https://github.com/python-hyper/h11
  6. Author: Nathaniel J. Smith
  7. Author-email: njs@pobox.com
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 3 - Alpha
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Programming Language :: Python :: Implementation :: CPython
  14. Classifier: Programming Language :: Python :: Implementation :: PyPy
  15. Classifier: Programming Language :: Python :: 3
  16. Classifier: Programming Language :: Python :: 3 :: Only
  17. Classifier: Programming Language :: Python :: 3.6
  18. Classifier: Programming Language :: Python :: 3.7
  19. Classifier: Programming Language :: Python :: 3.8
  20. Classifier: Programming Language :: Python :: 3.9
  21. Classifier: Topic :: Internet :: WWW/HTTP
  22. Classifier: Topic :: System :: Networking
  23. Requires-Python: >=3.6
  24. License-File: LICENSE.txt
  25. Requires-Dist: dataclasses ; python_version < "3.7"
  26. Requires-Dist: typing-extensions ; python_version < "3.8"
  27. h11
  28. ===
  29. .. image:: https://travis-ci.org/python-hyper/h11.svg?branch=master
  30. :target: https://travis-ci.org/python-hyper/h11
  31. :alt: Automated test status
  32. .. image:: https://codecov.io/gh/python-hyper/h11/branch/master/graph/badge.svg
  33. :target: https://codecov.io/gh/python-hyper/h11
  34. :alt: Test coverage
  35. .. image:: https://readthedocs.org/projects/h11/badge/?version=latest
  36. :target: http://h11.readthedocs.io/en/latest/?badge=latest
  37. :alt: Documentation Status
  38. This is a little HTTP/1.1 library written from scratch in Python,
  39. heavily inspired by `hyper-h2 <https://hyper-h2.readthedocs.io/>`_.
  40. It's a "bring-your-own-I/O" library; h11 contains no IO code
  41. whatsoever. This means you can hook h11 up to your favorite network
  42. API, and that could be anything you want: synchronous, threaded,
  43. asynchronous, or your own implementation of `RFC 6214
  44. <https://tools.ietf.org/html/rfc6214>`_ -- h11 won't judge you.
  45. (Compare this to the current state of the art, where every time a `new
  46. network API <https://trio.readthedocs.io/>`_ comes along then someone
  47. gets to start over reimplementing the entire HTTP protocol from
  48. scratch.) Cory Benfield made an `excellent blog post describing the
  49. benefits of this approach
  50. <https://lukasa.co.uk/2015/10/The_New_Hyper/>`_, or if you like video
  51. then here's his `PyCon 2016 talk on the same theme
  52. <https://www.youtube.com/watch?v=7cC3_jGwl_U>`_.
  53. This also means that h11 is not immediately useful out of the box:
  54. it's a toolkit for building programs that speak HTTP, not something
  55. that could directly replace ``requests`` or ``twisted.web`` or
  56. whatever. But h11 makes it much easier to implement something like
  57. ``requests`` or ``twisted.web``.
  58. At a high level, working with h11 goes like this:
  59. 1) First, create an ``h11.Connection`` object to track the state of a
  60. single HTTP/1.1 connection.
  61. 2) When you read data off the network, pass it to
  62. ``conn.receive_data(...)``; you'll get back a list of objects
  63. representing high-level HTTP "events".
  64. 3) When you want to send a high-level HTTP event, create the
  65. corresponding "event" object and pass it to ``conn.send(...)``;
  66. this will give you back some bytes that you can then push out
  67. through the network.
  68. For example, a client might instantiate and then send a
  69. ``h11.Request`` object, then zero or more ``h11.Data`` objects for the
  70. request body (e.g., if this is a POST), and then a
  71. ``h11.EndOfMessage`` to indicate the end of the message. Then the
  72. server would then send back a ``h11.Response``, some ``h11.Data``, and
  73. its own ``h11.EndOfMessage``. If either side violates the protocol,
  74. you'll get a ``h11.ProtocolError`` exception.
  75. h11 is suitable for implementing both servers and clients, and has a
  76. pleasantly symmetric API: the events you send as a client are exactly
  77. the ones that you receive as a server and vice-versa.
  78. `Here's an example of a tiny HTTP client
  79. <https://github.com/python-hyper/h11/blob/master/examples/basic-client.py>`_
  80. It also has `a fine manual <https://h11.readthedocs.io/>`_.
  81. FAQ
  82. ---
  83. *Whyyyyy?*
  84. I wanted to play with HTTP in `Curio
  85. <https://curio.readthedocs.io/en/latest/tutorial.html>`__ and `Trio
  86. <https://trio.readthedocs.io>`__, which at the time didn't have any
  87. HTTP libraries. So I thought, no big deal, Python has, like, a dozen
  88. different implementations of HTTP, surely I can find one that's
  89. reusable. I didn't find one, but I did find Cory's call-to-arms
  90. blog-post. So I figured, well, fine, if I have to implement HTTP from
  91. scratch, at least I can make sure no-one *else* has to ever again.
  92. *Should I use it?*
  93. Maybe. You should be aware that it's a very young project. But, it's
  94. feature complete and has an exhaustive test-suite and complete docs,
  95. so the next step is for people to try using it and see how it goes
  96. :-). If you do then please let us know -- if nothing else we'll want
  97. to talk to you before making any incompatible changes!
  98. *What are the features/limitations?*
  99. Roughly speaking, it's trying to be a robust, complete, and non-hacky
  100. implementation of the first "chapter" of the HTTP/1.1 spec: `RFC 7230:
  101. HTTP/1.1 Message Syntax and Routing
  102. <https://tools.ietf.org/html/rfc7230>`_. That is, it mostly focuses on
  103. implementing HTTP at the level of taking bytes on and off the wire,
  104. and the headers related to that, and tries to be anal about spec
  105. conformance. It doesn't know about higher-level concerns like URL
  106. routing, conditional GETs, cross-origin cookie policies, or content
  107. negotiation. But it does know how to take care of framing,
  108. cross-version differences in keep-alive handling, and the "obsolete
  109. line folding" rule, so you can focus your energies on the hard /
  110. interesting parts for your application, and it tries to support the
  111. full specification in the sense that any useful HTTP/1.1 conformant
  112. application should be able to use h11.
  113. It's pure Python, and has no dependencies outside of the standard
  114. library.
  115. It has a test suite with 100.0% coverage for both statements and
  116. branches.
  117. Currently it supports Python 3 (testing on 3.6-3.9) and PyPy 3.
  118. The last Python 2-compatible version was h11 0.11.x.
  119. (Originally it had a Cython wrapper for `http-parser
  120. <https://github.com/nodejs/http-parser>`_ and a beautiful nested state
  121. machine implemented with ``yield from`` to postprocess the output. But
  122. I had to take these out -- the new *parser* needs fewer lines-of-code
  123. than the old *parser wrapper*, is written in pure Python, uses no
  124. exotic language syntax, and has more features. It's sad, really; that
  125. old state machine was really slick. I just need a few sentences here
  126. to mourn that.)
  127. I don't know how fast it is. I haven't benchmarked or profiled it yet,
  128. so it's probably got a few pointless hot spots, and I've been trying
  129. to err on the side of simplicity and robustness instead of
  130. micro-optimization. But at the architectural level I tried hard to
  131. avoid fundamentally bad decisions, e.g., I believe that all the
  132. parsing algorithms remain linear-time even in the face of pathological
  133. input like slowloris, and there are no byte-by-byte loops. (I also
  134. believe that it maintains bounded memory usage in the face of
  135. arbitrary/pathological input.)
  136. The whole library is ~800 lines-of-code. You can read and understand
  137. the whole thing in less than an hour. Most of the energy invested in
  138. this so far has been spent on trying to keep things simple by
  139. minimizing special-cases and ad hoc state manipulation; even though it
  140. is now quite small and simple, I'm still annoyed that I haven't
  141. figured out how to make it even smaller and simpler. (Unfortunately,
  142. HTTP does not lend itself to simplicity.)
  143. The API is ~feature complete and I don't expect the general outlines
  144. to change much, but you can't judge an API's ergonomics until you
  145. actually document and use it, so I'd expect some changes in the
  146. details.
  147. *How do I try it?*
  148. .. code-block:: sh
  149. $ pip install h11
  150. $ git clone git@github.com:python-hyper/h11
  151. $ cd h11/examples
  152. $ python basic-client.py
  153. and go from there.
  154. *License?*
  155. MIT
  156. *Code of conduct?*
  157. Contributors are requested to follow our `code of conduct
  158. <https://github.com/python-hyper/h11/blob/master/CODE_OF_CONDUCT.md>`_ in
  159. all project spaces.