Skip to main content

Installation

This guide walks you through installing Twikit and setting up your Python environment.

Python version requirement

Twikit requires Python 3.8 or higher. Before installing, verify your Python version:
python --version
If you need to upgrade Python, visit python.org/downloads.

Install via pip

The simplest way to install Twikit is using pip:
pip install twikit
This installs Twikit along with all required dependencies.
Use a virtual environment to keep your project dependencies isolated. See the Virtual environment setup section below.

Dependencies

Twikit automatically installs the following dependencies:
  • httpx[socks] - HTTP client with async support and proxy capabilities
  • filetype - File type detection for media uploads
  • beautifulsoup4 - HTML parsing for web scraping
  • pyotp - One-time password support for 2FA
  • lxml - Fast XML/HTML processing
  • webvtt-py - WebVTT subtitle parsing
  • m3u8 - M3U8 playlist parsing for video handling
  • Js2Py-3.13 - JavaScript to Python translation for UI metrics
You don’t need to install these manually—pip handles them automatically.

Virtual environment setup

Using a virtual environment is recommended to avoid dependency conflicts with other projects.
1

Create a virtual environment

Navigate to your project directory and create a virtual environment:
python -m venv venv
2

Activate the virtual environment

Activate the environment based on your operating system:On macOS/Linux:
source venv/bin/activate
On Windows:
venv\Scripts\activate
Your terminal prompt should change to indicate the virtual environment is active.
3

Install Twikit

With the virtual environment activated, install Twikit:
pip install twikit

Verify installation

Confirm that Twikit is installed correctly by checking the version:
python -c "import twikit; print(twikit.__version__)"
This should print the installed version number (e.g., 2.3.3). You can also verify the installation in a Python script:
import twikit
from twikit import Client

print(f"Twikit version: {twikit.__version__}")
print("Installation successful!")

Proxy support

Twikit includes SOCKS proxy support through httpx. If you need to use a proxy, you can configure it when initializing the client:
from twikit import Client

client = Client(
    language='en-US',
    proxy='http://proxy.example.com:8080'
)
  • HTTP: http://proxy.example.com:8080
  • HTTPS: https://proxy.example.com:8080
  • SOCKS5: socks5://proxy.example.com:1080
  • With authentication: http://user:[email protected]:8080

Update Twikit

To update to the latest version of Twikit:
pip install --upgrade twikit
Twitter frequently updates their web interface, which can break scraping libraries. Keep Twikit updated to ensure compatibility.

Troubleshooting

Installation fails with compilation errors

If you encounter compilation errors during installation, ensure you have the necessary build tools: On Ubuntu/Debian:
sudo apt-get install python3-dev build-essential
On macOS:
xcode-select --install
On Windows: Install Microsoft C++ Build Tools.

Import errors

If you see import errors after installation:
  1. Verify you’re using the correct Python interpreter (especially in virtual environments)
  2. Try reinstalling: pip uninstall twikit && pip install twikit
  3. Check for conflicting dependencies: pip check

Next steps

Now that you have Twikit installed, you’re ready to start building:

Quickstart

Create your first Twikit script and make your first API call

Build docs developers (and LLMs) love