Twitter X-Client-Transaction-Id generator written in python.
Project description
LinkGrid X-Transaction-ID
🔗 A Python package for generating X-Client-Transaction-Id headers used in API requests
✨ Overview
deepsaha-x-transaction-id is a powerful Python package that simplifies the generation of X-Client-Transaction-Id headers required for making authenticated requests to X's (formerly Twitter) API endpoints. It handles all the complexity of generating valid transaction IDs so you can focus on building your application.
🚀 Features
- 🔥 Easy to Use: Simple and intuitive API for generating transaction IDs
- ⚡ High Performance: Optimized for speed and efficiency
- 🔄 Async Support: Built-in support for both synchronous and asynchronous operations
- 📦 Lightweight: Minimal dependencies, maximum functionality
- 🛡 Reliable: Battle-tested and production-ready
📦 Installation
Install the package using pip:
pip install linkgrid-x-transaction-id
🚀 Quick Start
from linkgrid_x_transaction_id import ClientTransaction
# Create a client instance
client = ClientTransaction()
# Get a transaction ID
transaction_id = client.get_transaction_id()
print(f"Generated Transaction ID: {transaction_id}")
import aiohttp import asyncio from deepsaha_x_transaction_id import ClientTransaction from deepsaha_x_transaction_id.utils import generate_headers, handle_x_migration, get_ondemand_file_url
async def main(): async with aiohttp.ClientSession(headers=generate_headers()) as session: # Get home page response home_page_response = await handle_x_migration(session, is_async=True)
# Get ondemand file URL and response
ondemand_file_url = get_ondemand_file_url(home_page_response)
async with session.get(ondemand_file_url) as response:
ondemand_file_response = await response.text()
# Initialize client and generate transaction ID
ct = ClientTransaction(home_page_response, ondemand_file_response)
transaction_id = ct.generate_transaction_id(
method="POST",
path="/i/api/1.1/jot/client_event.json"
)
print(f"Generated Transaction ID: {transaction_id}")
Run the async function
if name == "main": asyncio.run(main())
## 📚 API Reference
### `ClientTransaction` Class
The main class for generating X-Client-Transaction-Id headers.
```python
ClientTransaction(
home_page_response: bs4.BeautifulSoup,
ondemand_file_response: bs4.BeautifulSoup,
random_keyword: str = "qbg",
random_number: int = 1
)
Parameters
home_page_response(bs4.BeautifulSoup): Parsed HTML response from X/Twitter home pageondemand_file_response(bs4.BeautifulSoup): Parsed HTML response from the ondemand scriptrandom_keyword(str, optional): Custom keyword for transaction ID generation. Defaults to "qbg"random_number(int, optional): Custom number for transaction ID generation. Defaults to 1
Methods
generate_transaction_id(method: str, path: str) -> str
Generate a transaction ID for the given HTTP method and path.
Parameters:
method(str): HTTP method (e.g., "GET", "POST")path(str): API endpoint path (e.g., "/i/api/1.1/jot/client_event.json")
Returns:
str: Generated transaction ID string
Utility Functions
generate_headers() -> Dict[str, str]
Generate default headers for X/Twitter API requests.
handle_x_migration(session: requests.Session, is_async: bool = False) -> Union[bs4.BeautifulSoup, Coroutine]
Handle the X/Twitter migration and return the parsed home page response.
get_ondemand_file_url(response: bs4.BeautifulSoup) -> str
Extract the ondemand script URL from the home page response.
🤝 Contributing
Contributions are welcome! Feel free to submit issues and pull requests.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Author
Deep Saha
- Website: deepsaha.com
- Twitter: @DeepSahaDev
- GitHub: @OfficialDeepSaha
Feedback
If you have any feedback, please reach out to us at hiremeasadeveloper@gmail.com or contact me on Social Media @LegendDeep2003
Support
For support, email hiremeasadeveloper@gmail.com
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 linkgrid_x_transaction_id-1.0.0.tar.gz.
File metadata
- Download URL: linkgrid_x_transaction_id-1.0.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f423ae32f7d40ce75713fdd08960127acc311f42381a532bdd64ab615e7c2223
|
|
| MD5 |
9dce5bc50600f3b40203a9a6c8432c71
|
|
| BLAKE2b-256 |
a7a56f6444a75e1fe47f0f308a09a7cf5e65de32ec6ca7dd0dd85c7799d0eb81
|
File details
Details for the file linkgrid_x_transaction_id-1.0.0-py3-none-any.whl.
File metadata
- Download URL: linkgrid_x_transaction_id-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94430578a69a61d4103740ad6659c4939dd2ce59821bfdaa131dd84e1dac96d3
|
|
| MD5 |
8a6eae7d0860e2b86fcc4b32089c1407
|
|
| BLAKE2b-256 |
4218b33ea328416f96e19b115b224ccdfe2997f1f70360b083aac26fb19aefbf
|