10

About

A lightweight Python wrapper for the Stack Exchange API v2.1. Built with Requests.

Why yet another SE API Python wrapper? (I'm aware of Stack.PY - A Python Module for Accessing the Stack Exchange 2.1 API and Py-StackExchange: An API wrapper for Python.)

For me there were two key things:

  • make commands as straightforward as possible,
  • make easy to harvest a lot of pages.

First, because I wanted to use commands directly from the documentation, e.g.:

se = SEAPI.SEAPI() se.fetch("users/{ids}/comments/{toid}", ids=[29407, 23354], toid=22656, sort="creation", order="desc", site="stackoverflow") 

Second arose from practical reason - I wanted to plot Map of all SE sites (except the 3 biggest), see also Tag Graph Map of Stack Exchange wiki at GitHub, using e.g.:

se.fetch("users", site="cogsci") 

to easily get user_id, account_id and reputation.

License

An open license CC BY 3.0. No warranty etc.

Download

From GitHub: https://github.com/stared/se-api-py.

Do you want to raise an issue or contribute? Great!

Contact

[email protected]

General philosophy of usage

  • se.fetch[_one](command, **parameters)
  • parameters as in the documentation
  • in the command, "{something}" and "{somethings}" are treated as placeholders for an int/str or a list of int/str, respectively

Examples

import SEAPI se = SEAPI.SEAPI() some_users = se.fetch_one("users/{ids}", ids=[1,3,7,9,13], site="stackoverflow") all_user = se.fetch("users", site="academia") 

Now, some_users and all_user are lists with the respective response from each query.

Alternatively, you can initialize SEAPI with default options, typically - site name, e.g.

so = SEAPI.SEAPI(site="stackoverflow") some_questions = so.fetch("questions", page_limit=10) # except for very small sites, you want to set page limit some_sorted_posts = so.fetch_one("posts", order="desc", sort="votes") # for sorting sometimes asking for more that one results in "throttle violation" 

If you want to diagnose a problem, or avoid it:

so.last_call # lookup at the last command sent so.last_status # check the last response status slow_food = so.fetch("tags", min_delay=0.5) # or set delay (by default it's 0.05) 

Feedback

I'm a beginner, so all remarks with respect to the code quality, good practices, etc are welcome!

1

1 Answer 1

3

Step 1: I would like to retrieve all the related tags of a particular tag using your package, much like what is accomplished here.

Step 2: I would like to find the intersection between two lists of related tags.

RELATED: https://stackoverflow.com/q/19898666/307454

6
  • 1
    x = so.fetch("/tags/{tag}/related", tag=tag1), y = so.fetch("/tags/{tag}/related", tag=tag2) and the rest is Python (e.g. get tag names and make set intersection, if it is what you have in mind). Commented Dec 30, 2013 at 22:32
  • SEAPI is clean, efficient and a breath of fresh air compared to the other StackApps I've struggled with all night! It would be great if it incorporated authentication using requests_oauthlib. Is that already in the works? Commented Dec 30, 2013 at 23:17
  • SEAPI is not under active development. But if you want some changes, why not forking the repository - I would be happy to accept some pull requests. :) Commented Jan 21, 2014 at 18:58
  • Sorry, I am adding this here, but TimStone already deleted the other answer. The API seems to work okay for StackFavorites - stackapps.com/q/2438/12360. so.fetch("/users/{ids}/favorites",ids = [id], order="desc", sort="added", page=1) is what I am using, but it did not work. Commented Jan 21, 2014 at 19:38
  • I did click on the api.stackexchange.com you posted and it didn't respond to order parameter. As the SEAPI has no ambition beyond translating Pythonic queries to StackExchange API, there is little I can do. Maybe the other app uses a different query or takes all favourites (I guess, rarely more than a few thousands) and performs the sorting? I do not know. Commented Jan 22, 2014 at 12:00
  • You are right, that's what I probably need to do. THanks, Commented Jan 24, 2014 at 4:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.