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
with TwitterApiClient.from_oauth2_app_env() as twitter_client:
response_body = (
twitter_client.chain()
.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
twitter_api_py-0.4.5.tar.gz
(63.6 kB
view hashes)
Built Distribution
twitter_api_py-0.4.5-py3-none-any.whl
(165.5 kB
view hashes)
Close
Hashes for twitter_api_py-0.4.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 114171a18f649752b13be40cdafe4f4f8ed8d3420523dd2960bcd825c7c303a2 |
|
MD5 | 0f5d1eb5c1ede0812acad07e6fa7b980 |
|
BLAKE2b-256 | 61c4d5991e3306ae2cc897f3207fb419c5d321feca8bd4d4d7968bbaa48d4684 |