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.0.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.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for linkgrid_x_transaction_id-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f423ae32f7d40ce75713fdd08960127acc311f42381a532bdd64ab615e7c2223
MD5 9dce5bc50600f3b40203a9a6c8432c71
BLAKE2b-256 a7a56f6444a75e1fe47f0f308a09a7cf5e65de32ec6ca7dd0dd85c7799d0eb81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for linkgrid_x_transaction_id-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94430578a69a61d4103740ad6659c4939dd2ce59821bfdaa131dd84e1dac96d3
MD5 8a6eae7d0860e2b86fcc4b32089c1407
BLAKE2b-256 4218b33ea328416f96e19b115b224ccdfe2997f1f70360b083aac26fb19aefbf

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