kiss-headers


Namekiss-headers JSON
Version 2.4.3 PyPI version JSON
download
home_page
SummaryObject-oriented HTTP and IMAP (structured) headers.
upload_time2023-11-12 18:21:37
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords header headers http https imap imap4 mail text
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">HTTP Headers, the Complete Toolkit 🧰 <a href="https://twitter.com/intent/tweet?text=Python%20library%20for%20oriented%20object%20HTTP%20style%20headers.&url=https://www.github.com/Ousret/kiss-headers&hashtags=python,headers,opensource"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social"/></a></h1>

<p align="center">
  <sup>Object-oriented headers. Kind of structured headers.</sup><br>
  <a href='https://pypi.org/project/kiss-headers/'>
     <img src="https://img.shields.io/pypi/pyversions/kiss-headers.svg?orange=blue" />
  </a>
  <a href="https://codecov.io/gh/Ousret/kiss-headers">
      <img src="https://codecov.io/gh/Ousret/kiss-headers/branch/master/graph/badge.svg" />
  </a>
  <a href="https://pepy.tech/project/kiss-headers/">
     <img alt="Download Count Total" src="https://pepy.tech/badge/kiss-headers" />
  </a>
</p>

### ❓ Why

No matter if you are currently dealing with code using HTTP or IMAP _(message, email)_, you should not worry about easily accessing and exploiting headers.

<p align="center">
<img src="https://user-images.githubusercontent.com/9326700/77257881-55866300-6c77-11ea-820c-7550e6bdeee7.gif" alt="using kiss-headers from python interpreter"/>
</p>

I have seen so many chunks of code trying to deal with these headers; often I saw this implementation:
```python
# No more of that!
charset = headers['Content-Type'].split(';')[-1].split('=')[-1].replace('"', '')
# That too..
response = get(
    "https://httpbin.org/headers",
    headers={
        "user-agent": "custom/2.22",
        "referer": "https://www.google.com",
        "accept": "text/html",
        "accept-language": "en-US",
        "custom-header-xyz": "hello; charset=utf-8"
    }
)
```

**Scroll down and see how you could do it from now on.**

## 🔪 Features

`kiss-headers` is a basic library that allow you to handle headers as objects.

* A backwards-compatible syntax using bracket style.
* Capability to alter headers using simple, human-readable operator notation `+` and `-`.
* Flexibility if headers are from an email or HTTP, use as you need with one library.
* Ability to parse any object and extract recognized headers from it, it also supports UTF-8 encoded headers.
* Offer an opinionated way to un/serialize headers.
* Fully type-annotated.
* Provide great auto-completion in Python interpreter or any capable IDE.
* No dependencies. Never will be.
* Support JSON in header value.
* 90% test coverage.

Plus all the features that you would expect from handling headers...

* Properties syntax for headers and attribute in a header.
* Supports headers and attributes OneToOne, OneToMany and ManySquashedIntoOne.
* Capable of parsing `bytes`, `fp`, `str`, `dict`, `email.Message`, `requests.Response`, `niquests.Response`, `httpx._models.Response` and `urllib3.HTTPResponse`.
* Automatically unquote and unfold the value of an attribute when retrieving it.
* Keep headers and attributes ordering.
* Case-insensitive with header name and attribute key.
* Character `-` equal `_` in addition of above feature.
* Any syntax you like, we like.

### ✨ Installation

Whatever you like, use `pipenv` or `pip`, it simply works. Requires Python 3.7+ installed.
```sh 
pip install kiss-headers --upgrade
```

This project is included in [Niquests](https://github.com/jawah/niquests)! Your awesome drop-in replacement for Requests!

### 🍰 Usage

#### Quick start
`parse_it()` method takes `bytes`, `str`, `fp`, `dict`, `email.Message` or even a `requests.Response` or `httpx._models.Response` itself and returns a `Headers` object.

```python
from requests import get
from kiss_headers import parse_it

response = get('https://www.google.fr')
headers = parse_it(response)

headers.content_type.charset  # output: ISO-8859-1
# Its the same as
headers["content-type"]["charset"]  # output: ISO-8859-1
```

and also, the other way around:

```python
from requests import get
from kiss_headers import Headers, UserAgent, Referer, UpgradeInsecureRequests, Accept, AcceptLanguage, CustomHeader

class CustomHeaderXyz(CustomHeader):
    
    __squash__ = False
    
    def __init__(self, charset: str = "utf-8"):
        super().__init__("hello", charset=charset)

# Officially supported with requests
response = get(
    "https://httpbin.org/headers",
    headers=Headers(
        UserAgent("custom/2.22"),
        Referer("https://www.google.com"),
        UpgradeInsecureRequests(),
        Accept("text/html"),
        AcceptLanguage("en-US"),
        CustomHeaderXyz()
    )
)
```

httpbin should get back with:

```json
{
    "headers": {
        "Accept": "text/html",
        "Accept-Encoding": "identity",
        "Accept-Language": "en-US",
        "Custom-Header-Xyz": "hello; charset=\"utf-8\"",
        "Host": "httpbin.org",
        "Referer": "https://www.google.com",
        "Upgrade-Insecure-Requests": "1",
        "User-Agent": "custom/2.22",
        "X-Amzn-Trace-Id": "Root=1-622sz46b-973c5671113f58d611972de"
    }
}
```

Do not forget that headers are not OneToOne. One header can be repeated multiple times and attributes can have multiple values within the same header.

```python
from kiss_headers import parse_it

my_cookies = """set-cookie: 1P_JAR=2020-03-16-21; expires=Wed, 15-Apr-2020 21:27:31 GMT; path=/; domain=.google.fr; Secure; SameSite=none
set-cookie: CONSENT=WP.284b10; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.google.fr"""

headers = parse_it(my_cookies)

type(headers.set_cookie)  # output: list
headers.set_cookie[0].expires # output: Wed, 15-Apr-2020 21:27:31 GMT
headers.set_cookie[0]._1p_jar # output: 2020-03-16-21
headers.set_cookie[0]["1P_JAR"] # output: 2020-03-16-21
```

Since v2.1 you can transform an Header object to its target `CustomHeader` subclass to access more methods.

```python
from kiss_headers import parse_it, get_polymorphic, SetCookie

my_cookies = """set-cookie: 1P_JAR=2020-03-16-21; expires=Wed, 15-Apr-2020 21:27:31 GMT; path=/; domain=.google.fr; Secure; SameSite=none
set-cookie: CONSENT=WP.284b10; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.google.fr"""

headers = parse_it(my_cookies)

type(headers.set_cookie[0])  # output: Header

set_cookie = get_polymorphic(headers.set_cookie[0], SetCookie)

type(set_cookie)  # output: SetCookie

set_cookie.get_cookie_name()  # output: 1P_JAR
set_cookie.get_expire()  # output: datetime(...)
```

Just a note: Accessing a header that has the same name as a reserved keyword must be done this way :
```python
headers = parse_it('From: Ousret; origin=www.github.com\nIS: 1\nWhile: Not-True')

# this flavour
headers.from_ # to access From, just add a single underscore to it
# or.. just using :
headers['from']
```

#### ✍️Serialization

Since version 2.3.0 the package offer the possibility to un/serialize `Headers`.

```python
from requests import get
from kiss_headers import parse_it, dumps

json_repr: str = dumps(
    parse_it(
        get("https://www.google.fr")
    ),
    indent=4
)

print(json_repr)  # See the result bellow

# Additionally, how to parse the JSON repr to Headers again
headers = parse_it(json_repr)  # Yes! that easy!
```

```json
{
    "Date": [
        {
            "Tue, 02 Feb 2021 21:43:13 GMT": null
        }
    ],
    "Expires": [
        {
            "-1": null
        }
    ],
    "Cache-Control": [
        {
            "private": null
        },
        {
            "max-age": "0"
        }
    ],
    "Content-Type": [
        {
            "text/html": null,
            "charset": "ISO-8859-1"
        }
    ],
    "P3P": [
        {
            "CP": "This is not a P3P policy! See g.co/p3phelp for more info."
        }
    ],
    "Content-Encoding": [
        {
            "gzip": null
        }
    ],
    "Server": [
        {
            "gws": null
        }
    ],
    "X-XSS-Protection": [
        {
            "0": null
        }
    ],
    "X-Frame-Options": [
        {
            "SAMEORIGIN": null
        }
    ],
    "Set-Cookie": [
        {
            "NID": "208=D5XUqjrP9PNpiZu4laa_0xvy_IxBzQLtfxqeAqcPBgiY2y5sfSF51IFuXZnH0zDAF1KZ8x-0VsRyGOM0aStIzCUfdiPBOCxHSxUv39N0vwzku3aI2UkeRXhWw8-HWw5Ob41GB0PZi2coQsPM7ZEQ_fl9PlQ_ld1KrPA",
            "expires": "Wed, 04-Aug-2021 21:43:13 GMT",
            "path": "/",
            "domain": ".google.fr",
            "HttpOnly": null
        },
        {
            "CONSENT": "PENDING+880",
            "expires": "Fri, 01-Jan-2038 00:00:00 GMT",
            "path": "/",
            "domain": ".google.fr"
        }
    ],
    "Alt-Svc": [
        {
            "h3-29": ":443",
            "ma": "2592000"
        },
        {
            "h3-T051": ":443",
            "ma": "2592000"
        },
        {
            "h3-Q050": ":443",
            "ma": "2592000"
        },
        {
            "h3-Q046": ":443",
            "ma": "2592000"
        },
        {
            "h3-Q043": ":443",
            "ma": "2592000"
        },
        {
            "quic": ":443",
            "ma": "2592000",
            "v": "46,43"
        }
    ],
    "Transfer-Encoding": [
        {
            "chunked": null
        }
    ]
}
```

Alternatively you may use `from kiss_headers import parse_it, encode, decode` to transform `Headers` to `dict` (instead of JSON) or the other way around.
Understand that the `dict` returned in `encode` will differ from the method `to_dict()` in `Headers`.

#### 🛠️ Create headers from objects

Introduced in the version 2.0, kiss-headers now allow you to create headers with more than 40+ ready-to-use, fully documented, header objects.

1st example usage
```python
from kiss_headers import Headers, Authorization
from requests import get

response = get("https://httpbin.org/bearer", headers=Headers(Authorization("Bearer", "qwerty")))
print(response.status_code)  # 200
```

2nd example usage
```python
from kiss_headers import *

headers = (
    Host("developer.mozilla.org")
    + UserAgent(
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0"
    )
    + Accept("text/html")
    + Accept("application/xhtml+xml")
    + Accept("application/xml", qualifier=0.9)
    + Accept(qualifier=0.8)
    + AcceptLanguage("en-US")
    + AcceptLanguage("en", qualifier=0.5)
    + AcceptEncoding("gzip")
    + AcceptEncoding("deflate")
    + AcceptEncoding("br")
    + Referer("https://developer.mozilla.org/testpage.html")
    + Connection(should_keep_alive=True)
    + UpgradeInsecureRequests()
    + IfModifiedSince("Mon, 18 Jul 2016 02:36:04 GMT")
    + IfNoneMatch("c561c68d0ba92bbeb8b0fff2a9199f722e3a621a")
    + CacheControl(max_age=0)
)

raw_headers = str(headers)
```

`raw_headers` now retain the following :

```
Host: developer.mozilla.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html, application/xhtml+xml, application/xml; q="0.9", */*; q="0.8"
Accept-Language: en-US, en; q="0.5"
Accept-Encoding: gzip, deflate, br
Referer: https://developer.mozilla.org/testpage.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT
If-None-Match: "c561c68d0ba92bbeb8b0fff2a9199f722e3a621a"
Cache-Control: max-age="0"
```

See the complete list of available header class in the full documentation. 
Also, you can create your own custom header object using the class `kiss_headers.CustomHeader`.

## 📜 Documentation

See the full documentation for advanced usages : [ousret.github.io/kiss-headers](https://ousret.github.io/kiss-headers/)

## 👤 Contributing

Contributions, issues and feature requests are very much welcome.<br />
Feel free to check [issues page](https://github.com/Ousret/kiss-headers/issues) if you want to contribute.

Firstly, after getting your own local copy, run `./scripts/install` to initialize your virtual environment.
Then run `./scripts/check` before you commit, make sure everything is still working.

Remember to keep it sweet and simple when contributing to this project.

## 📝 License

Copyright © 2020 [Ahmed TAHRI @Ousret](https://github.com/Ousret).<br />
This project is [MIT](https://github.com/Ousret/kiss-headers/blob/master/LICENSE) licensed.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "kiss-headers",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "\"Ahmed R. TAHRI\" <ahmed.tahri@cloudnursery.dev>",
    "keywords": "header,headers,http,https,imap,imap4,mail,text",
    "author": "",
    "author_email": "\"Ahmed R. TAHRI\" <ahmed.tahri@cloudnursery.dev>",
    "download_url": "https://files.pythonhosted.org/packages/b7/6d/38924e42f83d18a133991cdfec631aecec1ee75c19716696b56975b914bc/kiss_headers-2.4.3.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">HTTP Headers, the Complete Toolkit \ud83e\uddf0 <a href=\"https://twitter.com/intent/tweet?text=Python%20library%20for%20oriented%20object%20HTTP%20style%20headers.&url=https://www.github.com/Ousret/kiss-headers&hashtags=python,headers,opensource\"><img src=\"https://img.shields.io/twitter/url/http/shields.io.svg?style=social\"/></a></h1>\n\n<p align=\"center\">\n  <sup>Object-oriented headers. Kind of structured headers.</sup><br>\n  <a href='https://pypi.org/project/kiss-headers/'>\n     <img src=\"https://img.shields.io/pypi/pyversions/kiss-headers.svg?orange=blue\" />\n  </a>\n  <a href=\"https://codecov.io/gh/Ousret/kiss-headers\">\n      <img src=\"https://codecov.io/gh/Ousret/kiss-headers/branch/master/graph/badge.svg\" />\n  </a>\n  <a href=\"https://pepy.tech/project/kiss-headers/\">\n     <img alt=\"Download Count Total\" src=\"https://pepy.tech/badge/kiss-headers\" />\n  </a>\n</p>\n\n### \u2753 Why\n\nNo matter if you are currently dealing with code using HTTP or IMAP _(message, email)_, you should not worry about easily accessing and exploiting headers.\n\n<p align=\"center\">\n<img src=\"https://user-images.githubusercontent.com/9326700/77257881-55866300-6c77-11ea-820c-7550e6bdeee7.gif\" alt=\"using kiss-headers from python interpreter\"/>\n</p>\n\nI have seen so many chunks of code trying to deal with these headers; often I saw this implementation:\n```python\n# No more of that!\ncharset = headers['Content-Type'].split(';')[-1].split('=')[-1].replace('\"', '')\n# That too..\nresponse = get(\n    \"https://httpbin.org/headers\",\n    headers={\n        \"user-agent\": \"custom/2.22\",\n        \"referer\": \"https://www.google.com\",\n        \"accept\": \"text/html\",\n        \"accept-language\": \"en-US\",\n        \"custom-header-xyz\": \"hello; charset=utf-8\"\n    }\n)\n```\n\n**Scroll down and see how you could do it from now on.**\n\n## \ud83d\udd2a Features\n\n`kiss-headers` is a basic library that allow you to handle headers as objects.\n\n* A backwards-compatible syntax using bracket style.\n* Capability to alter headers using simple, human-readable operator notation `+` and `-`.\n* Flexibility if headers are from an email or HTTP, use as you need with one library.\n* Ability to parse any object and extract recognized headers from it, it also supports UTF-8 encoded headers.\n* Offer an opinionated way to un/serialize headers.\n* Fully type-annotated.\n* Provide great auto-completion in Python interpreter or any capable IDE.\n* No dependencies. Never will be.\n* Support JSON in header value.\n* 90% test coverage.\n\nPlus all the features that you would expect from handling headers...\n\n* Properties syntax for headers and attribute in a header.\n* Supports headers and attributes OneToOne, OneToMany and ManySquashedIntoOne.\n* Capable of parsing `bytes`, `fp`, `str`, `dict`, `email.Message`, `requests.Response`, `niquests.Response`, `httpx._models.Response` and `urllib3.HTTPResponse`.\n* Automatically unquote and unfold the value of an attribute when retrieving it.\n* Keep headers and attributes ordering.\n* Case-insensitive with header name and attribute key.\n* Character `-` equal `_` in addition of above feature.\n* Any syntax you like, we like.\n\n### \u2728 Installation\n\nWhatever you like, use `pipenv` or `pip`, it simply works. Requires Python 3.7+ installed.\n```sh \npip install kiss-headers --upgrade\n```\n\nThis project is included in [Niquests](https://github.com/jawah/niquests)! Your awesome drop-in replacement for Requests!\n\n### \ud83c\udf70 Usage\n\n#### Quick start\n`parse_it()` method takes `bytes`, `str`, `fp`, `dict`, `email.Message` or even a `requests.Response` or `httpx._models.Response` itself and returns a `Headers` object.\n\n```python\nfrom requests import get\nfrom kiss_headers import parse_it\n\nresponse = get('https://www.google.fr')\nheaders = parse_it(response)\n\nheaders.content_type.charset  # output: ISO-8859-1\n# Its the same as\nheaders[\"content-type\"][\"charset\"]  # output: ISO-8859-1\n```\n\nand also, the other way around:\n\n```python\nfrom requests import get\nfrom kiss_headers import Headers, UserAgent, Referer, UpgradeInsecureRequests, Accept, AcceptLanguage, CustomHeader\n\nclass CustomHeaderXyz(CustomHeader):\n    \n    __squash__ = False\n    \n    def __init__(self, charset: str = \"utf-8\"):\n        super().__init__(\"hello\", charset=charset)\n\n# Officially supported with requests\nresponse = get(\n    \"https://httpbin.org/headers\",\n    headers=Headers(\n        UserAgent(\"custom/2.22\"),\n        Referer(\"https://www.google.com\"),\n        UpgradeInsecureRequests(),\n        Accept(\"text/html\"),\n        AcceptLanguage(\"en-US\"),\n        CustomHeaderXyz()\n    )\n)\n```\n\nhttpbin should get back with:\n\n```json\n{\n    \"headers\": {\n        \"Accept\": \"text/html\",\n        \"Accept-Encoding\": \"identity\",\n        \"Accept-Language\": \"en-US\",\n        \"Custom-Header-Xyz\": \"hello; charset=\\\"utf-8\\\"\",\n        \"Host\": \"httpbin.org\",\n        \"Referer\": \"https://www.google.com\",\n        \"Upgrade-Insecure-Requests\": \"1\",\n        \"User-Agent\": \"custom/2.22\",\n        \"X-Amzn-Trace-Id\": \"Root=1-622sz46b-973c5671113f58d611972de\"\n    }\n}\n```\n\nDo not forget that headers are not OneToOne. One header can be repeated multiple times and attributes can have multiple values within the same header.\n\n```python\nfrom kiss_headers import parse_it\n\nmy_cookies = \"\"\"set-cookie: 1P_JAR=2020-03-16-21; expires=Wed, 15-Apr-2020 21:27:31 GMT; path=/; domain=.google.fr; Secure; SameSite=none\nset-cookie: CONSENT=WP.284b10; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.google.fr\"\"\"\n\nheaders = parse_it(my_cookies)\n\ntype(headers.set_cookie)  # output: list\nheaders.set_cookie[0].expires # output: Wed, 15-Apr-2020 21:27:31 GMT\nheaders.set_cookie[0]._1p_jar # output: 2020-03-16-21\nheaders.set_cookie[0][\"1P_JAR\"] # output: 2020-03-16-21\n```\n\nSince v2.1 you can transform an Header object to its target `CustomHeader` subclass to access more methods.\n\n```python\nfrom kiss_headers import parse_it, get_polymorphic, SetCookie\n\nmy_cookies = \"\"\"set-cookie: 1P_JAR=2020-03-16-21; expires=Wed, 15-Apr-2020 21:27:31 GMT; path=/; domain=.google.fr; Secure; SameSite=none\nset-cookie: CONSENT=WP.284b10; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.google.fr\"\"\"\n\nheaders = parse_it(my_cookies)\n\ntype(headers.set_cookie[0])  # output: Header\n\nset_cookie = get_polymorphic(headers.set_cookie[0], SetCookie)\n\ntype(set_cookie)  # output: SetCookie\n\nset_cookie.get_cookie_name()  # output: 1P_JAR\nset_cookie.get_expire()  # output: datetime(...)\n```\n\nJust a note: Accessing a header that has the same name as a reserved keyword must be done this way :\n```python\nheaders = parse_it('From: Ousret; origin=www.github.com\\nIS: 1\\nWhile: Not-True')\n\n# this flavour\nheaders.from_ # to access From, just add a single underscore to it\n# or.. just using :\nheaders['from']\n```\n\n#### \u270d\ufe0fSerialization\n\nSince version 2.3.0 the package offer the possibility to un/serialize `Headers`.\n\n```python\nfrom requests import get\nfrom kiss_headers import parse_it, dumps\n\njson_repr: str = dumps(\n    parse_it(\n        get(\"https://www.google.fr\")\n    ),\n    indent=4\n)\n\nprint(json_repr)  # See the result bellow\n\n# Additionally, how to parse the JSON repr to Headers again\nheaders = parse_it(json_repr)  # Yes! that easy!\n```\n\n```json\n{\n    \"Date\": [\n        {\n            \"Tue, 02 Feb 2021 21:43:13 GMT\": null\n        }\n    ],\n    \"Expires\": [\n        {\n            \"-1\": null\n        }\n    ],\n    \"Cache-Control\": [\n        {\n            \"private\": null\n        },\n        {\n            \"max-age\": \"0\"\n        }\n    ],\n    \"Content-Type\": [\n        {\n            \"text/html\": null,\n            \"charset\": \"ISO-8859-1\"\n        }\n    ],\n    \"P3P\": [\n        {\n            \"CP\": \"This is not a P3P policy! See g.co/p3phelp for more info.\"\n        }\n    ],\n    \"Content-Encoding\": [\n        {\n            \"gzip\": null\n        }\n    ],\n    \"Server\": [\n        {\n            \"gws\": null\n        }\n    ],\n    \"X-XSS-Protection\": [\n        {\n            \"0\": null\n        }\n    ],\n    \"X-Frame-Options\": [\n        {\n            \"SAMEORIGIN\": null\n        }\n    ],\n    \"Set-Cookie\": [\n        {\n            \"NID\": \"208=D5XUqjrP9PNpiZu4laa_0xvy_IxBzQLtfxqeAqcPBgiY2y5sfSF51IFuXZnH0zDAF1KZ8x-0VsRyGOM0aStIzCUfdiPBOCxHSxUv39N0vwzku3aI2UkeRXhWw8-HWw5Ob41GB0PZi2coQsPM7ZEQ_fl9PlQ_ld1KrPA\",\n            \"expires\": \"Wed, 04-Aug-2021 21:43:13 GMT\",\n            \"path\": \"/\",\n            \"domain\": \".google.fr\",\n            \"HttpOnly\": null\n        },\n        {\n            \"CONSENT\": \"PENDING+880\",\n            \"expires\": \"Fri, 01-Jan-2038 00:00:00 GMT\",\n            \"path\": \"/\",\n            \"domain\": \".google.fr\"\n        }\n    ],\n    \"Alt-Svc\": [\n        {\n            \"h3-29\": \":443\",\n            \"ma\": \"2592000\"\n        },\n        {\n            \"h3-T051\": \":443\",\n            \"ma\": \"2592000\"\n        },\n        {\n            \"h3-Q050\": \":443\",\n            \"ma\": \"2592000\"\n        },\n        {\n            \"h3-Q046\": \":443\",\n            \"ma\": \"2592000\"\n        },\n        {\n            \"h3-Q043\": \":443\",\n            \"ma\": \"2592000\"\n        },\n        {\n            \"quic\": \":443\",\n            \"ma\": \"2592000\",\n            \"v\": \"46,43\"\n        }\n    ],\n    \"Transfer-Encoding\": [\n        {\n            \"chunked\": null\n        }\n    ]\n}\n```\n\nAlternatively you may use `from kiss_headers import parse_it, encode, decode` to transform `Headers` to `dict` (instead of JSON) or the other way around.\nUnderstand that the `dict` returned in `encode` will differ from the method `to_dict()` in `Headers`.\n\n#### \ud83d\udee0\ufe0f Create headers from objects\n\nIntroduced in the version 2.0, kiss-headers now allow you to create headers with more than 40+ ready-to-use, fully documented, header objects.\n\n1st example usage\n```python\nfrom kiss_headers import Headers, Authorization\nfrom requests import get\n\nresponse = get(\"https://httpbin.org/bearer\", headers=Headers(Authorization(\"Bearer\", \"qwerty\")))\nprint(response.status_code)  # 200\n```\n\n2nd example usage\n```python\nfrom kiss_headers import *\n\nheaders = (\n    Host(\"developer.mozilla.org\")\n    + UserAgent(\n        \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0\"\n    )\n    + Accept(\"text/html\")\n    + Accept(\"application/xhtml+xml\")\n    + Accept(\"application/xml\", qualifier=0.9)\n    + Accept(qualifier=0.8)\n    + AcceptLanguage(\"en-US\")\n    + AcceptLanguage(\"en\", qualifier=0.5)\n    + AcceptEncoding(\"gzip\")\n    + AcceptEncoding(\"deflate\")\n    + AcceptEncoding(\"br\")\n    + Referer(\"https://developer.mozilla.org/testpage.html\")\n    + Connection(should_keep_alive=True)\n    + UpgradeInsecureRequests()\n    + IfModifiedSince(\"Mon, 18 Jul 2016 02:36:04 GMT\")\n    + IfNoneMatch(\"c561c68d0ba92bbeb8b0fff2a9199f722e3a621a\")\n    + CacheControl(max_age=0)\n)\n\nraw_headers = str(headers)\n```\n\n`raw_headers` now retain the following :\n\n```\nHost: developer.mozilla.org\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0\nAccept: text/html, application/xhtml+xml, application/xml; q=\"0.9\", */*; q=\"0.8\"\nAccept-Language: en-US, en; q=\"0.5\"\nAccept-Encoding: gzip, deflate, br\nReferer: https://developer.mozilla.org/testpage.html\nConnection: keep-alive\nUpgrade-Insecure-Requests: 1\nIf-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT\nIf-None-Match: \"c561c68d0ba92bbeb8b0fff2a9199f722e3a621a\"\nCache-Control: max-age=\"0\"\n```\n\nSee the complete list of available header class in the full documentation. \nAlso, you can create your own custom header object using the class `kiss_headers.CustomHeader`.\n\n## \ud83d\udcdc Documentation\n\nSee the full documentation for advanced usages : [ousret.github.io/kiss-headers](https://ousret.github.io/kiss-headers/)\n\n## \ud83d\udc64 Contributing\n\nContributions, issues and feature requests are very much welcome.<br />\nFeel free to check [issues page](https://github.com/Ousret/kiss-headers/issues) if you want to contribute.\n\nFirstly, after getting your own local copy, run `./scripts/install` to initialize your virtual environment.\nThen run `./scripts/check` before you commit, make sure everything is still working.\n\nRemember to keep it sweet and simple when contributing to this project.\n\n## \ud83d\udcdd License\n\nCopyright \u00a9 2020 [Ahmed TAHRI @Ousret](https://github.com/Ousret).<br />\nThis project is [MIT](https://github.com/Ousret/kiss-headers/blob/master/LICENSE) licensed.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Object-oriented HTTP and IMAP (structured) headers.",
    "version": "2.4.3",
    "project_urls": {
        "Code": "https://github.com/ousret/kiss-headers",
        "Documentation": "https://ousret.github.io/kiss-headers",
        "Issue tracker": "https://github.com/ousret/kiss-headers/issues"
    },
    "split_keywords": [
        "header",
        "headers",
        "http",
        "https",
        "imap",
        "imap4",
        "mail",
        "text"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f93e9d8f56a758d8259abd6e33417067013a217f7db9e2f37a76d637c5439b9d",
                "md5": "0fb589a321219ed36ea9801b70e6f5c3",
                "sha256": "9d800b77532068e8748be9f96f30eaeb547cdc5345e4689ddf07b77071256239"
            },
            "downloads": -1,
            "filename": "kiss_headers-2.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0fb589a321219ed36ea9801b70e6f5c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 43800,
            "upload_time": "2023-11-12T18:21:36",
            "upload_time_iso_8601": "2023-11-12T18:21:36.015238Z",
            "url": "https://files.pythonhosted.org/packages/f9/3e/9d8f56a758d8259abd6e33417067013a217f7db9e2f37a76d637c5439b9d/kiss_headers-2.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b76d38924e42f83d18a133991cdfec631aecec1ee75c19716696b56975b914bc",
                "md5": "dbe196e31c26a81fd19fb4faee9e14b6",
                "sha256": "70c689ce167ac83146f094ea916b40a3767d67c2e05a4cb95b0fd2e33bf243f1"
            },
            "downloads": -1,
            "filename": "kiss_headers-2.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "dbe196e31c26a81fd19fb4faee9e14b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 72294,
            "upload_time": "2023-11-12T18:21:37",
            "upload_time_iso_8601": "2023-11-12T18:21:37.955460Z",
            "url": "https://files.pythonhosted.org/packages/b7/6d/38924e42f83d18a133991cdfec631aecec1ee75c19716696b56975b914bc/kiss_headers-2.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-12 18:21:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ousret",
    "github_project": "kiss-headers",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "kiss-headers"
}
        
Elapsed time: 0.37273s