{"id":13454132,"url":"https://github.com/ryanmcgrath/twython","last_synced_at":"2025-05-14T07:08:05.392Z","repository":{"id":536514,"uuid":"165892","full_name":"ryanmcgrath/twython","owner":"ryanmcgrath","description":"Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs.","archived":false,"fork":false,"pushed_at":"2022-07-30T23:24:29.000Z","size":2801,"stargazers_count":1857,"open_issues_count":27,"forks_count":396,"subscribers_count":102,"default_branch":"master","last_synced_at":"2025-05-14T02:41:55.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://stackoverflow.com/questions/tagged/twython","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanmcgrath.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-04-02T05:01:31.000Z","updated_at":"2025-05-11T05:39:53.000Z","dependencies_parsed_at":"2022-08-16T10:30:31.227Z","dependency_job_id":null,"html_url":"https://github.com/ryanmcgrath/twython","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmcgrath%2Ftwython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmcgrath%2Ftwython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmcgrath%2Ftwython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmcgrath%2Ftwython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanmcgrath","download_url":"https://codeload.github.com/ryanmcgrath/twython/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092652,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:51.152Z","updated_at":"2025-05-14T07:08:05.366Z","avatar_url":"https://github.com/ryanmcgrath.png","language":"Python","readme":"# Twython\n\n\u003ca href=\"https://pypi.python.org/pypi/twython\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/twython.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.python.org/pypi/twython\"\u003e\u003cimg src=\"https://img.shields.io/pypi/dw/twython.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/ryanmcgrath/twython\"\u003e\u003cimg src=\"https://img.shields.io/travis/ryanmcgrath/twython.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/r/ryanmcgrath/twython?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/coveralls/ryanmcgrath/twython/master.svg?style=flat-square\"\u003e\u003c/a\u003e\n\n`Twython` is a Python library providing an easy way to access Twitter data. Supports Python 3. It's been battle tested by companies, educational institutions and individuals alike. Try it today!\n\n**Note**: As of Twython 3.7.0, there's a general call for maintainers put out. If you find the project useful and want to help out, reach out to Ryan with the info from the bottom of this README. Great open source project to get your feet wet with!\n\n## Features\n- Query data for:\n    - User information\n    - Twitter lists\n    - Timelines\n    - Direct Messages\n    - and anything found in [the docs](https://developer.twitter.com/en/docs)\n- Image Uploading:\n    - Update user status with an image\n    - Change user avatar\n    - Change user background image\n    - Change user banner image\n- OAuth 2 Application Only (read-only) Support\n- Support for Twitter's Streaming API\n- Seamless Python 3 support!\n\n## Installation\nInstall Twython via pip:\n\n```bash\n$ pip install twython\n```\n\nIf you're on a legacy project that needs Python 2.7 support, you can install the last version of Twython that supported 2.7:\n\n```\npip install twython==3.7.0`\n```\n\nOr, if you want the code that is currently on GitHub:\n\n```bash\ngit clone git://github.com/ryanmcgrath/twython.git\ncd twython\npython setup.py install\n```\n\n## Documentation\nDocumentation is available at https://twython.readthedocs.io/en/latest/\n\n## Starting Out\nFirst, you'll want to head over to https://apps.twitter.com and register an application!\n\nAfter you register, grab your applications `Consumer Key` and `Consumer Secret` from the application details tab.\n\nThe most common type of authentication is Twitter user authentication using OAuth 1. If you're a web app planning to have users sign up with their Twitter account and interact with their timelines, updating their status, and stuff like that this **is** the authentication for you!\n\nFirst, you'll want to import Twython\n\n```python\nfrom twython import Twython\n```\n\n## Obtain Authorization URL\nNow, you'll want to create a Twython instance with your `Consumer Key` and `Consumer Secret`:\n\n- Only pass *callback_url* to *get_authentication_tokens* if your application is a Web Application\n- Desktop and Mobile Applications **do not** require a callback_url\n\n```python\nAPP_KEY = 'YOUR_APP_KEY'\nAPP_SECRET = 'YOUR_APP_SECRET'\n\ntwitter = Twython(APP_KEY, APP_SECRET)\n\nauth = twitter.get_authentication_tokens(callback_url='http://mysite.com/callback')\n```\n\nFrom the `auth` variable, save the `oauth_token` and `oauth_token_secret` for later use (these are not the final auth tokens). In Django or other web frameworks, you might want to store it to a session variable\n\n```python\nOAUTH_TOKEN = auth['oauth_token']\nOAUTH_TOKEN_SECRET = auth['oauth_token_secret']\n```\n\nSend the user to the authentication url, you can obtain it by accessing\n\n```python\nauth['auth_url']\n```\n\n## Handling the Callback\nIf your application is a Desktop or Mobile Application *oauth_verifier* will be the PIN code\n\nAfter they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in `get_authentication_tokens`.\n\nYou'll want to extract the `oauth_verifier` from the url.\n\nDjango example:\n\n```python\noauth_verifier = request.GET['oauth_verifier']\n```\n\nNow that you have the `oauth_verifier` stored to a variable, you'll want to create a new instance of Twython and grab the final user tokens\n\n```python\ntwitter = Twython(\n    APP_KEY, APP_SECRET,\n    OAUTH_TOKEN, OAUTH_TOKEN_SECRET\n)\n\nfinal_step = twitter.get_authorized_tokens(oauth_verifier)\n```\n\nOnce you have the final user tokens, store them in a database for later use::\n\n```python\n    OAUTH_TOKEN = final_step['oauth_token']\n    OAUTH_TOKEN_SECRET = final_step['oauth_token_secret']\n```\n\nFor OAuth 2 (Application Only, read-only) authentication, see [our documentation](https://twython.readthedocs.io/en/latest/usage/starting_out.html#oauth-2-application-authentication).\n\n## Dynamic Function Arguments\nKeyword arguments to functions are mapped to the functions available for each endpoint in the Twitter API docs. Doing this allows us to be incredibly flexible in querying the Twitter API, so changes to the API aren't held up from you using them by this library.\n\nBasic Usage\n-----------\n\n**Function definitions (i.e. get_home_timeline()) can be found by reading over twython/endpoints.py**\n\nCreate a Twython instance with your application keys and the users OAuth tokens\n\n```python\nfrom twython import Twython\ntwitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)\n```\n\n## Authenticated Users Home Timeline\n```python\ntwitter.get_home_timeline()\n```\n\n## Updating Status\nThis method makes use of dynamic arguments, [read more about them](https://twython.readthedocs.io/en/latest/usage/starting_out.html#dynamic-function-arguments).\n\n```python\ntwitter.update_status(status='See how easy using Twython is!')\n```\n\n## Advanced Usage\n- [Advanced Twython Usage](https://twython.readthedocs.io/en/latest/usage/advanced_usage.html)\n- [Streaming with Twython](https://twython.readthedocs.io/en/latest/usage/streaming_api.html)\n\n\n## Questions, Comments, etc?\nMy hope is that Twython is so simple that you'd never *have* to ask any questions, but if you feel the need to contact me for this (or other) reasons, you can hit me up at ryan@venodesigns.net.\n\nOr if I'm to busy to answer, feel free to ping mikeh@ydekproductions.com as well.\n\nFollow us on Twitter:\n\n- [@ryanmcgrath](https://twitter.com/ryanmcgrath)\n- [@mikehelmick](https://twitter.com/mikehelmick)\n\n## Want to help?\nTwython is useful, but ultimately only as useful as the people using it (say that ten times fast!). If you'd like to help, write example code, contribute patches, document things on the wiki, tweet about it. Your help is always appreciated!\n","funding_links":[],"categories":["Python","Third-party APIs","资源列表","第三方api","Tools","常用 Python 工具","第三方 API","Third-party APIs [🔝](#readme)","Awesome Python"],"sub_categories":["第三方 API","Third-party APIs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmcgrath%2Ftwython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanmcgrath%2Ftwython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmcgrath%2Ftwython/lists"}