A Python package for interacting with X (Twitter) platform using AI agents
Project description
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:
- Create Posts:
"Post this: [content]"or"Create a post with [content]" - Like Posts:
"Like the latest post"or"Like the post of [username]" - Unlike Posts:
"Unlike the post"or"Dislike the post of [username]" - Retweet Posts:
"Retweet the post"or"Retweet the post of [username]" - Get Trends:
"What's trending?"or"Show trends" - Get Tweet Details:
"Get tweet details for [tweet_id]" - 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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📧 Email: your.email@example.com
- 🐛 Issues: GitHub Issues
- 📖 Documentation: GitHub README
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ta_x_agent-0.1.2.tar.gz.
File metadata
- Download URL: ta_x_agent-0.1.2.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6464a44d648bf19267fc7ee0ddd45978ec71c635040708e298f82f2e6623989b
|
|
| MD5 |
518dc6ba0438130a4715b82484fe6493
|
|
| BLAKE2b-256 |
1e922148a79e063eda485dde12f70780902cdf4bdbc04ceaf0326e6dd8685d25
|
File details
Details for the file ta_x_agent-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ta_x_agent-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e012b898e028cabe2b506a30498a456cca71a1baf4e49d520e8e258d30a07f17
|
|
| MD5 |
ba1c4d11e938b796f5b5d65fb74659e8
|
|
| BLAKE2b-256 |
b758458ce26fdf84c2c04c9adfa896a6a554725473904e033d5714e8a4c118f9
|