Skip to main content

Headers: Keep-It=Simple; And=Stupid.

Project description

Welcome to Headers for Human 👋

Temporary logo
So simple ! With auto-completion !
License: MIT Documentation Status

Why ?

No matters your religion, IMAP4 or HTTP, you should not worries about accessing easily header and associated attributes, adjectives or values.

using kiss-headers from python interpreter

I have seen so much chunk of code trying to deal with them, often I saw this :

charset = headers['Content-Type'].split(';')[-1].split('=')[-1]

No more of that !

Your support

Please ⭐ this repository if this project helped you!

✨ Installation

Whatever you like, use Pipenv or pip, it simply work. We are expecting you to have python 3.6+ installed.

pip install kiss-headers

🍰 Usage

parse_it() method take bytes, str, fp, dict or even requests.Response itself and give you back a Headers object.

from requests import get
from kiss_headers import parse_it

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

'Content-Type' in headers  # output: True
'Content_type' in headers  # output: True

str(headers.content_type)  # output : text/html; charset=ISO-8859-1
'application/json' in headers.content_type  # output: False
'text/html' in headers.content_type # output: True

str(headers.content_type.charset)  # output : ISO-8859-1
type(headers.set_cookie) # output: list
'Secure' in headers.set_cookie[0] # output: True
'domain' in headers.set_cookie[0] # output: True
headers.set_cookie[0].domain # output: .google.fr

Do not forget that headers are not 1 TO 1. One header can be repeated multiple time and attribute can have multiple value within the same header.

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

👤 Contributing

Contributions, issues and feature requests are very much welcome.
Feel free to check issues page if you want to contribute.

📝 License

Copyright © 2020 Ahmed TAHRI @Ousret.
This project is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiss-headers-1.0.2.tar.gz (7.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page