METADATA 8.0 KB

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