All Projects → fcurella → python-datauri

fcurella / python-datauri

Licence: Unlicense license
Data URI manipulation made easy.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to python-datauri

blur-up
A tool that creates preview images.
Stars: ✭ 28 (-3.45%)
Mutual labels:  data-uri
Webcamjs
HTML5 Webcam Image Capture Library with Flash Fallback
Stars: ✭ 2,363 (+8048.28%)
Mutual labels:  data-uri
Qr Code
QR Code Generator
Stars: ✭ 3,519 (+12034.48%)
Mutual labels:  data-uri
valid-data-url
Detect if a string is a data URL
Stars: ✭ 17 (-41.38%)
Mutual labels:  data-uri
ng-webcam
ngWebcam is an AngularJS directive for capturing images from your computer's camera, and delivering then to you as data uri.
Stars: ✭ 14 (-51.72%)
Mutual labels:  data-uri
vue-base64-file-upload
Upload files as base64 data-uris
Stars: ✭ 77 (+165.52%)
Mutual labels:  data-uri

DataURI

Build status of the master branch on Mac/Linux https://coveralls.io/repos/github/fcurella/python-datauri/badge.svg?branch=master

Data URI manipulation made easy.

This isn't very robust, and will reject a number of valid data URIs. However, it meets the most useful case: a mimetype, a charset, and the base64 flag.

Installation

$ pip install python-datauri

Parsing

>>> from datauri import DataURI
>>> uri = DataURI('data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu')
>>> uri.mimetype
'text/plain'
>>> uri.charset
'utf-8'
>>> uri.is_base64
True
>>> uri.data
b'The quick brown fox jumped over the lazy dog.'

Note that DataURI.data will always return bytes, (which in Python 2 is the same as a string). Use DataURI.text to get a string.

Creating from a string

>>> from datauri import DataURI
>>> made = DataURI.make('text/plain', charset='us-ascii', base64=True, data='This is a message.')
>>> made
DataURI('data:text/plain;charset=us-ascii;base64,VGhpcyBpcyBhIG1lc3NhZ2Uu')
>>> made.data
b'This is a message.'

Creating from a file

This is really just a convenience method.

>>> from datauri import DataURI
>>> png_uri = DataURI.from_file('somefile.png')
>>> png_uri.mimetype
'image/png'
>>> png_uri.data
b'\x89PNG\r\n...'

License

This code is released under the Unlicense.

Credits

This is a repackaging of this Gist originally written by Zachary Voase.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].