twitter-client-py


Nametwitter-client-py JSON
Version 0.3.3 PyPI version JSON
download
home_pageNone
SummaryPython client for interacting with Twitter V2 API available at https://rapidapi.com/datarise-datarise-default/api/twitter-x
upload_time2024-06-14 17:14:49
maintainerNone
docs_urlNone
authorOmar MHAIMDAT
requires_python>=3.7
license(The MIT License) Copyright (c) 2017 Sergey Potapov <blake131313@gmail.com> Copyright (c) 2014 Titus Wormer <tituswormer@gmail.com> Copyright (c) 2008 Kent S Johnson Copyright (c) 2006 Jacob R Rideout <kde@jacobrideout.net> Copyright (c) 2004 Maciej Ceglowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords twitter api client v2
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Unofficial Twitter Python Client for [Twitter/X Rapid API](https://rapidapi.com/datarise-datarise-default/api/twitter-x)

<!-- Add badges for CI/CD, Code Coverage, PyPI, etc. -->
[![PyPI](https://img.shields.io/pypi/v/twitter-client-py)](https://pypi.org/project/twitter-client-py/)
![Build Status](https://github.com/datarise-org-ma/twitter-client-py/actions/workflows/ci.yaml/badge.svg)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/twitter-client-py)](https://pypi.org/project/twitter-client-py/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/twitter-client-py)](https://pypi.org/project/twitter-client-py/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Table of Contents

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
  - [Simple Example](#simple-example)
  - [Advanced Example](#advanced-example)
  - [Asynchronous Example](#asynchronous-example)
  - [Check Rate Limit](#check-rate-limit)
- [License](#license)
- [Contact](#contact)

## Overview

This is a Python client for interacting with the Twitter V2 API via the [RapidAPI platform](https://rapidapi.com/datarise-datarise-default/api/twitter-x). The library provides synchronous, asynchronous, and multi-threaded capabilities for retrieving Twitter user details and tweets.


## Installation

```bash
pip install -U twitter-client-py
```

## Usage

### Simple Example

The following example demonstrates how to use the library to get user details and tweets.

```python
from os import getenv
import json

from twitter_client_py import TwitterClient

api_key = getenv('API_KEY')

client = TwitterClient(api_key=api_key, timeout=20, verbose=True)

# Get user details by username
user_details  = client.user_details(username='elonmusk')
if user_details.status_code == 200:
    print(json.dumps(user_details.json(), indent=4))

# Get user details by id
user_details  = client.user_details(user_id='44196397')
if user_details.status_code == 200:
    print(json.dumps(user_details.json(), indent=4))

# Get user tweets by username
user_tweets = client.user_tweets(username='elonmusk')
if user_tweets.status_code == 200:
    print(json.dumps(user_tweets.json(), indent=4))
    
# Get user tweets by id
user_tweets = client.user_tweets(user_id='44196397')
if user_tweets.status_code == 200:
    print(json.dumps(user_tweets.json(), indent=4))
```

### Advanced Example

*TwitterClient* class is thread-safe, so you can use it in a multi-threaded environment.

```python
from os import getenv
import json
from concurrent.futures import ThreadPoolExecutor

from twitter_client_py import TwitterClient

api_key = getenv('API_KEY')

client = TwitterClient(api_key=api_key, timeout=20, verbose=True)

users = ['elonmusk', 'BillGates', 'JeffBezos', 'tim_cook', 'satyanadella']

def get_user_details(username):
    user_details  = client.user_details(username=username)
    if user_details.status_code == 200:
        return user_details.json()

with ThreadPoolExecutor(max_workers=5) as executor:
    results = executor.map(get_user_details, users)

for result in results:
    print(json.dumps(result, indent=4))
```

### Asynchronous Example

The library also supports asynchronous requests using `aiohttp` with `asyncio`

```python
from os import getenv
import asyncio
import json

from twitter_client_py import AsyncTwitterClient

api_key = getenv('API_KEY') # X-RapidAPI-Key

client = AsyncTwitterClient(api_key=api_key, timeout=20, verbose=True)

users = ['elonmusk', 'BillGates', 'JeffBezos', 'tim_cook', 'satyanadella']

async def get_user_details(username):
    user_details  = await client.user_details(username=username)
    if user_details.status == 200:
        return user_details.json()

async def main():
    tasks = [get_user_details(username) for username in users]
    results = await asyncio.gather(*tasks)
    for result in results:
        print(json.dumps(await result, indent=4))

await main()
```

### Check Rate Limit

You can check the rate limit of the API using the `rate_limit` method. TwitterClient and AsyncTwitterClient have a `rate_limit` attribute that returns the rate limit details. It's updated after each request.

```python
rate_limit = client.rate_limit
print(f"Limit: {rate_limit.limit}")
print(f"Remaining requests: {rate_limit.remaining}")
print(f"Reset time: {rate_limit.reset}")
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contact

If you have any questions or feedback, feel free to reach out to us at contact [at] datarise [dot] ma.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "twitter-client-py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "twitter, api, client, v2",
    "author": "Omar MHAIMDAT",
    "author_email": "Omar MHAIMDAT <omarmhaimdat@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8e/84/1e3498032e1594fdc69fab68a5c60ef0d49e8b1a3c312c44b98bae491dd4/twitter_client_py-0.3.3.tar.gz",
    "platform": null,
    "description": "# Unofficial Twitter Python Client for [Twitter/X Rapid API](https://rapidapi.com/datarise-datarise-default/api/twitter-x)\n\n<!-- Add badges for CI/CD, Code Coverage, PyPI, etc. -->\n[![PyPI](https://img.shields.io/pypi/v/twitter-client-py)](https://pypi.org/project/twitter-client-py/)\n![Build Status](https://github.com/datarise-org-ma/twitter-client-py/actions/workflows/ci.yaml/badge.svg)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/twitter-client-py)](https://pypi.org/project/twitter-client-py/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/twitter-client-py)](https://pypi.org/project/twitter-client-py/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Simple Example](#simple-example)\n  - [Advanced Example](#advanced-example)\n  - [Asynchronous Example](#asynchronous-example)\n  - [Check Rate Limit](#check-rate-limit)\n- [License](#license)\n- [Contact](#contact)\n\n## Overview\n\nThis is a Python client for interacting with the Twitter V2 API via the [RapidAPI platform](https://rapidapi.com/datarise-datarise-default/api/twitter-x). The library provides synchronous, asynchronous, and multi-threaded capabilities for retrieving Twitter user details and tweets.\n\n\n## Installation\n\n```bash\npip install -U twitter-client-py\n```\n\n## Usage\n\n### Simple Example\n\nThe following example demonstrates how to use the library to get user details and tweets.\n\n```python\nfrom os import getenv\nimport json\n\nfrom twitter_client_py import TwitterClient\n\napi_key = getenv('API_KEY')\n\nclient = TwitterClient(api_key=api_key, timeout=20, verbose=True)\n\n# Get user details by username\nuser_details  = client.user_details(username='elonmusk')\nif user_details.status_code == 200:\n    print(json.dumps(user_details.json(), indent=4))\n\n# Get user details by id\nuser_details  = client.user_details(user_id='44196397')\nif user_details.status_code == 200:\n    print(json.dumps(user_details.json(), indent=4))\n\n# Get user tweets by username\nuser_tweets = client.user_tweets(username='elonmusk')\nif user_tweets.status_code == 200:\n    print(json.dumps(user_tweets.json(), indent=4))\n    \n# Get user tweets by id\nuser_tweets = client.user_tweets(user_id='44196397')\nif user_tweets.status_code == 200:\n    print(json.dumps(user_tweets.json(), indent=4))\n```\n\n### Advanced Example\n\n*TwitterClient* class is thread-safe, so you can use it in a multi-threaded environment.\n\n```python\nfrom os import getenv\nimport json\nfrom concurrent.futures import ThreadPoolExecutor\n\nfrom twitter_client_py import TwitterClient\n\napi_key = getenv('API_KEY')\n\nclient = TwitterClient(api_key=api_key, timeout=20, verbose=True)\n\nusers = ['elonmusk', 'BillGates', 'JeffBezos', 'tim_cook', 'satyanadella']\n\ndef get_user_details(username):\n    user_details  = client.user_details(username=username)\n    if user_details.status_code == 200:\n        return user_details.json()\n\nwith ThreadPoolExecutor(max_workers=5) as executor:\n    results = executor.map(get_user_details, users)\n\nfor result in results:\n    print(json.dumps(result, indent=4))\n```\n\n### Asynchronous Example\n\nThe library also supports asynchronous requests using `aiohttp` with `asyncio`\n\n```python\nfrom os import getenv\nimport asyncio\nimport json\n\nfrom twitter_client_py import AsyncTwitterClient\n\napi_key = getenv('API_KEY') # X-RapidAPI-Key\n\nclient = AsyncTwitterClient(api_key=api_key, timeout=20, verbose=True)\n\nusers = ['elonmusk', 'BillGates', 'JeffBezos', 'tim_cook', 'satyanadella']\n\nasync def get_user_details(username):\n    user_details  = await client.user_details(username=username)\n    if user_details.status == 200:\n        return user_details.json()\n\nasync def main():\n    tasks = [get_user_details(username) for username in users]\n    results = await asyncio.gather(*tasks)\n    for result in results:\n        print(json.dumps(await result, indent=4))\n\nawait main()\n```\n\n### Check Rate Limit\n\nYou can check the rate limit of the API using the `rate_limit` method. TwitterClient and AsyncTwitterClient have a `rate_limit` attribute that returns the rate limit details. It's updated after each request.\n\n```python\nrate_limit = client.rate_limit\nprint(f\"Limit: {rate_limit.limit}\")\nprint(f\"Remaining requests: {rate_limit.remaining}\")\nprint(f\"Reset time: {rate_limit.reset}\")\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contact\n\nIf you have any questions or feedback, feel free to reach out to us at contact [at] datarise [dot] ma.\n",
    "bugtrack_url": null,
    "license": "(The MIT License)  Copyright (c) 2017 Sergey Potapov <blake131313@gmail.com> Copyright (c) 2014 Titus Wormer <tituswormer@gmail.com> Copyright (c) 2008 Kent S Johnson Copyright (c) 2006 Jacob R Rideout <kde@jacobrideout.net> Copyright (c) 2004 Maciej Ceglowski  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Python client for interacting with Twitter V2 API available at https://rapidapi.com/datarise-datarise-default/api/twitter-x",
    "version": "0.3.3",
    "project_urls": {
        "documentation": "https://github.com/datarise-org-ma/twitter-client-py/blob/main/README.md",
        "homepage": "https://github.com/datarise-org-ma/twitter-client-py",
        "issues": "https://github.com/datarise-org-ma/twitter-client-py/issues",
        "repository": "https://github.com/datarise-org-ma/twitter-client-py"
    },
    "split_keywords": [
        "twitter",
        " api",
        " client",
        " v2"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06095e8efe5baa200eff85413905b807065fa0c073f337907ee9b9ca51c649f9",
                "md5": "7d2e3e3bd250e36ab36bf17855488f87",
                "sha256": "e00ee409e1b3527b51c03cd29dea79d32378c53cd2d1113e014ae815b83d49eb"
            },
            "downloads": -1,
            "filename": "twitter_client_py-0.3.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d2e3e3bd250e36ab36bf17855488f87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 11236,
            "upload_time": "2024-06-14T17:14:32",
            "upload_time_iso_8601": "2024-06-14T17:14:32.472437Z",
            "url": "https://files.pythonhosted.org/packages/06/09/5e8efe5baa200eff85413905b807065fa0c073f337907ee9b9ca51c649f9/twitter_client_py-0.3.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e841e3498032e1594fdc69fab68a5c60ef0d49e8b1a3c312c44b98bae491dd4",
                "md5": "ab93befd32eaaf67a7fe5f0e8a53e780",
                "sha256": "fa05037b8605a68112b914778f79988f4386e2a2acce386eaedbed58c737e194"
            },
            "downloads": -1,
            "filename": "twitter_client_py-0.3.3.tar.gz",
            "has_sig": false,
            "md5_digest": "ab93befd32eaaf67a7fe5f0e8a53e780",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10787,
            "upload_time": "2024-06-14T17:14:49",
            "upload_time_iso_8601": "2024-06-14T17:14:49.589417Z",
            "url": "https://files.pythonhosted.org/packages/8e/84/1e3498032e1594fdc69fab68a5c60ef0d49e8b1a3c312c44b98bae491dd4/twitter_client_py-0.3.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-14 17:14:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "datarise-org-ma",
    "github_project": "twitter-client-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "twitter-client-py"
}
        
Elapsed time: 0.73153s