Nicholas H.Tollervey
ntoll.org
/
ntoll@ntoll.org
/
@ntoll
(I'm glossing over a lot here...)
>>> home = {}
>>> home['ntoll'] = 'Towcester'
>>> home['voidspace'] = 'Bugbrook'
>>> home['pinner'] = 'Coventry'
>>> home
{
'ntoll': 'Towcester',
'voidspace': 'Bugbrook',
'pinner': 'Coventry'
}
>>> home['ntoll']
'Towcester'
A very simple key / value data store.
What the rest of the talk is about:
>>> import requests
>>> response = requests.get(
'http://www.gutenberg.org/ebooks/2600.txt.utf-8')
>>> war_and_peace = response.content
>>> len(war_and_peace)
3291641
>>> from hashlib import sha1
>>> hash = sha1(war_and_peace)
>>> hash.hexdigest()
'ee9fe1af40a27e58ca32dce32c891dce2885bbcb'
>>> int(hash.hexdigest().encode('hex'), 16)
8460127932676481751312505548999589516107164899634142
19229096415778905956014446754451978211976034L
A hash is just a number.
>>> from hashlib import sha1
>>> item = {
... 'my_key': 'Some value I want to store'
... }
>>> sha1('my_key').hexdigest()
'0f7da3f82f86e5ea63d3ac270f091af4bcfa819a'
(ID, IP address and port etc...)
Licensed under CC BY 2.0
The source for this presentation can be found online here: