Skip to main content

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

PyPI Version Python Version License

InstallationQuick StartFeaturesAPI Reference

✨ 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 page
  • ondemand_file_response (bs4.BeautifulSoup): Parsed HTML response from the ondemand script
  • random_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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkgrid_x_transaction_id-1.0.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linkgrid_x_transaction_id-1.0.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file linkgrid_x_transaction_id-1.0.1.tar.gz.

File metadata

File hashes

Hashes for linkgrid_x_transaction_id-1.0.1.tar.gz
Algorithm Hash digest
SHA256 702ca6eb67f430097ad038f9e6819a0283cc92509a2d8c185f6a9aa924096b2a
MD5 f34d88e4e66b82ab49c2378e12b9233d
BLAKE2b-256 93aac7f67ccd02a3b655755713a03b1a128b1c111ad1cb4deb94b51e12b1aa3f

See more details on using hashes here.

File details

Details for the file linkgrid_x_transaction_id-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for linkgrid_x_transaction_id-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 174fdb55d2c1896ca84f4ebb40fe99476ec3979279d83821862bf1bb80e94904
MD5 4f2d19d58c55dc360ea568ca38517824
BLAKE2b-256 658c4cfeafe0813ff890278055635cbd481bc60226e7cadba1de8af52550d5a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page