A simple python wrapper for making requests to the API of TheBigDB.com. Full API documentation.
Just grab the file thebigdb.py
. You'll only need to have the package requests intalled.
First, you need to initialize the class with:
from thebigdb import TheBigDB
thebigdb = TheBigDB()
The following actions return a dict object from the parsed JSON the server answered.
Search (api doc)
thebigdb.search({"subject": {match: "James"}, "property": "job", "answer": "President of the United States"})
thebigdb.search({"subject": "London", "property": "population"}, {"period": {"on": "2007-06-05"}})
Create (api doc)
thebigdb.api_key = "your-private-api-key"
thebigdb.create({"subject": "iPhone 5", "property": "weight", "answer": "112 grams"})
thebigdb.create({"subject": "Bill Clinton", "property": "job", "answer": "President of the United States"}, {"period": {"from": "1993-01-20 12:00:00", "to": "2001-01-20 12:00:00"}})
thebigdb.show("id-of-the-sentence")
thebigdb.upvote("id-of-the-sentence") # don't forget to set your API key
thebigdb.downvote("id-of-the-sentence") # don't forget to set your API key
That's it!
If you want more details on what has been received, you can check thebigdb.response
after each request.
It is the object returned by the requests
package after each request.
It has several readable attributes:
thebigdb.show("id-of-the-sentence")
thebigdb.response.content # String of the actual content received from the server
thebigdb.response.headers # Dict of the headers received from the server
You can access other parts of the API in the same way as statements:
thebigdb.user(action, parameters)
# Examples
thebigdb.user("show", {"login": "christophe"})["user"]["karma"]
- Python 2.7+
Don't hesitate to send a pull request !
First, install the required packages:
pip install -r requirements.pip
Then, run the tests in the tests.py
file with:
nosetests
- bobtwinkles for creating the first version of this wrapper
- The community for their invaluable feedback!