Name | httpy JSON |
Version |
2.1.2
JSON |
| download |
home_page | None |
Summary | A lightweight socket-based HTTP(s) and WebSocket client. |
upload_time | 2024-09-27 14:38:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6.0 |
license | GNU General Public License v3 (GPLv3) |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
.. image:: https://badgen.net/github/release/jenca-adam/httpy?color=green
:target: https://github.com/jenca-adam/httpy/releases/latest
:alt: Latest Release
.. image:: https://badgen.net/github/stars/jenca-adam/httpy?color=red
:target: https://github.com/jenca-adam/httpy/
:alt: Stars
.. image:: https://badgen.net/github/tags/jenca-adam/httpy?color=cyan
:target: https://github.com/jenca-adam/httpy/tags
:alt: Tags
.. image:: https://badgen.net/github/releases/jenca-adam/httpy?color=yellow
:target: https://github.com/jenca-adam/httpy/releases
:alt: Releases Count
.. image:: https://badgen.net/github/license/jenca-adam/httpy?color=black
:target: https://github.com/jenca-adam/httpy/blob/main/LICENSE
:alt: License
.. image:: https://badgen.net/badge/icon/github?icon=github&label
:target: https://github.com/jenca-adam/httpy/
:alt: GitHub
.. image:: https://badgen.net/badge/icon/pypi?icon=pypi&label&color=purple
:target: https://pypi.org/project/httpy
:alt: PyPI
.. image:: https://readthedocs.org/projects/httpy/badge/?version=latest
:target: https://httpy.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/github/size/jenca-adam/httpy/latest_release%2Flatest.whl
:target: https://github.com/jenca-adam/httpy
:alt: Size
.. image:: https://img.shields.io/pypi/dm/httpy.svg
:target: https://pypi.org/project/httpy
:alt: Downloads/Month
Docs at https://httpy.readthedocs.io/
=====
httpy
=====
A Python lightweight socket-based library to create HTTP(s) and
WebSocket connections.
Features
========
- Cookies support
- Caching support
- Easy debugging
- HTTP Basic and Digest authentication
- Form support
- Keep-Alive and Sessions support
- JSON support
- Sessions support
- Runs in PyPy
- Independent of http.client
- HTTP/2 Support
- Async IO support
Requirements
============
- Python>=3.6
Installation
============
Any platform
------------
Git
~~~
1. ``git clone https://github.com/jenca-adam/httpy``
2. ``cd httpy``
3. ``python3 setup.py install``
The Python version check will be performed automatically
Pip
~~~
1. ``python3 -m pip install httpy``
Arch Linux
----------
1. ``yay -S httpy``
Usage
=====
`REFERENCE <httpy.html#submodules>`__
HTTP
----
It's easy.
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/") # Do a request
resp.content #Access content
Specifying a HTTP version
~~~~~~~~~~~~~~~~~~~~~~~~~
Set the ``http_version`` argument, but keep in mind the following
1. You can't make an asynchronous request using HTTP/1.1
2. HTTP/2 requests can't be performed over insecure (http scheme)
connections.
If you don't set it, the HTTP version will be automatically detected
using ALPN <https://datatracker.ietf.org/doc/html/rfc7301>.
Valid ``http_version`` values are ``"1.1"`` and ``"2"``.
Non-blocking requests
~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
import httpy
pending = httpy.request("https://example.com/", blocking = False)
``PendingRequest.response`` returns the result of the response. You can
check if the request is already done using ``PendingRequest.finished``
I want cookies!
~~~~~~~~~~~~~~~
The ``Dir`` class allows you to store httpy's data (cache and cookies)
on the path of your choice. By default, the data is stored in
``~/.cache/httpy``. If you want to store the data without using the ``Dir`` class, use the
``enable_cookies`` or ``enable_cache`` argument of ``request``.
.. code-block:: python
import httpy
directory = httpy.Dir("your/path")
directory.request("https://example.com/") # ...
Keep-Alive requests
~~~~~~~~~~~~~~~~~~~
If you want to reuse a connection, it is highly recommended to use a
``Session`` class. It offers more control over connection closure than
the standard ``request``
.. code-block:: python
import httpy
session = httpy.Session()
session.request("https://example.com/")
HTTPy sets ``Connection: close`` by default in non-Session requests. If
you want to keep the connection alive outside a session, you must
specify so in the ``headers`` argument.
Asynchronous requests
~~~~~~~~~~~~~~~~~~~~~
You can perform async requests using the ``async_request`` method.
The simplest use case:
.. code-block:: python
import httpy
async def my_function():
return await httpy.request("https://example.com/")
If you want to perform multiple requests at once on the same connection
(i.e. with ``asyncio.gather``), use the ``initiate_http2_connection``
method of ``Session``:
.. code-block:: python
import httpy
import asyncio
async def my_function():
session = httpy.Session()
await session.initiate_http2_connection(host="example.com")
return await asyncio.gather(*(session.async_request("https://www.example.com/") for _ in range(69)))
``Session`` and ``Dir`` and everything with a ``request()`` method has
an ``async_request()`` equivalent.
Streams
~~~~~~~
If you want to receive the response as a stream, set the `stream` argument of `request` to True.
A `Stream` or `AsyncStream` is returned.
They both have the `read()` method.
It returns the given number of bytes of the response body. If no arguments are given, the entire rest of the body is read and returned.
You can access the current stream state using `stream.state`. It contains some useful information about the stream. Status and headers are also available directly (`stream.status`, `stream.headers`).
Stream state
^^^^^^^^^^^^
Attributes:
* `bytes_read`
* `body`
* `connection`
* `finished`
.. warning::
The `stream.state.bytes_read` attribute represents the amount of bytes received from the server and is not representative of the actual number of bytes read from the stream. For this use `stream.bytes_read` instead.
The same applies for `stream.state.body`
.. code-block:: python
import httpy
stream = httpy.request("https://example.com/big-file", stream=True)
stream.read(1) # read 1 byte
stream.read(6) # read 6 bytes
stream.bytes_read # 7
stream.read() # read the rest
stream.state.finished #True
``Response`` class attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``Response`` class returned by ``request()`` has some useful
attributes:
``Response.content``
^^^^^^^^^^^^^^^^^^^^
The response content as ``bytes``. Example:
.. code-block:: python
import httpy
resp = httpy.request("https://www.google.com/")
print(resp.content)
#b'!<doctype html>\n<html>...
``Response.status``
^^^^^^^^^^^^^^^^^^^
The response status as a ``Status`` object. Example:
.. code-block:: python
import httpy
resp = httpy.request("https://www.example.com/this_url_doesnt_exist")
print(resp.status)
# 404
print(resp.status.reason)
# NOT FOUND
print(resp.status.description)
# indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
print(resp.status>400)
# True
``Status`` subclasses ``int``.
``Response.history``
^^^^^^^^^^^^^^^^^^^^
All the redirects on the way to this response as ``list``.
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://httpbin.org/redirect/1")
print(resp.history)
# [<Response GET [302 Found] (https://httpbin.org/redirect/1/)>, <Response GET [200 OK] (https://httpbin.org/get/)>]
``Response.history`` is ordered from oldest to newest
``Response.fromcache``
^^^^^^^^^^^^^^^^^^^^^^
Indicates whether the response was loaded from cache (``bool``).
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.fromcache)
# False
resp = httpy.request("https://example.com/")
print(resp.fromcache)
# True
``Response.request``
^^^^^^^^^^^^^^^^^^^^
Some of the attributes of the request that produced this response, as a
``Request`` object.
``Request``'s attributes
''''''''''''''''''''''''
- ``Request.url`` - the URL requested (``str``)
- ``Request.headers`` - the requests' headers (``Headers``)
- ``Request.socket`` - the underlying connection (either
``socket.socket`` or ``httpy.http2.connection.HTTP2Connection``)
- ``Request.cache`` - the same as ``Response.fromcache`` (``bool``)
- ``Request.http_version`` - the HTTP version used (``str``)
- ``Request.method`` - the HTTP method used (``str``)
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.request.url)
# https://example.com/
print(resp.request.headers)
# {'Accept-Encoding': 'gzip, deflate, identity', 'Host': 'example.com', 'User-Agent': 'httpy/2.0.0', 'Connection': 'close', 'Accept': '*/*'}
print(resp.request.method)
# GET
``Response.original_content``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Raw content received from the server, not decoded with Content-Encoding
(``bytes``).
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.original_content)
# b'\x1f\x8b\x08\x00\xc2 ...
``Response.time_elapsed``
^^^^^^^^^^^^^^^^^^^^^^^^^
Time the request took, in seconds. Only the loading time of this
particular request, doesn't account for redirects. (``float``).
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.time_elapsed)
# 0.2497
``Response.speed``
^^^^^^^^^^^^^^^^^^
The download speed for the response, in bytes per second. (``float``).
Might be different for HTTP/2 request. Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.speed)
# 2594.79
``Response.content_type``
^^^^^^^^^^^^^^^^^^^^^^^^^
The response's ``Content-Type`` header contents, with the charset
information stripped. If the headers lack ``Content-Type``, it's
``text/html`` by default.
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.content_type)
# text/html
``Response.charset`` (property)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Gets the charset of the response (``str`` or ``None``):
1. If a charset was specified in the response headers, return it
2. If a charset was not specified, but ``chardet`` is available, try to
detect the charset (Note that this still returns ``None`` if
``chardet`` fails)
3. If a charset was not specified, and ``chardet`` is not available,
return ``None``
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.charset)
# UTF-8
``Response.string`` (property)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``Response.content``, decoded using ``Response.charset`` (``str``)
.. warning::
Do not try to access ``Response.string``, if ``Response.charset`` is
``None``, unless you are absolutely sure the response data is
decodable by the default locale encoding.
For ASCII responses this is probably harmless, but you have been
warned!
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/")
print(resp.string)
#<!doctype html>
...
``Response.json`` (property)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If ``Response.content_type`` is ``application/json``, try to parse
``Response.string`` using JSON. Throw an error otherwise.
.. warning::
The same as above applies.
Example:
.. code-block:: python
import httpy
resp = httpy.request("https://httpbin.org/get")
print(resp.json["url"])
# https://httpbin.org/get
``Response.method``
^^^^^^^^^^^^^^^^^^^
The same as ``Response.request.method``
WebSockets
----------
Easy again...
.. code-block:: python
>>> import httpy
>>> sock = httpy.WebSocket("wss://echo.websocket.events/")# create a websocket client(echo server example)
>>> sock.send("Hello, world!💥")# you can send also bytes
>>> sock.recv()
"Hello, world!💥"
Examples
========
POST method
-----------
Simple Form
~~~~~~~~~~~
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/", method="POST", body = {"foo":"bar"})
# ...
Sending files
~~~~~~~~~~~~~
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/", method = "POST", body = { "foo" : "bar", "file" : httpy.File.open( "example.txt" ) })
# ...
Sending binary data
~~~~~~~~~~~~~~~~~~~
.. code-block:: python
import httpy
resp = httpy.request("https://example.com/", method = "POST", body= b" Hello, World ! ")
# ...
Sending plain text
~~~~~~~~~~~~~~~~~~
.. code-block:: python
resp = httpy.request("https://example.com/", method = "POST", body = "I support Ünicode !")
# ...
Sending JSON
~~~~~~~~~~~~
.. code-block:: python
resp = httpy.request("https://example.com/", method = "POST", body = "{\"foo\" : \"bar\" }", content_type = "application/json")
# ...
Debugging
=========
Just set ``debug`` to ``True`` :
.. code-block:: python
>>> import httpy
>>> httpy.request("https://example.com/",debug=True)
[INFO][request](1266): request() called.
[INFO][_raw_request](1112): _raw_request() called.
[INFO][_raw_request](1113): Accessing cache.
[INFO][_raw_request](1120): No data in cache.
[INFO][_raw_request](1151): Establishing connection
[INFO]Connection[__init__](778): Created new Connection upon <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.88', 58998), raddr=('93.184.216.34', 443)>
send:
GET / HTTP/1.1
Accept-Encoding: gzip, deflate, identity
Host: www.example.com
User-Agent: httpy/1.1.0
Connection: keep-alive
response:
HTTP/1.1 200 OK
Content-Encoding: gzip
Age: 438765
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Wed, 13 Apr 2022 12:59:07 GMT
Etag: "3147526947+gzip"
Expires: Wed, 20 Apr 2022 12:59:07 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dcb/7F37)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 648
<Response [200 OK] (https://www.example.com/)>
Raw data
{
"_id": null,
"home_page": null,
"name": "httpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6.0",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Adam Jenca <jenca.a@gjh.sk>",
"download_url": "https://files.pythonhosted.org/packages/c4/e5/8f6d261bae8ff8dec37cfa89a233540ba7ea1407dd933cdeaad394efa26c/httpy-2.1.2.tar.gz",
"platform": null,
"description": "\n.. image:: https://badgen.net/github/release/jenca-adam/httpy?color=green\n :target: https://github.com/jenca-adam/httpy/releases/latest\n :alt: Latest Release\n\n.. image:: https://badgen.net/github/stars/jenca-adam/httpy?color=red\n :target: https://github.com/jenca-adam/httpy/\n :alt: Stars\n\n.. image:: https://badgen.net/github/tags/jenca-adam/httpy?color=cyan\n :target: https://github.com/jenca-adam/httpy/tags\n :alt: Tags\n\n.. image:: https://badgen.net/github/releases/jenca-adam/httpy?color=yellow\n :target: https://github.com/jenca-adam/httpy/releases\n :alt: Releases Count\n\n.. image:: https://badgen.net/github/license/jenca-adam/httpy?color=black\n :target: https://github.com/jenca-adam/httpy/blob/main/LICENSE\n :alt: License\n\n.. image:: https://badgen.net/badge/icon/github?icon=github&label\n :target: https://github.com/jenca-adam/httpy/\n :alt: GitHub\n\n.. image:: https://badgen.net/badge/icon/pypi?icon=pypi&label&color=purple\n :target: https://pypi.org/project/httpy\n :alt: PyPI\n\n.. image:: https://readthedocs.org/projects/httpy/badge/?version=latest\n :target: https://httpy.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\n.. image:: https://img.shields.io/github/size/jenca-adam/httpy/latest_release%2Flatest.whl\n :target: https://github.com/jenca-adam/httpy\n :alt: Size\n\n\n.. image:: https://img.shields.io/pypi/dm/httpy.svg\n :target: https://pypi.org/project/httpy\n :alt: Downloads/Month\n\n\n\nDocs at https://httpy.readthedocs.io/\n\n=====\nhttpy\n=====\n\n\nA Python lightweight socket-based library to create HTTP(s) and\nWebSocket connections.\n\nFeatures\n========\n\n- Cookies support\n- Caching support\n- Easy debugging\n- HTTP Basic and Digest authentication\n- Form support\n- Keep-Alive and Sessions support\n- JSON support\n- Sessions support\n- Runs in PyPy\n- Independent of http.client\n- HTTP/2 Support\n- Async IO support\n\nRequirements\n============\n\n- Python>=3.6\n\nInstallation\n============\n\nAny platform\n------------\n\nGit\n~~~\n\n 1. ``git clone https://github.com/jenca-adam/httpy``\n 2. ``cd httpy``\n 3. ``python3 setup.py install``\n\nThe Python version check will be performed automatically\n\nPip\n~~~\n\n 1. ``python3 -m pip install httpy``\n\nArch Linux\n----------\n\n 1. ``yay -S httpy``\n\nUsage\n=====\n\n`REFERENCE <httpy.html#submodules>`__\n\nHTTP\n----\n\nIt's easy.\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\") # Do a request\n resp.content #Access content\n\nSpecifying a HTTP version\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSet the ``http_version`` argument, but keep in mind the following\n\n1. You can't make an asynchronous request using HTTP/1.1\n2. HTTP/2 requests can't be performed over insecure (http scheme)\n connections.\n\nIf you don't set it, the HTTP version will be automatically detected\nusing ALPN <https://datatracker.ietf.org/doc/html/rfc7301>.\n\nValid ``http_version`` values are ``\"1.1\"`` and ``\"2\"``.\n\nNon-blocking requests\n~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n import httpy\n pending = httpy.request(\"https://example.com/\", blocking = False)\n\n``PendingRequest.response`` returns the result of the response. You can\ncheck if the request is already done using ``PendingRequest.finished``\n\nI want cookies!\n~~~~~~~~~~~~~~~\n\nThe ``Dir`` class allows you to store httpy's data (cache and cookies)\non the path of your choice. By default, the data is stored in\n``~/.cache/httpy``. If you want to store the data without using the ``Dir`` class, use the\n``enable_cookies`` or ``enable_cache`` argument of ``request``. \n\n.. code-block:: python\n\n import httpy\n directory = httpy.Dir(\"your/path\")\n directory.request(\"https://example.com/\") # ...\n\nKeep-Alive requests\n~~~~~~~~~~~~~~~~~~~\n\nIf you want to reuse a connection, it is highly recommended to use a\n``Session`` class. It offers more control over connection closure than\nthe standard ``request``\n\n.. code-block:: python\n\n import httpy\n session = httpy.Session()\n session.request(\"https://example.com/\")\n\nHTTPy sets ``Connection: close`` by default in non-Session requests. If\nyou want to keep the connection alive outside a session, you must\nspecify so in the ``headers`` argument.\n\nAsynchronous requests\n~~~~~~~~~~~~~~~~~~~~~\n\nYou can perform async requests using the ``async_request`` method.\n\nThe simplest use case:\n\n.. code-block:: python\n\n import httpy\n\n async def my_function():\n return await httpy.request(\"https://example.com/\")\n\nIf you want to perform multiple requests at once on the same connection\n(i.e.\u00a0with ``asyncio.gather``), use the ``initiate_http2_connection``\nmethod of ``Session``:\n\n.. code-block:: python\n\n import httpy\n import asyncio\n\n async def my_function():\n session = httpy.Session()\n await session.initiate_http2_connection(host=\"example.com\")\n return await asyncio.gather(*(session.async_request(\"https://www.example.com/\") for _ in range(69)))\n\n``Session`` and ``Dir`` and everything with a ``request()`` method has\nan ``async_request()`` equivalent.\n\nStreams\n~~~~~~~\n\nIf you want to receive the response as a stream, set the `stream` argument of `request` to True.\nA `Stream` or `AsyncStream` is returned.\nThey both have the `read()` method.\nIt returns the given number of bytes of the response body. If no arguments are given, the entire rest of the body is read and returned.\n\nYou can access the current stream state using `stream.state`. It contains some useful information about the stream. Status and headers are also available directly (`stream.status`, `stream.headers`).\n\nStream state\n^^^^^^^^^^^^\n\nAttributes:\n* `bytes_read`\n* `body`\n* `connection`\n* `finished`\n\n.. warning::\n The `stream.state.bytes_read` attribute represents the amount of bytes received from the server and is not representative of the actual number of bytes read from the stream. For this use `stream.bytes_read` instead.\n The same applies for `stream.state.body`\n\n.. code-block:: python\n\n import httpy\n stream = httpy.request(\"https://example.com/big-file\", stream=True)\n stream.read(1) # read 1 byte\n stream.read(6) # read 6 bytes\n stream.bytes_read # 7\n stream.read() # read the rest\n stream.state.finished #True\n\n``Response`` class attributes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe ``Response`` class returned by ``request()`` has some useful\nattributes:\n\n``Response.content``\n^^^^^^^^^^^^^^^^^^^^\n\nThe response content as ``bytes``. Example:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://www.google.com/\")\n print(resp.content)\n #b'!<doctype html>\\n<html>...\n\n``Response.status``\n^^^^^^^^^^^^^^^^^^^\n\nThe response status as a ``Status`` object. Example:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://www.example.com/this_url_doesnt_exist\")\n print(resp.status)\n # 404\n print(resp.status.reason)\n # NOT FOUND\n print(resp.status.description)\n # indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.\n print(resp.status>400)\n # True\n\n``Status`` subclasses ``int``.\n\n``Response.history``\n^^^^^^^^^^^^^^^^^^^^\n\nAll the redirects on the way to this response as ``list``.\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://httpbin.org/redirect/1\")\n print(resp.history)\n # [<Response GET [302 Found] (https://httpbin.org/redirect/1/)>, <Response GET [200 OK] (https://httpbin.org/get/)>]\n\n``Response.history`` is ordered from oldest to newest\n\n``Response.fromcache``\n^^^^^^^^^^^^^^^^^^^^^^\n\nIndicates whether the response was loaded from cache (``bool``).\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.fromcache)\n # False\n resp = httpy.request(\"https://example.com/\")\n print(resp.fromcache)\n # True\n\n``Response.request``\n^^^^^^^^^^^^^^^^^^^^\n\nSome of the attributes of the request that produced this response, as a\n``Request`` object.\n\n``Request``'s attributes\n''''''''''''''''''''''''\n\n- ``Request.url`` - the URL requested (``str``)\n- ``Request.headers`` - the requests' headers (``Headers``)\n- ``Request.socket`` - the underlying connection (either\n ``socket.socket`` or ``httpy.http2.connection.HTTP2Connection``)\n- ``Request.cache`` - the same as ``Response.fromcache`` (``bool``)\n- ``Request.http_version`` - the HTTP version used (``str``)\n- ``Request.method`` - the HTTP method used (``str``)\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.request.url)\n # https://example.com/\n print(resp.request.headers)\n # {'Accept-Encoding': 'gzip, deflate, identity', 'Host': 'example.com', 'User-Agent': 'httpy/2.0.0', 'Connection': 'close', 'Accept': '*/*'}\n print(resp.request.method)\n # GET\n\n``Response.original_content``\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nRaw content received from the server, not decoded with Content-Encoding\n(``bytes``).\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.original_content)\n # b'\\x1f\\x8b\\x08\\x00\\xc2 ...\n\n``Response.time_elapsed``\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTime the request took, in seconds. Only the loading time of this\nparticular request, doesn't account for redirects. (``float``).\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.time_elapsed)\n # 0.2497\n\n``Response.speed``\n^^^^^^^^^^^^^^^^^^\n\nThe download speed for the response, in bytes per second. (``float``).\nMight be different for HTTP/2 request. Example:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.speed)\n # 2594.79\n\n``Response.content_type``\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe response's ``Content-Type`` header contents, with the charset\ninformation stripped. If the headers lack ``Content-Type``, it's\n``text/html`` by default.\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.content_type)\n # text/html\n\n``Response.charset`` (property)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nGets the charset of the response (``str`` or ``None``):\n\n1. If a charset was specified in the response headers, return it\n2. If a charset was not specified, but ``chardet`` is available, try to\n detect the charset (Note that this still returns ``None`` if\n ``chardet`` fails)\n3. If a charset was not specified, and ``chardet`` is not available,\n return ``None``\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.charset)\n # UTF-8\n\n``Response.string`` (property)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n``Response.content``, decoded using ``Response.charset`` (``str``)\n\n.. warning::\n\n Do not try to access ``Response.string``, if ``Response.charset`` is\n ``None``, unless you are absolutely sure the response data is\n decodable by the default locale encoding.\n\n For ASCII responses this is probably harmless, but you have been\n warned!\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\")\n print(resp.string)\n #<!doctype html>\n ...\n\n``Response.json`` (property)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf ``Response.content_type`` is ``application/json``, try to parse\n``Response.string`` using JSON. Throw an error otherwise.\n\n.. warning::\n\n The same as above applies.\n\nExample:\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://httpbin.org/get\")\n print(resp.json[\"url\"])\n # https://httpbin.org/get\n\n``Response.method``\n^^^^^^^^^^^^^^^^^^^\n\nThe same as ``Response.request.method``\n\nWebSockets\n----------\n\nEasy again...\n\n.. code-block:: python\n\n >>> import httpy\n >>> sock = httpy.WebSocket(\"wss://echo.websocket.events/\")# create a websocket client(echo server example)\n >>> sock.send(\"Hello, world!\ud83d\udca5\")# you can send also bytes\n >>> sock.recv()\n \"Hello, world!\ud83d\udca5\"\n\nExamples\n========\n\nPOST method\n-----------\n\nSimple Form\n~~~~~~~~~~~\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\", method=\"POST\", body = {\"foo\":\"bar\"})\n # ...\n\nSending files\n~~~~~~~~~~~~~\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\", method = \"POST\", body = { \"foo\" : \"bar\", \"file\" : httpy.File.open( \"example.txt\" ) })\n # ...\n\nSending binary data\n~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n import httpy\n resp = httpy.request(\"https://example.com/\", method = \"POST\", body= b\" Hello, World ! \")\n # ...\n\nSending plain text\n~~~~~~~~~~~~~~~~~~\n\n.. code-block:: python\n\n resp = httpy.request(\"https://example.com/\", method = \"POST\", body = \"I support \u00dcnicode !\")\n # ...\n\nSending JSON\n~~~~~~~~~~~~\n\n.. code-block:: python\n\n resp = httpy.request(\"https://example.com/\", method = \"POST\", body = \"{\\\"foo\\\" : \\\"bar\\\" }\", content_type = \"application/json\")\n # ...\n\nDebugging\n=========\n\nJust set ``debug`` to ``True`` :\n\n.. code-block:: python\n\n >>> import httpy\n >>> httpy.request(\"https://example.com/\",debug=True)\n [INFO][request](1266): request() called.\n [INFO][_raw_request](1112): _raw_request() called.\n [INFO][_raw_request](1113): Accessing cache.\n [INFO][_raw_request](1120): No data in cache.\n [INFO][_raw_request](1151): Establishing connection\n [INFO]Connection[__init__](778): Created new Connection upon <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.100.88', 58998), raddr=('93.184.216.34', 443)>\n\n send:\n GET / HTTP/1.1\n Accept-Encoding: gzip, deflate, identity\n Host: www.example.com\n User-Agent: httpy/1.1.0\n Connection: keep-alive\n\n response: \n HTTP/1.1 200 OK\n\n Content-Encoding: gzip\n Age: 438765\n Cache-Control: max-age=604800\n Content-Type: text/html; charset=UTF-8\n Date: Wed, 13 Apr 2022 12:59:07 GMT\n Etag: \"3147526947+gzip\"\n Expires: Wed, 20 Apr 2022 12:59:07 GMT\n Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT\n Server: ECS (dcb/7F37)\n Vary: Accept-Encoding\n X-Cache: HIT\n Content-Length: 648\n <Response [200 OK] (https://www.example.com/)>\n",
"bugtrack_url": null,
"license": "GNU General Public License v3 (GPLv3)",
"summary": "A lightweight socket-based HTTP(s) and WebSocket client.",
"version": "2.1.2",
"project_urls": {
"Bug_Tracker": "https://github.com/jenca-adam/httpy/issues",
"Download": "https://github.com/jenca-adam/httpy/releases/latest",
"Homepage": "https://github.com/jenca-adam/httpy",
"PyPI": "https://pypi.python.org/project/httpy"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5fa1b6a890e54a205388f4f49c8e658d7b1bfd16a6074dff26ab41fdcbbab733",
"md5": "3d741bb0cc128af5963996a64b153917",
"sha256": "7db897b293d3021079077e7e9e4debe34dd882c21ef42fae99ca2c028c03baf0"
},
"downloads": -1,
"filename": "httpy-2.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3d741bb0cc128af5963996a64b153917",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.0",
"size": 76356,
"upload_time": "2024-09-27T14:38:18",
"upload_time_iso_8601": "2024-09-27T14:38:18.678076Z",
"url": "https://files.pythonhosted.org/packages/5f/a1/b6a890e54a205388f4f49c8e658d7b1bfd16a6074dff26ab41fdcbbab733/httpy-2.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c4e58f6d261bae8ff8dec37cfa89a233540ba7ea1407dd933cdeaad394efa26c",
"md5": "7c7edb42193d5bf5885e57e67f4598fa",
"sha256": "f0fbcec94549b3fe5f284e72b7bc0e4a685ea5f96f83d19dfdffaa4e21cd1b15"
},
"downloads": -1,
"filename": "httpy-2.1.2.tar.gz",
"has_sig": false,
"md5_digest": "7c7edb42193d5bf5885e57e67f4598fa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.0",
"size": 73112,
"upload_time": "2024-09-27T14:38:20",
"upload_time_iso_8601": "2024-09-27T14:38:20.289832Z",
"url": "https://files.pythonhosted.org/packages/c4/e5/8f6d261bae8ff8dec37cfa89a233540ba7ea1407dd933cdeaad394efa26c/httpy-2.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-27 14:38:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jenca-adam",
"github_project": "httpy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "httpy"
}