• Website
  • Server status
  • API documentation
  • Blog
Telegram Icon Community
EN
English
Português
Русский
中文 (中国)
Tiếng Việt
Log in Try for €3.99
  • Website
  • Server status
  • API documentation
  • Blog
  • Telegram Icon Community
  • English (US)
    English
    Português
    Русский
    中文 (中国)
    Tiếng Việt
Log in View Plans

Custom API scripts with Python

Build powerful automation workflows with Python and the Multilogin API. Create, manage, and launch browser profiles with fully customizable scripts.

search icon

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Getting started with Multilogin X automation
  • Basic automation with CLI
  • Low-code automation with Postman
  • Script runner & predefined scripts
  • Puppeteer, Selenium, and Playwright
  • Custom API scripts with Python
  • Quick solutions in Developer Tools
  • Home
  • breadcrumb separator bar
  • Multilogin X
  • breadcrumb separator bar
  • Task automation with API
  • breadcrumb separator bar
  • Custom API scripts with Python
  • breadcrumb separator bar
  • How to import external proxy lists with Python

How to import external proxy lists with Python

Written by Marcelo B ( Updated on May 2nd, 2025 )

Updated on May 2nd, 2025

In this article, we'll show you how to convert your external proxy lists into API-ready JSON files. This approach allows you to save all your credentials in a convenient JSON format, making it easier to integrate with API endpoints.

Before you start

  1. Ensure you have a Python environment set up with the following packages installed:
    1. json
    2. re
  2. Save the script json_proxy_list in your desired folder 

json_proxy_list

import json
import re

# Input the proxy list path here, if any.
file_path = "C:/Users/.../input_list.txt"

# Paste the proxy list here. Supported separators: comma, bar, space, newline
paste_list = """ 
host:port:username:password
"""

# Reading the proxies from the file path, if any
def read_proxies_from_file(file_path):
    try:
        with open(file_path, 'r') as file:
            return file.read()
    except Exception as e:
        print("Error reading file - please check your file PATH.")
        print(f'Exception found: {e}')
        return

# User input needed: proxy type (HTTP/SOCKS5)
def get_proxy_type():
    print("Enter the proxy type:")
    print("(1) HTTP")
    print("(2) HTTPS")
    print("(3) SOCKS5")
    choose_type = input()

    if choose_type == "1":
        proxy_type = "http"
    elif choose_type == "2":
        proxy_type = "https"
    elif choose_type == "3":
        proxy_type = "socks5"
    else:
        print("Invalid proxy type. Enter a valid option number.")
        return get_proxy_type()
    
    return proxy_type

# Detect line separator from block of credentials
def get_line_separator(proxy_list):
    # Detect the most common line separators
    separators = ['\n', ',', '/', ' ']
    separator_counts = {sep: proxy_list.count(sep) for sep in separators}
    sorted_separators = sorted(separator_counts, key=separator_counts.get, reverse=True)
    most_likely_separator = sorted_separators[0]

    # Handle double values such as '\n,' by checking combinations of common separators
    combined_separators = ['\n,', ',\n', '\n/', '/\n', '\n ', ' \n', ', ', ' ,', '/ ', ' /']
    for combo in combined_separators:
        if combo in proxy_list:
            return combo

    return most_likely_separator

# Main Function - Inputs user for preferred proxy list source
def main():
    # Select proxy list source
    print("Select the list source:")
    print("(1) from TEXT")
    print("(2) from PATH")
    choice = input()
    
    # Take action based on the script source
    if choice == '2':
        proxy_list_content = read_proxies_from_file(file_path)
        if proxy_list_content is None:
            return
    else:
        proxy_list_content = paste_list

    # Check if HTTP/SOCKS5
    proxy_type = get_proxy_type()

    # Split the proxy list based on detected separator
    proxy_lines = re.split(r'[\n, /]+', proxy_list_content.strip())

    # Add the proxy type to each line
    proxy_lines = [f"{proxy_type}:{line.strip()}" for line in proxy_lines if line.strip()]

    # Create JSON object that is similar to API output for easy future integration
    proxies_json = {
        "proxies": {
            "proxy": []
            }
        }

    # For each proxy line contained in the proxy list, take each proxy element to assign it.
    for line in proxy_lines:
        parts = line.split(':')
        if len(parts) != 5:
            print(f"Skipping invalid line: {line}. Please check your proxy credentials file.")
            continue
        proxy = {
            "type": parts[0],
            "host": parts[1],
            "port": parts[2],
            "username": parts[3],
            "password": parts[4]
        }
        proxies_json["proxies"]["proxy"].append(proxy)

    # Create the JSON.dumps, save it on proxies.json file.
    with open('proxies.json', 'w') as json_file:
        json.dump(proxies_json, json_file, indent=2)

    print("File proxies.json was written succesfully.")

if __name__ == "__main__":
    main()
 
 

Running the script

  1. Open your terminal and navigate to the folder containing the script
  2. Run the script json_proxy_list
  1. Choose the proxy details list source you need:
    1. On line 5, paste the .txt file path, or
    2. On line 8, paste the proxy details string
  2. Select the proxy type: external proxy credentials generally don’t include a proxy type, so this will correctly append the type to all proxy lines
  3. Check the results in the file proxies.json stored in the same folder

Was this article helpful?

Give feedback about this article

In this article

  • Before you start
  • json_proxy_list
  • Running the script

Multilogin community

Stay informed, share your thoughts, and engage with others!

Telegram Icon Join us on Telegram

Read more on the topic

Blog Post Img

10 Best Datacenter Proxies for Web Scraping (2025 Edition)

Apr 2, 2025 5 min read
Google SERP Img

What is a Google SERP Proxy and Why Should You Care?

Apr 1, 2025 6 min read
UK Proxy Img

What Are Dedicated UK Proxies? Everything You Need to Know

Apr 1, 2025 6 min read
Related Article Title Icon

Related Articles

  • How to edit the app.properties file
  • How to export proxy details from browser profiles using Python
  • How to retrieve API tokens with Python

ANTIDETECT PLATFORM

  • Antidetect browser
  • Mobile antidetect browser
  • Headless browser
  • Multilogin residential proxies
  • Multi-account management
  • Web automation

RESOURCES

  • Knowledge base
  • API documentation
  • Glossary
  • Blog
  • Multilogin 6 download
  • Server status
  • Release notes

PLATFORM PROXIES

  • Google proxy
  • Facebook proxy
  • Reddit proxy
  • Twitter proxy
  • Amazon proxy
  • LinkedIn proxy

GEO PROXIES

  • Japan proxy
  • UK proxy
  • USA proxy
  • China proxy
  • Canada proxy
  • India proxy

MULTI-ACCOUNT MANAGEMENT

  • Create multiple Facebook accounts
  • Create multiple LinkedIn accounts
  • Create multiple Amazon accounts
  • Create multiple eBay accounts
  • Create multiple Gmail accounts
  • Create multiple Discord accounts

COMPARISON

  • Multilogin vs. Gologin
  • Multilogin vs. Adspower
  • Multilogin vs. Dolphin Anty
  • Multilogin vs. Incognition
  • Multilogin vs. Octo Browser

GET IN TOUCH

  • Contact 24/7 support
    [email protected]
  • Contact sales
  • Affiliate program
  • Careers

© 2025 Multilogin. All rights reserved.

  • Privacy policy
  • Terms of service
  • Cookie policy
Multilogin abstract watermark
  • ANTIDETECT PLATFORM

    • Antidetect browser
    • Mobile antidetect browser
    • Headless browser
    • Multilogin residential proxies
    • Multi-account management
    • Web automation
  • RESOURCES

    • Knowledge base
    • API documentation
    • Glossary
    • Blog
    • Multilogin 6 download
    • Server status
    • Release notes
  • MULTI-ACCOUNT MANAGEMENT

    • Create multiple Facebook accounts
    • Create multiple LinkedIn accounts
    • Create multiple Amazon accounts
    • Create multiple eBay accounts
    • Create multiple Gmail accounts
    • Create multiple Discord accounts
  • COMPARISON

    • Multilogin vs. Gologin
    • Multilogin vs. Adspower
    • Multilogin vs. Dolphin Anty
    • Multilogin vs. Incognition
    • Multilogin vs. Octo Browser
  • PLATFORM PROXIES

    • Google proxy
    • Facebook proxy
    • Reddit proxy
    • Twitter proxy
    • Amazon proxy
    • LinkedIn proxy
  • GEO PROXIES

    • Japan proxy
    • UK proxy
    • USA proxy
    • China proxy
    • Canada proxy
    • India proxy
  • GET IN TOUCH

    • 24/7 support: [email protected]
    • Contact sales
    • Affiliate program
    • Careers
Multilogin abstract watermark
  • Privacy policy
  • Terms of service
  • Cookie policy

© 2025 Multilogin. All rights reserved.

Expand