1
1
#firebase-python
2
2
######A nice (working!) Python Firebase integration for hackers
3
3
4
- Quick and dirty but not crappy: this Python module will get you from 0 to Firebase in under 3 seconds.
5
-
6
- Supports streaming API but not authentication.
4
+ Quick and dirty, but not crappy. Supports streaming API but not authentication.
7
5
8
6
Requires ` requests ` and ` sseclient ` , which are on pip. If you don't know what that is, don't worry; just run ` ./setup.sh ` .
9
7
10
8
11
9
12
10
##get and put
13
11
14
- `get` gets the value of a Firebase at some URL, and `put` sets the value of a Firebase at some URL to some data.
12
+ ` get ` gets the value of a Firebase at some URL, and ` put ` sets the value of a Firebase at URL to some data.
15
13
16
14
``` python
17
15
>> > import firebase
18
-
19
16
>> > URL = ' lucid-lychee' # see note on URLs at the bottom of documentation
20
-
21
17
>> > firebase.get(URL ) == None # this is an empty Firebase
22
18
True
23
19
24
20
>> > firebase.put(URL , ' tell me everything' ) # can take a string
25
-
26
21
>> > firebase.get(URL )
27
22
u ' tell me everything'
28
23
29
24
>> > firebase.put(URL , {' lucidity' : 9001 }) # or a dictionary
30
-
31
25
>> > firebase.get(URL )
32
26
{u ' lucidity' : 9001 }
33
27
34
28
>> > firebase.put(URL , {' color' : ' red' }) # replaces old value
35
-
36
29
>> > firebase.get(URL )
37
30
{u ' color' : u ' red' }
38
31
@@ -44,23 +37,19 @@ u'red'
44
37
45
38
##patch
46
39
47
- `patch` updates an existing key value store at some URL with new key value pairs , without deleting the old key value pairs.
40
+ ` patch ` adds new key value pairs to an existing Firebase , without deleting the old key value pairs.
48
41
49
42
``` python
50
43
>> > import firebase
51
-
52
44
>> > URL = ' tibetan-tumbleweed'
53
-
54
45
>> > firebase.get(URL ) == None
55
46
True
56
47
57
48
>> > firebase.patch(URL , {' taste' : ' tibetan' })
58
-
59
49
>> > firebase.get(URL )
60
50
{u ' taste' : u ' tibetan' }
61
51
62
52
>> > firebase.patch(URL , {' size' : ' tumbly}) # patching does not overwrite
63
-
64
53
>> > firebase.get(URL )
65
54
{u ' taste' : u ' tibetan' , u ' size' : u ' tumbly' }
66
55
```
69
58
70
59
# #subscriber
71
60
72
- `subscriber` takes a URL and callback function and calls that callback on every update of the Firebase at URL.
61
+ `subscriber` takes a URL and callback function and calls the callback on every update of the Firebase at URL .
73
62
74
63
```python
75
64
>> > import firebase
76
-
77
65
>> > from pprint import pprint # function which pretty prints objects
78
-
79
66
>> > URL = ' clumsy-clementine'
80
-
81
67
>> > S = firebase.subscriber(URL , pprint) # pprint will be called on all Firebase updates
82
-
83
68
>> > S.start() # will get called with initial value of URL, which is empty
84
69
{u ' data' : None , u ' path' : u ' /' }
85
70
86
71
>> > firebase.put(URL , ' ;-)' ) # will make S print something
87
72
{u ' data' : u ' ;-)' , u ' path' : u ' /' }
88
73
89
- >>> firebase.put(URL, {'status': 'mortified'})
74
+ >> > firebase.put(URL , {' status' : ' mortified' }) # continuing from above
90
75
{u ' data' : {u ' status' : u ' mortified' }, u ' path' : u ' /' }
91
-
92
76
>> > firebase.patch(URL , {' reason' : ' blushing' }) # this one is scary
93
77
{u ' data' : {u ' reason' : u ' blushing' }, u ' path' : u ' /' }
94
-
95
- >>> firebase.get(URL) # notice the update only gave us the update without telling us
78
+ >> > firebase.get(URL ) # notice the update only gave us the new k,v without telling us
96
79
{u ' status' : u ' mortified' , u ' reason' : u ' blushing' }
97
80
98
81
>> > firebase.put(URL , {' color' : ' orange-red' }) # expect change from S
99
82
{u ' data' : {u ' color' : u ' orange-red' }, u ' path' : u ' /' }
100
-
101
83
>> > firebase.get(URL ) # put overwrites, but S doesn't tell us!
102
84
{u ' color' : u ' orange-red' }
103
85
0 commit comments