pywhatkit Documentation

repository·master·Indexed 23 days ago

https://github.com/ankit404butfound/pywhatkit

A Python library for automation tasks including scheduling WhatsApp messages to contacts and groups, playing YouTube videos, converting images to ASCII art, and remotely controlling a Windows PC via a phone browser.

Tokens
1.1K
Snippets
8
Records
8
Agent score
32%

What's inside pywhatkit

  1. Remotely control your PC using your phone (Windows only)

    master

    You can use pywhatkit.start_server() to turn your PC into a remote-controlled device via a phone browser.

    Requirements & Setup:

    1. Windows Only: This feature is only supported on Windows.
    2. Network: Both PC and phone must be on the same network.
    3. Network Profile: On your PC, ensure the Network Profile is set to Private (Network and Internet Settings > Properties > Network Profile).
    4. Execution:
      • Run pywhatkit.start_server() in your Python script.
      • Open Command Prompt on your PC and run ipconfig to find your IPv4 Address.
      • On your phone's browser, navigate to [YOUR_IPv4_ADDRESS]:8000 (e.g., 192.168.0.1:8000).

    Once connected, you can move the cursor, type, and scroll using your phone.

    import pywhatkit
    pywhatkit.start_server()
  2. Send a WhatsApp message to a group

    master

    Use pywhatkit.sendwhatmsg_to_group() to schedule a message to a WhatsApp group using its Group ID. Use pywhatkit.sendwhatmsg_to_group_instantly() to send a message to a group immediately without scheduling.

    import pywhatkit
    
    # Send a WhatsApp Message to a Group at 12:00 AM
    pywhatkit.sendwhatmsg_to_group("AB123CDEFGHijklmn", "Hey All!", 0, 0)
    
    # Send a WhatsApp Message to a Group instantly
    pywhatkit.sendwhatmsg_to_group_instantly("AB123CDEFGHijklmn", "Hey All!")
  3. Send an image to a WhatsApp group or contact

    master

    Use pywhatkit.sendwhats_image() to send an image.

    • To send to a group, provide the Group ID.
    • To send to a contact, provide the phone number with +.

    If a caption is provided, it will be sent with the image. If no caption is provided, the image is sent alone.

    import pywhatkit
    
    # Send an Image to a Group with the Caption as Hello
    pywhatkit.sendwhats_image("AB123CDEFGHijklmn", "Images/Hello.png", "Hello")
    
    # Send an Image to a Contact with no Caption
    pywhatkit.sendwhats_image("+910123456789", "Images/Hello.png")
  4. Send a WhatsApp message and close the tab automatically

    master

    Use pywhatkit.sendwhatmsg() with additional parameters to automatically close the browser tab after sending the message.

    Parameters:

    • phone_no: Contact number with +.
    • message: The text to send.
    • time_hour: Hour (24h format).
    • time_min: Minute.
    • wait_time: Seconds to wait before sending (default is 15).
    • tab_close: Boolean to close the tab after sending.
    • close_time: Seconds to wait after sending before closing the tab.
    import pywhatkit
    
    # Same as above but Closes the Tab in 2 Seconds after Sending the Message
    pywhatkit.sendwhatmsg("+910123456789", "Hi", 13, 30, 15, True, 2)
  5. Send a WhatsApp message to a contact

    master

    Use pywhatkit.sendwhatmsg() to schedule a WhatsApp message to a specific contact. You must provide the phone number in international format (including the + sign), the message string, and the hour and minute in 24-hour format.

    import pywhatkit
    
    # Send a WhatsApp Message to a Contact at 1:30 PM
    pywhatkit.sendwhatmsg("+910123456789", "Hi", 13, 30)