Twitter API Client by Typed Python.
Project description
✨✨ Twitter API Client by Typed Python ✨✨
Install
pip install twitter_api_py
Features
- Fully type annotated.
- OAuth1 / OAuth2 support.
- Sync / Async Client support.
- Mock Client support.
Usage
The simplest way to use the library is as follows:
from twitter_api import TwitterApiClient
response_body = (
TwitterApiClient.from_oauth2_app_env()
.request("https://api.twitter.com/2/tweets")
.get({
"ids": "1460323737035677698",
"expansions": ["referenced_tweets.id"]
})
)
As a characteristic feature of the library, it explicitly prompts the user to write the Endpoint URL, which makes it clear from the source code which Twitter API is being called.
Test Code
A mock client is provided by the library to simplify the writing of test code.
This client has the same interface as TwitterApiClient
/TwitterApiAsyncClient
, and also provides methods (inject_*_response_body
) for injecting test data.
from twitter_api import TwitterApiClient, TwitterApiMockClient
def your_logic(twitter_client: TwitterApiClient):
...
def test_your_logic():
twitter_client = (
TwitterApiMockClient.from_oauth2_app_env()
.inject_post_response_body("https://api.twitter.com/2/tweets", post_response_body)
.inject_get_response_body("https://api.twitter.com/2/tweets/:id", get_response_body)
.inject_delete_response_body("https://api.twitter.com/2/tweets", delete_response_body)
)
assert your_logic(twitter_client) is True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file twitter_api_py-0.9.0.tar.gz
.
File metadata
- Download URL: twitter_api_py-0.9.0.tar.gz
- Upload date:
- Size: 63.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1039-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 637e8af65870d9c3fd62fca472c5bf916bbf6fce6b295cd8d9ba62c02fcdb80c |
|
MD5 | 99c77f4b18e45a543a93208103c5b20c |
|
BLAKE2b-256 | 3aa89f48fa961dfe3ead6ce3776969f35b5722b6bb808a37eb154f60f0b57186 |
File details
Details for the file twitter_api_py-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: twitter_api_py-0.9.0-py3-none-any.whl
- Upload date:
- Size: 169.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1039-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de6876f89e4fb9278727505e2eac74cbeb063560ac521d5964c8bd7d158e1681 |
|
MD5 | 31e24503cfb08f940e64ae21a1c41085 |
|
BLAKE2b-256 | 47756a763b0baeba083ed717d97cffef75545da13d2bdc8b9bd1be67feea6ba3 |