Skip to main content

This Python package provides convenient access to the Local API REST interface of the Kameleo Client.

Project description

Kameleo Local API Client

With Kameleo, you can easily create multiple virtual browser profiles to work with multiple accounts. It helps you hide your actual timezone, geolocation, language, IP address and creates natural browser fingerprints to prevent detection by anti-bot systems. Kameleo is compatible with Selenium, Playwright, and Puppeteer frameworks for automating web scraping tasks. This Python package provides convenient access to the Local API REST interface of the Kameleo Client. See the article in our knowledge base for Getting Started with Kameleo Automation.

Features

  • Stay completely undetected, so websites won’t be able to detect that you are using automation tools
  • Start unlimited number of profiles with different natural browser fingerprints
  • Use authenticated HTTP/SOCKS/SSH proxies in browsers
  • Create isolated browsing environments simultaneously
  • Use real browser profiles of Chrome, Firefox, Safari and Edge
  • Edit, Import or Export browser cookies
  • Modify WebRTC parameters
  • Modify Geolocation settings
  • Modify Timezone and Language settings
  • Modify WebGL fingerprint
  • Modify 2D Canvas fingerprint
  • Modify Navigator properties
  • Modify Screen resolution

Note: You need Automation package of Kameleo to access the features described below.

Quickstart Guide

1. Install package

pip install kameleo.local_api_client

2. Start the Kameleo.CLI on your computer

./Kameleo.CLI.exe email="your@email.com" password="Pa$$w0rd"

3. Start a browser with out-of-the-box fingerprinting protection

from kameleo.local_api_client import KameleoLocalApiClient
from kameleo.local_api_client.builder_for_create_profile import BuilderForCreateProfile

client = KameleoLocalApiClient()
base_profiles = client.search_base_profiles(
    device_type='desktop',
    browser_product='chrome'
)

# Create a new profile with recommended settings
# for browser fingerprinting protection
create_profile_request = BuilderForCreateProfile \
    .for_base_profile(base_profiles[0].id) \
    .set_name('example profile') \
    .set_recommended_defaults() \
    .build()
profile = client.create_profile(body=create_profile_request)

# Start the browser
client.start_profile(profile.id)

# At this point you can automate the browser with your favorite framework

Automate Kameleo profiles with Selenium

Kameleo gives you the ability to control any supported browser using Selenium. It uses the WebDriver protocol, a W3C specification, and industry-standard to interact with a browser.

You need to install the official Selenium package.

from selenium import webdriver
# Connect to the running browser instance using WebDriver
kameleo_port = 5050
options = webdriver.ChromeOptions()
options.add_experimental_option('kameleo:profileId', profile.id)
driver = webdriver.Remote(
    command_executor=f'http://localhost:{kameleo_port}/webdriver',
    options=options
)

# Use any WebDriver command to drive the browser
# and enjoy full protection from bot detection products
driver.get('https://google.com')

The full example can be found here.

Automate Kameleo profiles with Puppeteer (Chromium-based)

Kameleo lets you control Chromium-based browsers (sorry Firefox fans) using the Pyppeteer library. In this simple example you can see how to connect to the browser that Kameleo starts.

You need to import the Pyppeteer library.

import pyppeteer
# Connect to the browser with Puppeteer through CDP
kameleo_port = 5050
browser_ws_endpoint = f'ws://localhost:{kameleo_port}/puppeteer/{profile.id}'
browser = await pyppeteer.launcher.connect(browserWSEndpoint=browser_ws_endpoint, defaultViewport=False)
page = await browser.newPage()

# Use any Playwright command to drive the browser
# and enjoy full protection from bot detection products
await page.goto('https://google.com')

The full example can be found here.

Automate Kameleo profiles with Playwright

Kameleo allows you to control the browser with the official Playwright package. It works little bit different with Chromium-based browsers and Firefox, so we provide an example for both. Here we showcase how you can connect to the browser that is already started by Kameleo.

You need to import the official Playwright package.

import playwright
from playwright.sync_api import sync_playwright

You can find more details here: Using Kameleo with Playwright framework – Kameleo Support Center.

Chromium-based profiles with Playwright

# Connect to the browser with Playwright through CDP
kameleo_port = 5050
browser_ws_endpoint = f'ws://localhost:{kameleo_port}/playwright/{profile.id}'
with sync_playwright() as playwright:
    browser = playwright.chromium.connect_over_cdp(endpoint_url=browser_ws_endpoint)
    context = browser.contexts[0]
    page = context.new_page()

    # Use any Playwright command to drive the browser
    # and enjoy full protection from bot detection products
    page.goto('https://google.com')

The full example can be found here.

Firefox-based profiles with Playwright

# Connect to the browser with Playwright
kameleo_port = 5050
browser_ws_endpoint = f'ws://localhost:{kameleo_port}/playwright/{profile.id}'
with sync_playwright() as playwright:
    # The exact path to the bridge executable is subject to change. Here, we use %LOCALAPPDATA%\Programs\Kameleo\pw-bridge.exe
    executable_path_example = path.expandvars(r'%LOCALAPPDATA%\Programs\Kameleo\pw-bridge.exe')
    browser = playwright.firefox.launch_persistent_context(
        '',
        # The Playwright framework is not designed to connect to already running
        # browsers. To overcome this limitation, a tool bundled with Kameleo, named
        # pw-bridge.exe will bridge the communication gap between the running Firefox
        # instance and this playwright script.
        executable_path=executable_path_example,
        args=[f'-target {browser_ws_endpoint}'],
        viewport=None)

    # Kameleo will open the a new page in the default browser context.
    # NOTE: We DO NOT recommend using multiple browser contexts, as this might interfere
    #       with Kameleo's browser fingerprint modification features.
    page = browser.new_page()

    # Use any Playwright command to drive the browser
    # and enjoy full protection from bot detection products
    page.goto('https://google.com')

    # Here we need to close the browser object as well, it is not enough just to stop the profile
    client.stop_profile(profile.id)
    browser.close()

The full example can be found here.

Automate mobile profiles

Kameleo can emulate mobile devices in the custom built Chromium.

# Search for a mobile Base Profiles
base_profile_list = client.search_base_profiles(
    device_type='mobile',
    os_family='ios',
    browser_product='safari',
    language='en-us'
)

# Create a new profile with recommended settings
# Choose one of the Base Profiles
# Set the launcher to 'chromium' so the mobile profile will be started in Chroma browser
create_profile_request = BuilderForCreateProfile \
    .for_base_profile(base_profile_list[0].id) \
    .set_name('automate mobile profiles on desktop example') \
    .set_recommended_defaults() \
    .set_launcher('chromium') \
    .build()
profile = client.create_profile(body=create_profile_request)

# Start the profile
client.start_profile_with_options(profile.id, body={
    # This allows you to click on elements using the cursor when emulating a touch screen in the browser.
    # If you leave this out, your script may time out after clicks and fail.
    'additionalOptions': [
        {
            'key': 'disableTouchEmulation',
            'value': True,
        },
    ],
})

# At this point you can automate the browser with your favorite framework

The full example can be found here.

Example codes

Several examples have been prepared in a different repository to showcase the most interesting features. Feel free to create a pull request to add new example codes.

  • Finding base profiles
  • Creating profiles with custom options
  • Updating profiles with new settings
  • How to start a profile
  • Using Selenium with Local API
  • Using Playwright with Kameleo
  • Using Puppeteer with Kameleo
  • How to emulate mobile devices
  • Adding an HTTP, SOCKS or SSH proxy to profile
  • Saving/Loading a browsing session to/from a .kameleo file
  • Modify and Delete browser cookies
  • Start profile with extra WebDriver capabilities
  • How to duplicate virtual browser profiles
  • Refresh the browser of the emulated profiles

Note: If you are interested in more information about Kameleo, or have encountered an issue with using it, please check out our Help Center.

Endpoints

Available API endpoints with exhaustive descriptions and example values are documented on this SwaggerHub page. This package has built-in IntelliSense support in Visual Studio Code, no extra package installation needed.

Package

This package can be found on PyPI here: kameleo.local-api-client.

License

This project is released under MIT License. Please refer the LICENSE.txt 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

kameleo.local_api_client-3.2.0.tar.gz (60.4 kB view details)

Uploaded Source

Built Distribution

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

kameleo.local_api_client-3.2.0-py2.py3-none-any.whl (66.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file kameleo.local_api_client-3.2.0.tar.gz.

File metadata

  • Download URL: kameleo.local_api_client-3.2.0.tar.gz
  • Upload date:
  • Size: 60.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for kameleo.local_api_client-3.2.0.tar.gz
Algorithm Hash digest
SHA256 efff618dbb56b8b289cc8fa0b87316af0654d9c90cf9411bba1035b1bd07e9c8
MD5 03b8954ba350a8ccdbde36dccc2d546c
BLAKE2b-256 d7035c90946911a85b0d8b90c39b49f62ef05ef2a2b100d534912fef745e96bb

See more details on using hashes here.

File details

Details for the file kameleo.local_api_client-3.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for kameleo.local_api_client-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e4ba793f9e60e34309eb625881878ef675f09ac07678c24de5f235913038eea
MD5 b6e7d77f9f5d4abfdd992143e1f35633
BLAKE2b-256 b44adb4735d7d4896bb4ea5f25d35e098165838e13f9b523d0efb731aec4a817

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