TwitterTweetLoader#

class langchain_community.document_loaders.twitter.TwitterTweetLoader(auth_handler: OAuthHandler | OAuth2BearerHandler, twitter_users: Sequence[str], number_tweets: int | None = 100)[source]#

Load Twitter tweets.

Read tweets of the user’s Twitter handle.

First you need to go to https://developer.twitter.com/en/docs/twitter-api /getting-started/getting-access-to-the-twitter-api to get your token. And create a v2 version of the app.

Methods

__init__(auth_handler,Β twitter_users[,Β ...])

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

from_bearer_token(oauth2_bearer_token,Β ...)

Create a TwitterTweetLoader from OAuth2 bearer token.

from_secrets(access_token,Β ...[,Β number_tweets])

Create a TwitterTweetLoader from access tokens and secrets.

lazy_load()

A lazy loader for Documents.

load()

Load tweets.

load_and_split([text_splitter])

Load Documents and split into chunks.

Parameters:
  • auth_handler (Union[OAuthHandler, OAuth2BearerHandler]) –

  • twitter_users (Sequence[str]) –

  • number_tweets (Optional[int]) –

__init__(auth_handler: OAuthHandler | OAuth2BearerHandler, twitter_users: Sequence[str], number_tweets: int | None = 100)[source]#
Parameters:
  • auth_handler (Union[OAuthHandler, OAuth2BearerHandler]) –

  • twitter_users (Sequence[str]) –

  • number_tweets (Optional[int]) –

async alazy_load() β†’ AsyncIterator[Document]#

A lazy loader for Documents.

Return type:

AsyncIterator[Document]

async aload() β†’ List[Document]#

Load data into Document objects.

Return type:

List[Document]

classmethod from_bearer_token(oauth2_bearer_token: str, twitter_users: Sequence[str], number_tweets: int | None = 100) β†’ TwitterTweetLoader[source]#

Create a TwitterTweetLoader from OAuth2 bearer token.

Parameters:
  • oauth2_bearer_token (str) –

  • twitter_users (Sequence[str]) –

  • number_tweets (int | None) –

Return type:

TwitterTweetLoader

classmethod from_secrets(access_token: str, access_token_secret: str, consumer_key: str, consumer_secret: str, twitter_users: Sequence[str], number_tweets: int | None = 100) β†’ TwitterTweetLoader[source]#

Create a TwitterTweetLoader from access tokens and secrets.

Parameters:
  • access_token (str) –

  • access_token_secret (str) –

  • consumer_key (str) –

  • consumer_secret (str) –

  • twitter_users (Sequence[str]) –

  • number_tweets (int | None) –

Return type:

TwitterTweetLoader

lazy_load() β†’ Iterator[Document]#

A lazy loader for Documents.

Return type:

Iterator[Document]

load() β†’ List[Document][source]#

Load tweets.

Return type:

List[Document]

load_and_split(text_splitter: TextSplitter | None = None) β†’ List[Document]#

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters:

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns:

List of Documents.

Return type:

List[Document]

Examples using TwitterTweetLoader