• This repository has been archived on 08/Aug/2024
  • Stars
    star
    3,414
  • Rank 13,101 (Top 0.3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python wrapper around the Twitter API.

Python Twitter

A Python wrapper around the Twitter API.

By the Python-Twitter Developers

Downloads Documentation Status Circle CI Codecov Requirements Status Dependency Status

Introduction

This library provides a pure Python interface for the Twitter API. It works with Python versions from 2.7+ and Python 3.

Twitter provides a service that allows people to connect via the web, IM, and SMS. Twitter exposes a web services API and this library is intended to make it even easier for Python programmers to use.

Installing

You can install python-twitter using:

$ pip install python-twitter

If you are using python-twitter on Google App Engine, see more information about including 3rd party vendor library dependencies in your App Engine project.

Getting the code

The code is hosted at https://github.com/bear/python-twitter

Check out the latest development version anonymously with:

$ git clone git://github.com/bear/python-twitter.git
$ cd python-twitter

To install dependencies, run either:

$ make dev

or:

$ pip install -Ur requirements.testing.txt
$ pip install -Ur requirements.txt

Note that `make dev` will install into your local `pyenv` all of the versions needed for test runs using `tox`.

To install the minimal dependencies for production use (i.e., what is installed with pip install python-twitter) run:

$ make env

or:

$ pip install -Ur requirements.txt

Running Tests

The test suite can be run against a single Python version or against a range of them depending on which Makefile target you select.

Note that tests require `pip install pytest` and optionally `pip install pytest-cov` (these are included if you have installed dependencies from `requirements.testing.txt`)

To run the unit tests with a single Python version:

$ make test

to also run code coverage:

$ make coverage

To run the unit tests against a set of Python versions:

$ make tox

Documentation

View the latest python-twitter documentation at https://python-twitter.readthedocs.io. You can view Twitter's API documentation at: https://dev.twitter.com/overview/documentation

Using

The library provides a Python wrapper around the Twitter API and the Twitter data model. To get started, check out the examples in the examples/ folder or read the documentation at https://python-twitter.readthedocs.io which contains information about getting your authentication keys from Twitter and using the library.

Using with Django

Additional template tags that expand tweet urls and urlize tweet text. See the django template tags available for use with python-twitter: https://github.com/radzhome/python-twitter-django-tags

Models

The library utilizes models to represent various data structures returned by Twitter. Those models are:
  • twitter.Category
  • twitter.DirectMessage
  • twitter.Hashtag
  • twitter.List
  • twitter.Media
  • twitter.Status
  • twitter.Trend
  • twitter.Url
  • twitter.User
  • twitter.UserStatus

To read the documentation for any of these models, run:

$ pydoc twitter.[model]

API

The API is exposed via the twitter.Api class.

The python-twitter requires the use of OAuth keys for nearly all operations. As of Twitter's API v1.1, authentication is required for most, if not all, endpoints. Therefore, you will need to register an app with Twitter in order to use this library. Please see the "Getting Started" guide on https://python-twitter.readthedocs.io for more information.

To generate an Access Token you have to pick what type of access your application requires and then do one of the following:

For full details see the Twitter OAuth Overview

To create an instance of the twitter.Api with login credentials (Twitter now requires an OAuth Access Token for all API calls):

>>> import twitter
>>> api = twitter.Api(consumer_key='consumer_key',
                      consumer_secret='consumer_secret',
                      access_token_key='access_token',
                      access_token_secret='access_token_secret')

To see if your credentials are successful:

>>> print(api.VerifyCredentials())
{"id": 16133, "location": "Philadelphia", "name": "bear"}

NOTE: much more than the small sample given here will print

To fetch a single user's public status messages, where user is a Twitter user's screen name:

>>> statuses = api.GetUserTimeline(screen_name=user)
>>> print([s.text for s in statuses])

To fetch a list of a user's friends:

>>> users = api.GetFriends()
>>> print([u.name for u in users])

To post a Twitter status message:

>>> status = api.PostUpdate('I love python-twitter!')
>>> print(status.text)
I love python-twitter!

There are many more API methods, to read the full API documentation either check out the documentation on readthedocs, build the documentation locally with:

$ make docs

or check out the inline documentation with:

$ pydoc twitter.Api

Todo

Patches, pull requests, and bug reports are welcome, just please keep the style consistent with the original source.

In particular, having more example scripts would be a huge help. If you have a program that uses python-twitter and would like a link in the documentation, submit a pull request against twitter/doc/getting_started.rst and add your program at the bottom.

The twitter.Status and twitter.User classes are going to be hard to keep in sync with the API if the API changes. More of the code could probably be written with introspection.

The twitter.Status and twitter.User classes could perform more validation on the property setters.

More Information

Please visit the google group for more discussion.

Contributors

Originally two libraries by DeWitt Clinton and Mike Taylor which were then merged into python-twitter.

Now it's a full-on open source project with many contributors over time. See AUTHORS.rst for the complete list.

License

Copyright 2007-2016 The Python-Twitter Developers

Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

parsedatetime

Parse human-readable date/time strings
Python
694
star
2

s3scan

scan s3 buckets for security issues
Python
83
star
3

ronkyuu

่ซ–ๅŠ ronkyuu - mention, reference to, touching upon
HTML
42
star
4

kaku-deprecated

ๆ›ธใ- to write
Makefile
25
star
5

python-indieweb

Example Flask App to test Indieweb features
Python
19
star
6

indie-stats

Indieweb site crawler and MF2 data collection tool
Python
11
star
7

bearlib-deprecated

A Python module of items that I use often in projects and got tired of copying from project to project
Python
10
star
8

ninka-deprecated

่ชๅฏ - ninka - permission, license, to approve, permit
Python
9
star
9

tenki-deprecated

ๅคฉๆฐ— weather
Python
9
star
10

kenkou-deprecated

ๅฅๅบท - health -- small python tool to check that an http resource is alive
Python
6
star
11

iptable-tools

bash script to ease iptable rule handling
Shell
4
star
12

babble-deprecated

yes, another python bot - this one is geared to new coders
Python
4
star
13

relengbot

RelEng Bot
Python
3
star
14

palala

taming the river of news
Python
3
star
15

github-archive

Create a tarball of the cloned repo and all issues
Python
2
star
16

chef-cookbook-inspircd

Ruby
2
star
17

hakkan-deprecated

็™บๅˆŠ hakkan - to publish
Makefile
2
star
18

PythonFlaskTesting

Resources and Notes from my Python Testing talk
2
star
19

kagami-deprecated

tool to ship logstash events to a remote logstash server using zeromq
Python
2
star
20

kosu-deprecated

ใ“ใ™ - to filter, to strain
Clojure
2
star
21

dainin-deprecated

ไปฃไบบ dainin -- a proxy, substitute, deputy or agent - a tool to manage events and actions on my behalf
Python
2
star
22

chiru_js-deprecated

scatter tasks/jobs to workers
JavaScript
1
star
23

indiewebnews-deprecated

IndieWeb News aggregator
Python
1
star
24

danron-deprecated

่ซ‡่ซ– danron - discussion
Makefile
1
star
25

rsinfo

Rackspace Server Info
Python
1
star
26

OpsNotes-deprecated

Collection of notes and links relating to Ops
Python
1
star
27

bear-deprecated

tools, notes and .dot files
Shell
1
star
28

kyaku-deprecated

Automated tool to manage social media events using good old mailing list tech
Python
1
star