convert offline/online data to base64 clean, fast and easy
- clean, fast and easy
- convert data (image, video, text) to base64 from URL or local or b'string'
- convert base64 to data (image, video, text)
- auto-detect source type all you have to do is inserting the source
- support proxies, custom success code
- convert data to html(base64) tags, and data_uri
You can either install from pypi or the source code
- Using pip
pip install b64
- from the source code
git clone https://github.com/n0x1s/b64
cd b64
python setup.py install
Let us suppose you have a group of data that you want to convert to base64 or the opposite
>>> from b64 import B64
### some examples ####
>>> online_image = 'https://avatars3.githubusercontent.com/u/1'
>>> local_image = 'test.jpg'
>>> string = 'hello'.encode()
>>> online_base64 = 'https://pastebin.com/raw/mYPrvzDz'
>>> local_base64 = 'example.txt'
>>> b64_string = b'aGVsbG8='
- converting online data
>>> B64(online_image).data # converting image to base64
> b'iVBORw0KGgoAAAANSUhEUgAAAcwAAAHMCAYAAABY25iGA...'
>>> B64('https://pastebin.com/raw/mYPrvzDz', to='string', codes=[200, 201]).data # you can set the success http codes or use proxies
> b'Hello'
- converting local data
>>> B64(local_image).data # converting image to base64
> b'iVBORw0KGgoAAAANSUhEUgAAAcwAAAHMCAYAAABY25iGA...'
>>> B64('example.txt', to='string').data # converting local base64 string to bytes
> b'Hello'
>>> from b64 import Tag64
>>> t = Tag64('https://avatars3.githubusercontent.com/u/1', 'img')
>>> t.html_tag
> '<img src="data:;base64,/9j/4AAQSkZJRgABAQAAAQA...'
>>> t.data_uri
> b'iVBORw0KGgoAAAANSUhEUgAAAcwAAAHMCAYAAABY25iGA...'
I will try to maintain this respiratory and update or add new things to it you are welcome to contribute
And, as always have a beautiful day!