Back to use cases

    Use case / SOCIAL DATA / Python 3 / Published

    Check a username across Instagram, TikTok, X and Facebook

    Check one or more usernames across Instagram, TikTok, X and Facebook in one run. Get a grid of public profiles with names, follower counts and links.

    One handle checked through Desearch on four social networks into a results grid

    This username checker looks up one or more handles on Instagram, TikTok, X and Facebook in one run. It prints a grid of public profile results with display names, follower counts and profile links. It is a Python CLI with no extra packages. This page shows a stored sample; there is no hosted demo.

    The problem

    Before you launch a brand, a product or a campaign, you want to know where a handle is already in use. Checking four networks by hand for several candidates is slow, and the results are hard to compare. You also need to know which answers are certain and which ones the network would not confirm.

    What the app does

    • Accepts plain handles, handles with @ and supported profile URLs.
    • Checks each handle on Instagram, TikTok, X and Facebook, or on the networks you choose.
    • Labels each result as found, no public profile found, could not check or invalid.
    • Shows the display name, follower count when present and a profile link for each found profile.
    • Writes a results CSV, a Markdown grid and a raw JSON log with credentials redacted.

    No public profile found does not mean the handle is free. It can be reserved, banned, private, suspended or deactivated. Check on the network's own signup page.

    How it works

    1. Normalize the input. Handles are trimmed and leading @ characters removed. A profile URL is reduced to its handle. Handles that break a network's local format rules are marked invalid and skip the request.
    2. Call each network. Instagram, TikTok and Facebook use their Desearch profile routes. X uses GET /twitter/user/posts with only the username, because there is no X profile lookup route.
    3. Run in parallel. Up to 8 workers run at once. Results keep the input order of handles and networks.
    4. Classify. A recognizable profile in the response is found. A 404 is no public profile found. Only HTTP 503 is retried, once after two seconds. Other errors, and responses without a recognizable profile, are could not check.
    5. Report. The grid prints to stdout, and a call, cost and time summary prints to stderr.

    The code

    This verbatim excerpt from username_checker.py reads a handle from text or a profile URL and builds the request URL for each network:

    PYTHON
    def normalize(value):
        value = value.strip()
        parsed = urllib.parse.urlparse(value if '://' in value else '//' + value)
        hosts = {'instagram.com', 'tiktok.com', 'x.com', 'twitter.com', 'facebook.com'}
        if (parsed.hostname or '').lower().removeprefix('www.') in hosts:
            value = urllib.parse.unquote(parsed.path).strip('/').split('/')[0]
            if (parsed.hostname or '').lower().removeprefix('www.') == 'facebook.com' and value == 'profile.php':
                profile_id = urllib.parse.parse_qs(parsed.query).get('id', [''])[0]
                value = profile_id if re.fullmatch(r'[0-9]+', profile_id) else ''
        return value.lstrip('@').strip()
    
    
    def profile_url(network, handle):
        h = urllib.parse.quote(str(handle), safe='')
        return {'instagram': f'https://www.instagram.com/{h}/', 'tiktok': f'https://www.tiktok.com/@{h}', 'x': f'https://x.com/{h}', 'facebook': f'https://www.facebook.com/{h}'}[network]
    
    
    def endpoint(network, handle):
        h = urllib.parse.quote(handle, safe='')
        if network == 'x':
            return 'https://api.desearch.ai/twitter/user/posts?' + urllib.parse.urlencode({'username': handle})
        return f'https://api.desearch.ai/desearch/{network}/profile/{h}'

    View the code

    Endpoints

    • GET /desearch/instagram/profile/{username}
    • GET /desearch/tiktok/profile/{username}
    • GET /desearch/facebook/profile/{profile_id}
    • GET /twitter/user/posts

    Example output

    From sample-output.md in the source folder, a real run on 2026-10-29 with three public brand handles:

    | Handle | instagram | tiktok | x | facebook |
    | --- | --- | --- | --- | --- |
    | desearch_ai | no public profile found | could not check | [found](https://x.com/desearch_ai) | invalid |
    | netflix | [found](https://www.instagram.com/netflix/) | [found](https://www.tiktok.com/@netflix) | [found](https://x.com/netflix) | [found](https://www.facebook.com/netflix) |
    | NASA | [found](https://www.instagram.com/nasa/) | [found](https://www.tiktok.com/@nasa) | [found](https://x.com/NASA) | [found](https://www.facebook.com/NASA) |

    The full sample also lists the display name, follower count and profile link for each found profile, and the reason for each other status.

    Run it yourself

    Get the Python examples and open the username checker folder. Use Python 3.10 or newer; no packages are needed. Create an API key in the console and set DESEARCH_API_KEY, or pass --key-file.

    BASH
    git clone https://github.com/Desearch-ai/desearch-py-examples
    cd desearch-py-examples/username-checker

    These commands are copied from the source README. The dry run prints the planned URLs and maximum calls without a key or network.

    SH
    python3 username_checker.py candidate_one candidate_two
    python3 username_checker.py https://www.instagram.com/candidate_one/ --networks instagram,x
    python3 username_checker.py candidate_one --dry-run

    Use --networks to check fewer networks, --json to print structured results and --from-raw to rebuild the outputs from a saved run with no new calls.

    What it costs

    On 2026-10-29, a found Instagram, TikTok or Facebook profile cost $0.00207 per call, read from the X-Desearch-Cost-Usd header. X user posts cost $0.0027 to $0.00285 per found account. Every not found answer (404) and every TikTok 503 cost $0. Three handles on four networks, 12 calls, cost $0.02097 and took about 10 seconds with parallel calls.

    These are dated measurements, not current price quotes. Use --dry-run to see the planned calls, and check pricing before a larger run.

    Ideas to extend it

    • Check a shortlist of brand name candidates before you pick one.
    • Add a column that links each network's own signup page for handles with no public profile found.
    • Run the checker on a schedule to see when a handle you watch becomes active.
    • Feed found profiles into a profile analytics script for follower details.

    Use with AI agents

    Point an MCP client at the hosted Desearch server. Replace the placeholder with a key from the console. Do not commit the key.

    JSON
    {
      "mcpServers": {
        "desearch": {
          "url": "https://mcp.desearch.ai/mcp",
          "headers": {
            "Authorization": "Bearer <key>"
          }
        }
      }
    }

    Prompt you can paste for this example:

    Build a Python CLI username checker using Desearch. Accept handles or profile URLs, strip @ and validate local format rules before any request. For each handle call GET /desearch/instagram/profile/{username}, GET /desearch/tiktok/profile/{username}, GET /desearch/facebook/profile/{profile_id} and GET /twitter/user/posts?username=<handle> in parallel. Classify each result as found, not_found, could_not_check or invalid. Retry only HTTP 503, once. Print a grid with display names, follower counts and profile links, and write results CSV, grid Markdown and a redacted raw JSON file. Record X-Desearch-Cost-Usd per call. State that no public profile found does not mean the handle is free.

    Build your own example.

    Give your agents access to web and social search. Get an API key to start building, or talk to us about your integration.

    Read docs