Skip to main content

TA-X-AGENT: X (Twitter) Agent Package

A Python package for interacting with X (Twitter) platform using AI agents. This package provides a simple and intuitive interface to perform various Twitter operations like posting, liking, retweeting, and retrieving data.

Features

  • 🤖 AI-powered X (Twitter) interactions
  • 📝 Create and post content
  • ❤️ Like and unlike posts
  • 🔄 Retweet posts
  • 📊 Get trending topics
  • 👤 Get user details and tweet information
  • 🔧 Easy configuration and setup
  • 🚀 Ready for PyPI distribution

Quick Start

Installation

pip install ta-x-agent

Basic Usage

import asyncio
from ta_x import setup, XAgent

async def main():
    # Setup authentication
    setup(
        x_auth_token="your_x_auth_token_here",
        x_ct0="your_x_ct0_token_here", 
        openai_api_key="your_openai_api_key_here",
        rapid_api_key="your_rapid_api_key_here"
    )
    
    # Create agent instance
    agent = XAgent()
    
    # Use the agent
    result = await agent.run("Post this: Hello X world!")
    print(result)

asyncio.run(main())

Import Syntax

The package supports the exact import syntax you wanted:

from ta_x import XAgent
agent = XAgent()
agent.run(user_prompt=" ")

Available Operations

1. Create Posts

await agent.run("Post this: Hello X world!")
await agent.run("Create a post about AI and social media")

2. Like Posts

await agent.run("Like the latest post")
await agent.run("Like the latest post of elonmusk")
await agent.run("Like the second latest post of elonmusk")

3. Unlike Posts

await agent.run("Unlike the latest post")
await agent.run("Unlike the latest post of elonmusk")

4. Retweet Posts

await agent.run("Retweet the latest post")
await agent.run("Retweet the latest post of elonmusk")

5. Get Trends

await agent.run("What's trending on X?")
await agent.run("Show trends")

6. Get User Details

await agent.run("Get user details for elonmusk")
await agent.run("Show user info for elonmusk")

7. Get Tweet Details

await agent.run("Get tweet details for 123456789")

Authentication Setup

Method 1: Using setup() function

from ta_x import setup

setup(
    x_auth_token="your_x_auth_token",
    x_ct0="your_x_ct0_token",
    openai_api_key="your_openai_api_key",
    rapid_api_key="your_rapid_api_key"
)

Method 2: Environment Variables

export X_AUTH_TOKEN="your_x_auth_token"
export X_CT0="your_x_ct0_token"
export OPENAI_API_KEY="your_openai_api_key"
export RAPID_API_KEY="your_rapid_api_key"

Method 3: .env file

Create a .env file in your project root:

X_AUTH_TOKEN=your_x_auth_token
X_CT0=your_x_ct0_token
OPENAI_API_KEY=your_openai_api_key
RAPID_API_KEY=your_rapid_api_key

CLI Usage

The package also provides a command-line interface:

# Setup authentication
ta-x-agent setup --x-auth-token "your_token" --x-ct0 "your_ct0" --openai-key "your_key" --rapid-api-key "your_rapid_key"

# Create a post
ta-x-agent post "Hello X world!"

# Like the latest post
ta-x-agent like

# Get trending topics
ta-x-agent trends

# Get user details
ta-x-agent user-details elonmusk

Advanced Usage

Using XAgent Class Directly

from ta_x import XAgent

custom_agent = XAgent(
    auth_token="your_x_auth_token",
    ct0="your_x_ct0_token"
)

result = await custom_agent.run("Post this: Hello world!")

Using execute_x_task Function

from ta_x import execute_x_task

result = await execute_x_task("Post this: Hello world!")

Error Handling

try:
    result = await agent.run("Post this: Test post")
    print(f"Success: {result}")
except Exception as e:
    print(f"Error: {e}")
    print("Make sure authentication tokens are set correctly!")

Configuration Management

Get Current Configuration

from ta_x import get_config

config = get_config()
print(f"X Auth Token: {config.x_auth_token}")
print(f"X CT0: {config.x_ct0}")
print(f"OpenAI API Key: {config.openai_api_key}")
print(f"RapidAPI Key: {config.rapid_api_key}")

Reset Configuration

from ta_x import reset_config

# Reset to default values
reset_config()

Available Operations

The agent supports the following operations:

  1. Create Posts: "Post this: [content]" or "Create a post with [content]"
  2. Like Posts: "Like the latest post" or "Like the post of [username]"
  3. Unlike Posts: "Unlike the post" or "Dislike the post of [username]"
  4. Retweet Posts: "Retweet the post" or "Retweet the post of [username]"
  5. Get Trends: "What's trending?" or "Show trends"
  6. Get Tweet Details: "Get tweet details for [tweet_id]"
  7. Get User Details: "Get user details for [username]"

Error Handling

The package includes comprehensive error handling:

  • Missing Configuration: Clear error messages when required tokens are not set
  • Invalid Credentials: Proper handling of authentication failures
  • Network Errors: Graceful handling of connection issues
  • Rate Limiting: Built-in support for X API rate limits

Development

Installing Development Dependencies

pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black ta_x/

Type Checking

mypy ta_x/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Disclaimer

This package is for educational and development purposes. Please ensure you comply with X (Twitter)'s Terms of Service and API usage guidelines when using this package.

Metadata

Release files for ta-x-agent 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ta-x-agent 0.1.2
File Size Uploaded Provenance Actions
ta_x_agent-0.1.2.tar.gz 19.0 kB Without provenance Details for ta_x_agent-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ta-x-agent 0.1.2
File Interpreter ABI Platform Actions
ta_x_agent-0.1.2-py3-none-any.whl Python 3 none any Details for ta_x_agent-0.1.2-py3-none-any.whl

Total release size: 36.2 kB

Release files / ta_x_agent-0.1.2.tar.gz

Download URL ta_x_agent-0.1.2.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6464a44d648bf19267fc7ee0ddd45978ec71c635040708e298f82f2e6623989b
BLAKE2b-256 checksum
How to use checksums
1e922148a79e063eda485dde12f70780902cdf4bdbc04ceaf0326e6dd8685d25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / ta_x_agent-0.1.2-py3-none-any.whl

Download URL ta_x_agent-0.1.2-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e012b898e028cabe2b506a30498a456cca71a1baf4e49d520e8e258d30a07f17
BLAKE2b-256 checksum
How to use checksums
b758458ce26fdf84c2c04c9adfa896a6a554725473904e033d5714e8a4c118f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for ta-x-agent 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page