{"id":13729520,"url":"https://github.com/sns-sdks/python-twitter","last_synced_at":"2026-04-10T10:02:39.240Z","repository":{"id":39896353,"uuid":"293502395","full_name":"sns-sdks/python-twitter","owner":"sns-sdks","description":"A simple Python wrapper for Twitter API v2 ✨ 🍰 ✨ ","archived":false,"fork":false,"pushed_at":"2025-11-04T08:40:35.000Z","size":1167,"stargazers_count":249,"open_issues_count":7,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-11-04T09:21:46.180Z","etag":null,"topics":["twitter-api","twitter-api-v2","twitter-sdk","twitter-streaming-api"],"latest_commit_sha":null,"homepage":"https://sns-sdks.github.io/python-twitter/","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/sns-sdks.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-07T10:59:22.000Z","updated_at":"2025-11-04T08:40:21.000Z","dependencies_parsed_at":"2023-11-21T11:45:43.650Z","dependency_job_id":"6bfd4813-3054-4598-b078-68f9e076b89a","html_url":"https://github.com/sns-sdks/python-twitter","commit_stats":{"total_commits":290,"total_committers":5,"mean_commits":58.0,"dds":0.01379310344827589,"last_synced_commit":"c7f2162cdab3a2a6ea5ac8d2b76756125662dd8e"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/sns-sdks/python-twitter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sns-sdks%2Fpython-twitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sns-sdks%2Fpython-twitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sns-sdks%2Fpython-twitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sns-sdks%2Fpython-twitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sns-sdks","download_url":"https://codeload.github.com/sns-sdks/python-twitter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sns-sdks%2Fpython-twitter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31637748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T07:40:12.752Z","status":"ssl_error","status_checked_at":"2026-04-10T07:40:11.664Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["twitter-api","twitter-api-v2","twitter-sdk","twitter-streaming-api"],"created_at":"2024-08-03T02:01:01.688Z","updated_at":"2026-04-10T10:02:39.234Z","avatar_url":"https://github.com/sns-sdks.png","language":"Python","funding_links":[],"categories":["Libraries","Tools"],"sub_categories":["Python"],"readme":"python-twitter\n\nA simple Python wrapper for Twitter API v2 :sparkles: :cake: :sparkles:.\n\n.. image:: https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2\n   :target: https://developer.x.com/en/docs/twitter-api\n   :alt: v2\n\n.. image:: https://github.com/sns-sdks/python-twitter/workflows/Test/badge.svg\n    :target: https://github.com/sns-sdks/python-twitter/actions\n    :alt: Build Status\n\n.. image:: https://codecov.io/gh/sns-sdks/python-twitter/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/sns-sdks/python-twitter\n    :alt: Codecov\n\n.. image:: https://img.shields.io/pypi/v/python-twitter-v2.svg\n    :target: https://pypi.org/project/python-twitter-v2/\n    :alt: PyPI\n\n\n\n============\nIntroduction\n============\n\nTwitter has published new version `Twitter API V2 \u003chttps://x.com/TwitterDev/status/1293593516040269825\u003e`_ for developer at Aug 13, 2020.\n\nThis library provides a service to easily use this new version Twitter API.\n\n=============\nDocumentation\n=============\n\nYou can get all API descriptions `Twitter API v2 Documentation \u003chttps://developer.x.com/en/docs/twitter-api\u003e`_.\n\nDocs for this library on `here \u003chttps://sns-sdks.github.io/python-twitter/\u003e`_\n\n\n==========\nInstalling\n==========\n\nYou can install this library easily by `pypi`:\n\n.. code-block:: shell\n\n    $ pip install python-twitter-v2\n\nCode is hosted at `https://github.com/sns-sdks/python-twitter \u003chttps://github.com/sns-sdks/python-twitter\u003e`_.\n\nCheckout latest development version with:\n\n.. code-block:: shell\n\n    $ git clone https://github.com/sns-sdks/python-twitter.git\n    $ cd python-twitter\n\nInstall dependencies with:\n\n.. code-block:: shell\n\n    $ make env\n\n\nRun tests with:\n\n.. code-block:: shell\n\n    $ make test\n\nRun tests with coverage:\n\n.. code-block:: shell\n\n    $ make cov-term\n    $ make cov-html\n\n=====\nUsing\n=====\n\nThe API is exposed via the ``pytwitter.Api`` class.\n\nNow covers these features:\n\n- Tweets\n    - Tweet lookup\n    - Manage Tweets\n    - Quote Tweets\n    - Retweet Tweets\n    - Timelines\n    - Search Tweets\n    - Tweet counts\n    - Filtered stream\n    - Volume streams\n    - Retweets\n    - Likes\n    - Bookmarks\n    - Hide replies\n\n- Users\n    - User lookup\n    - Follows\n    - Blocks\n    - Mutes\n\n- Usage\n    - Tweets\n\n- Trends\n\n- Spaces\n    - Spaces lookup\n    - Search Spaces\n\n- Direct Messages\n    - Direct Messages lookup\n    - Manage Direct Messages\n\n- Lists\n    - List lookup\n    - Manage lists\n    - List Tweets lookup\n    - List members\n    - List follows\n    - Pinned Lists\n\n- Compliance\n    - Batch compliance\n\n- Media Upload\n    - Media Simple upload\n    - Media Chunked upload\n\n-----------\nINSTANTIATE\n-----------\n\nYou can initialize with an bearer token:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from pytwitter import Api\n    \u003e\u003e\u003e api = Api(bearer_token=\"Your bearer token\")\n\nWith OAuth 1.0A user context token:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api = Api(\n            consumer_key=\"consumer key\",\n            consumer_secret=\"consumer secret\",\n            access_token=\"access token\",\n            access_secret=\"access secret\"\n        )\n\nOr with authorization done by user:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api = Api(consumer_key=\"consumer key\",consumer_secret=\"consumer secret\",oauth_flow=True)\n    # get url for user to authorize\n    \u003e\u003e\u003e api.get_authorize_url()\n    # copy the response url\n    \u003e\u003e\u003e api.generate_access_token(\"https://localhost/?oauth_token=oauth_token\u0026oauth_verifier=oauth_verifier\")\n    {'oauth_token': 'oauth_token',\n     'oauth_token_secret': 'oauth_token_secret',\n     'user_id': '123456',\n     'screen_name': 'screen name'}\n\nTwitter has `announced OAuth 2.0 user authentication support with fine-grained scopes \u003chttps://twittercommunity.com/t/announcing-oauth-2-0-general-availability/163555\u003e`_\n\nNow if you have app with ``OAuth2.0`` client ID. you can do authorize with ``OAuth2``.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api = Api(client_id=\"You client ID\", oauth_flow=True)\n    # get the url and code verifier for user to authorize\n    \u003e\u003e\u003e url, code_verifier, _ = api.get_oauth2_authorize_url()\n    # copy the response url\n    \u003e\u003e\u003e api.generate_oauth2_access_token(\"https://localhost/?state=state\u0026code=code\", code_verifier)\n    {'token_type': 'bearer',\n     'expires_in': 7200,\n     'access_token': 'access_token',\n     'scope': 'users.read tweet.read',\n     'expires_at': 1631775928}\n\n\n------------\nUsers-lookup\n------------\n\nYou can get information about a user or group of users, specified by a user ID or a username.\n\nGet group of users:\n\n.. code-block:: python\n\n    # By ids\n    \u003e\u003e\u003e api.get_users(ids=[\"783214\", \"2244994945\"])\n    Response(data=[User(id='2244994945', name='Twitter Dev', username='TwitterDev'), User(id='783214', name='Twitter', username='Twitter')])\n\n    # By username\n    \u003e\u003e\u003e api.get_users(usernames=\"Twitter,TwitterDev\")\n    Response(data=[User(id='2244994945', name='Twitter Dev', username='TwitterDev'), User(id='783214', name='Twitter', username='Twitter')])\n\nGet single user:\n\n.. code-block:: python\n\n    # By id\n    \u003e\u003e\u003e api.get_user(user_id=\"783214\")\n    Response(data=User(id='783214', name='Twitter', username='Twitter'))\n\n    # By username\n    \u003e\u003e\u003e api.get_user(username=\"Twitter\")\n    Response(data=User(id='783214', name='Twitter', username='Twitter'))\n\nGet user following:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.get_following(user_id=\"2244994945\", max_results=5)\n    Response(data=[User(id='459860328', name='julie✨', username='JulieMendoza206'), User(id='273830767', name='🄿🅄🅂🄷', username='rahul_pushkarna')...])\n\nGet user followers:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.get_followers(user_id=\"2244994945\", max_results=5)\n    Response(data=[User(id='715131097332518912', name='Daniel', username='RGIDaniel'), User(id='1176323137757048832', name='Joyce Wang', username='joycew67')...])\n\n\nYou can follow or unfollow user if you have User context.\n\nfollow user:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.follow_user(user_id=\"123456\", target_user_id=\"654321\")\n    {'data': {'following': True, 'pending_follow': False}}\n\n\nunfollow user:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.unfollow_user(user_id=\"123456\", target_user_id=\"654321\")\n    {'data': {'following': False}}\n\n-------------\nTweets-lookup\n-------------\n\nYou can get information about a tweet or group of tweets by tweet id(s).\n\nGet single tweet:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.get_tweet(\"1354143047324299264\", expansions=[\"attachments.media_keys\"], media_fields=[\"type\",\"duration_ms\"])\n    Response(data=Tweet(id=1354143047324299264, text=Academics are one of the biggest groups using...))\n\nGet group of tweets:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api.get_tweets([\"1261326399320715264\",\"1278347468690915330\"],expansions=\"author_id\",tweet_fields=[\"created_at\"], user_fields=[\"username\",\"verified\"])\n    Response(data=[Tweet(id=1261326399320715264, text=Tune in to the @MongoDB @Twitch stream...), Tweet(id=1278347468690915330, text=Good news and bad news: 2020 is half over)])\n\n-------------\nStreaming API\n-------------\n\nFor Streaming, this provide `StreamApi` independent. Same as main `Api`, You need initialize it first.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from pytwitter import StreamApi\n    \u003e\u003e\u003e stream_api = StreamApi(bearer_token=\"bearer token\")\n    # or use consumer key and secret\n    \u003e\u003e\u003e stream_api = StreamApi(consumer_key=\"consumer key\", consumer_secret=\"consumer secret\")\n\n\nFor Sample Stream tweets, you can use the `sample_stream` function to build a connection.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e stream_api.sample_stream()\n\nFor Filtered Stream, you can create rules.\n\nGet your current rules.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e stream_api.get_rules()\n    Response(data=[StreamRule(id='1369580714056843266', value='twitter api ')])\n\nDelete your rules.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e stream_api.manage_rules(rules={\"delete\": {\"ids\": [\"1369580714056843266\"]}})\n    Response(data=[])\n\nAdd new rules. If you set `dry_run` to True, will only validate rules, and not create them.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e np = {\n            \"add\": [\n                {\"value\": \"cat has:media\", \"tag\": \"cats with media\"},\n                {\"value\": \"cat has:media -grumpy\", \"tag\": \"happy cats with media\"}\n            ]\n         }\n    \u003e\u003e\u003e stream_api.manage_rules(rules=np, dry_run=True)\n    Response(data=[StreamRule(id='1370406958721732610', value='cat has:media -grumpy'), StreamRule(id='1370406958721732609', value='cat has:media')])\n\nThen you can use `search_stream` to get tweets matching your rules.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e stream_api.search_stream()\n\n\nYou can go to the `Example folder \u003cexamples\u003e`_ for streaming examples.\n\n====\nTODO\n====\n\n- More Api waiting twitter\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsns-sdks%2Fpython-twitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsns-sdks%2Fpython-twitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsns-sdks%2Fpython-twitter/lists"}