Skip to main content

Unnoficial TikTok library for chatbot making. Use at your own risk.

Project description

PyUTAL For Python

PyUTAL

GitHub PyPi LICENSE DOCUMENTATION

PyUTAL (Unofficial TikTok Automation Library) is a Python library designed to develop chatbots or automate TikTok's direct messages (not TikTok Live) using Selenium.

Installation

To install PyUTAL, it is recommended to first create a virtual environment to isolate project dependencies. Follow these steps:

  1. Install virtualenv if you don’t have it yet:
    pip install virtualenv
    
  2. Create a virtual environment:
    python3 -m venv venv
    
  3. Activate the virtual environment:
    • Windows:
      venv\Scripts\activate
      
    • Linux/macOS:
      source venv/bin/activate
      
  4. Install utal inside the virtual environment:
    pip install utal
    

Quick Start

Here is a guide to setting up a simple project using utal.

  1. Initialize the webdriver with Selenium without headless mode the first time to log in manually.
  2. Then, use the following code:
import os
from utal.core import PyUTAL
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

def startup_selenium():
    USERDATADIR = os.path.abspath("path/to/user/data/directory")
    DRIVERPATH = "path/to/webdriver"

    options = webdriver.ChromeOptions()
    options.add_experimental_option("detach", True)
    options.add_argument("--headless")  # Run without headless mode the first time
    options.add_argument(rf"user-data-dir={USERDATADIR}")
    
    driver = webdriver.Chrome(service=Service(DRIVERPATH), options=options)
    return driver  # Important to return the driver

def main(driver, app: PyUTAL):
    driver.get("https://tiktok.com/messages")
    
    while True:  # Important to use loops
        message = app.client.listen()  # Retrieves all messages
        if message:
            print(message)

        if message and message == "hello":  
            user_nickname = app.conversation.get_user_nickname()
            app.conversation.send(f"Hi, {user_nickname} 🌟")

if __name__ == "__main__":
    driver = startup_selenium()
    app = PyUTAL(driver)
    main(driver, app)
  • Console output (if the user sends "hello")
hello
  • Bot response (if the nickname is "thiago")
Hi, thiago 🌟

Important Notes

  • Headless mode must be disabled the first time to allow manual login and save session data.
  • A loop is required for the bot to continuously listen for incoming messages.
  • The bot does NOT have a prefix configured and does not filter its own messages in this example. See the documentation to learn how to implement that.

Next Steps

These are just recommendations.

  • Implement a system of custom prefixes for each user.
  • Develop a command handler to structure the bot’s commands better.
  • Use a database to store bot or user information.
  • Take inspiration from Discord bot development structures.
  • Experiment and test the different functions of the library.
  • See the Selenium documentation to scale the project.

Disclaimers

By using PyUTAL from the utal library, you agree to the following terms. If you do not agree, we recommend you stop using PyUTAL:

  • This library was created for educational purposes and must be used at your own risk. The creator and/or contributors are not responsible for any misuse of the tool.
  • This is not an official TikTok tool.
  • This tool does not connect to TikTok's official APIs; it only performs automation through scraping.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

utal-0.2.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

utal-0.2.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file utal-0.2.3.tar.gz.

File metadata

  • Download URL: utal-0.2.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for utal-0.2.3.tar.gz
Algorithm Hash digest
SHA256 76f898abe62d0f71f18f7cce2244ab4ff02bf5e3567b2f57895a41f439aa9a45
MD5 53488a7ceffeeee28bb5ad5c7214f485
BLAKE2b-256 bde1e3d08db23cf5a23b24de2292f9439cabbe27ee8d31abab6d96f8a1eeca87

See more details on using hashes here.

Provenance

The following attestation bundles were made for utal-0.2.3.tar.gz:

Publisher: python-publish.yml on thiagostilo2121/utal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file utal-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: utal-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for utal-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 296a7d4b8b3d2758cdc25e60cb6bd2e51b79c91288ffb26bed57b7b082261601
MD5 47f4726c2b9d13fbdbe513b7d0cef710
BLAKE2b-256 9b45b8ea9ff9c690d3675d70712271121c8b67d07f0b1ee463d9264ab0a66b8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for utal-0.2.3-py3-none-any.whl:

Publisher: python-publish.yml on thiagostilo2121/utal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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