Skip to main content

An unofficial X SDK for Python

Project description

corvx Logo

Downloads PyPi License

An unofficial X SDK for Python

Buy Me A Coffee

Installation

corvx works with Python +3.10

You can install the corvx package directly with pip:

pip install -e .

or

pip install corvx

Usage

To work with the X Scraper module you have to import the corresponding module first:

from corvx import Corvx

# You can also set the tokens with environment variables X_AUTH_TOKEN and X_CSRF_TOKEN
corvx = Corvx(
    auth_token=os.getenv('X_AUTH_TOKEN'),
    csrf_token=os.getenv('X_CSRF_TOKEN'),
)

The available methods and its usage are described below.

Query Formats

corvx supports two query formats:

1. Simple String Format

You can directly pass strings as queries:

queries = [
    'python programming',
    'javascript development',
]

for tweet in corvx.search(queries=queries):
    print(tweet)

2. Advanced Query Language

For more complex searches, a JSON-based query language is available. The query must be specified as a Python dictionary containing a list of fields and global options.

Global options


lang

This option will force the tweets to match a given language. The language must be specified with its ISO 639-1 two-letter code (e.g., es for Spanish).

since

This parameter refers to the minimum allowed date. It has to be specified in the YYYY-MM-DD format.

until

This parameter refers to the maximum allowed date. It has to be specified in the YYYY-MM-DD format.

near

It has to be specified with a tuple object composed of a text location and a range in miles (e.g., ('Santiago de Compostela', 15)).

Fields


A query can specify multiple fields which are Python dictionaries with one or more keys and values:

items

This is a list of strings, either terms or phrases.

exact

If True, the specified terms or phrases must match exactly as they were written on the tweets (case/latin insensitive). If this flag is set, the target parameter will be ignored.

match

If not specified, the tweets will match every item.

  • 'any' (the tweets must match at least one of the items)
  • 'none' (the tweets won't match any item)

target

If not specified, the tweets will match ordinary keywords.

  • 'hashtag' (tweets containing #item)
  • 'mention' (tweets mentioning @item)
  • 'from' (tweets written by @item)
  • 'to' (tweets that are replies to @item)

Examples


Simple search with multiple queries:

# Simple string queries
queries = ['python', 'javascript']
for tweet in corvx.search(queries=queries):
    print(tweet)

Advanced search with a single query:

# Advanced query format
query = {
    'fields': [
        {'items': ['Santiago']},
        {'items': ['Chile'], 'match': 'none'},
    ],
    'lang': 'es'
}

for tweet in corvx.search(query=query):
    print(tweet)

Advanced search with multiple queries:

# Multiple advanced queries
queries = [
    {
        'fields': [{'items': ['python'], 'match': 'any'}],
        'lang': 'en'
    },
    {
        'fields': [{'items': ['javascript'], 'match': 'any'}],
        'lang': 'en'
    }
]

for tweet in corvx.search(queries=queries):
    print(tweet)

Search Options

Deep Search

Search for all available results by going back in time:

for tweet in corvx.search(queries=queries, deep=True):
    print(tweet)

Limit Results

Limit the number of results:

for tweet in corvx.search(queries=queries, limit=100):
    print(tweet)

Rate Limiting

Control the time between API calls:

for tweet in corvx.search(queries=queries, sleep_time=30):
    print(tweet)

Stream

Search constantly for new results:

# Stream with multiple queries
queries = ['python', 'javascript']
for tweet in corvx.stream(queries=queries):
    print(tweet)

Debug Logging

Enable debug logging to see detailed information:

import logging

# Configure logging at the start of your script
logging.basicConfig(
    level=logging.DEBUG,
    format='[%(asctime)s] %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
)

# Configure corvx logger
logger = logging.getLogger('corvx')
logger.setLevel(logging.DEBUG)
logger.propagate = True

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

corvx-1.2501.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file corvx-1.2501.1-py3-none-any.whl.

File metadata

  • Download URL: corvx-1.2501.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for corvx-1.2501.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a55a2adb46fab614aa9b711f3aa732f661fa0d8956ee003d2fa9f1fe77d303d3
MD5 aafbab139bb49853deab2e6c53428ca5
BLAKE2b-256 b5ec8489a3cd5cfa091d0f68919270188e75d39c70af1a05ecb1b5ae7fe6cb6a

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