Headers: Keep-It=Simple; And=Stupid.
Project description
Welcome to Headers for Human 👋
Imagine you could combine advantages of many representations ! With auto-completion !
❓ Why
No matters your religion, IMAP4 or HTTP, you should not worries about accessing easily header and associated attributes, adjectives or values.
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].replace('"', '')
No more of that ! 🤮
🔪 Features
kiss-headers
is a library on steroid that allow you to handle with great care headers.
- A backward compatible syntax using bracket style.
- Capable to alter headers using simple operator notation
+
and-
like a human would do. - Does not care if headers are from IMAP4 or HTTP, do as you need with one library.
- Ability to parse any object and extract from it recognized headers.
- Fully type annotated.
- Provide great auto-completion in python interpreter or any capable IDE.
- 90% test coverage.
Plus all the features that you would expect from handling headers...
- Properties syntax for headers and attribute in header.
- Support headers and attributes OneToOne and OneToMany.
- Capable of parsing
bytes
,fp
,str
,dict
andrequests.Response
. - Automatically unquote value of an attribute when retrieving it.
- Case insensible on header name and attribute key.
- Character
-
equal_
in addition of above feature. - Any syntax you like. We like.
Your support
Please 🌟 this repository if this project helped you! ✨ That would be very much appreciated ✨
✨ 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)
headers.content_type.charset # output: ISO-8859-1
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
Just a note to inform you that accessing a header that have the same name as a reserved keyword must be done this way :
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..
headers['from']
📜 Documentation
See the full documentation for advanced usages : www.kiss-headers.tech
👤 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for kiss_headers-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d682469fd775ee4b6a96155cd0d8fac13f1cb0acff477566c380889bc41f19ea |
|
MD5 | bf7cd7a857e5e4998031af988ab17287 |
|
BLAKE2b-256 | e9c49fe9cdd8312ac1a5abf462b14f4cf7f1a200378193bb46f87c626f3095dc |