File tree 3 files changed +40
-9
lines changed
3 files changed +40
-9
lines changed Original file line number Diff line number Diff line change
1
+ # Sniffpy
2
+
3
+ Sniffpy is a python implementation of [ MIME Sniffing Standard] ( https://mimesniff.specw.whatwg.org/ )
4
+ MIME sniffing describes algorithms that attempt to discern the correct MIME type of some given
5
+ data. The MIME type of a file or byte stream describes its format. For example, the MIME type of an image could be
6
+ ` image/jpeg ` or ` image/png ` depending on its exact format. MIME types consist of:
7
+
8
+ * the ` type ` which describesthe broad category of the data
9
+ * the ` subtype ` which describes the exact kind of data
10
+ * an optional ` parameter ` which gives further information about the data
11
+
12
+ The exact specification of MIME types can be found [ here] ( https://tools.ietf.org/html/rfc6838 )
13
+
14
+ ## Example
15
+
16
+ The following is an example on how to use sniffpy to guess the MIME type of an HTTP response using requests
17
+
18
+ ```
19
+ import requests
20
+
21
+ r = requests.get("https://httpbin.org/image/jpeg")
22
+ mime_type = sniffpy.sniff(r.content) #returns a MIMEType object
23
+
24
+ print(mime_type.type) #prints "image"
25
+ print(mime_type.subtype) #prints "jpeg"
26
+
27
+ print(mime_type) #prints "image/jpeg"
28
+ ```
29
+
30
+ Documentation on how to use the package and how to contribute can be found on [ here] ( https://sniffpy.readthedocs.io/en/latest/ )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import sniffpy
2
+ import requests
3
+
4
+ r = requests .get ("https://httpbin.org/image/jpeg" )
5
+ mime_type = sniffpy .sniff (r .content ) #returns a MIMEType object
6
+
7
+ print (mime_type .type ) #prints "image"
8
+ print (mime_type .subtype ) #prints "jpeg"
9
+
10
+ print (mime_type ) #prints "image/jpeg"
You can’t perform that action at this time.
0 commit comments