This example demonstrates how to export all your static proxies (datacenter and ISP types) to a formatted list using the dedicated list endpoint. The list_by_search endpoint is specifically designed for exporting proxies in various formats, making it more efficient than manually formatting proxies from the search endpoint.

import requests
import os
from datetime import datetime

# API credentials
API_PUBLIC_KEY = "your_public_key"
API_PRIVATE_KEY = "your_private_key"
BASE_URL = "https://api.pingproxies.com/1.0/public"

# Headers for authentication
headers = {
    "X-API-Public-Key": API_PUBLIC_KEY,
    "X-API-Private-Key": API_PRIVATE_KEY
}

def get_static_proxy_list():
    """
    Retrieve all static proxies using the list_by_search endpoint.
    
    Note: You can modify format_type and protocol parameters to get different formats:
    - format_type options: "standard", "http", "socks5", "socks5h"
    - protocol options: "http" or "socks5"
    
    Returns:
        List of formatted proxy strings
    """
    # Set up the parameters for list_by_search
    params = {
        "list_format": "standard",  # You can change this to "http", "socks5", or "socks5h"
        "list_protocol": "http",    # You can change this to "socks5"
        "list_version": "ipv4",     # IP version (ipv4 or ipv6)
        "list_authentication": "username_and_password"  # Authentication type
    }
    
    # Make request to the list_by_search endpoint
    response = requests.get(
        f"{BASE_URL}/user/proxy/list_by_search",
        params=params,
        headers=headers
    )
    
    if response.status_code != 200:
        print(f"Error: {response.status_code}")
        return []
    
    data = response.json()
    
    # The list endpoint returns the formatted proxies directly in data
    proxy_list = data["data"]
    
    print(f"Successfully retrieved {len(proxy_list)} formatted proxies")
    return proxy_list

def export_to_file(proxy_list):
    """Export proxy list to a file."""
    # Create a default filename with timestamp
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"proxies_{timestamp}.txt"
    
    # Write the proxy list to a file
    with open(filename, "w") as file:
        for proxy in proxy_list:
            file.write(f"{proxy}\n")
    
    print(f"Exported {len(proxy_list)} proxies to {filename}")
    return filename

# Example usage
if __name__ == "__main__":
    # Get proxies in standard format
    proxy_list = get_static_proxy_list()
    
    # Export to file
    if proxy_list:
        export_to_file(proxy_list)
    
    # Print sample output
    if proxy_list:
        print(f"\nSample output: {proxy_list[0]}")

Understanding the List Endpoint

The list_by_search endpoint provides formatted proxy strings ready for use in your applications. It focuses only on static proxies (datacenter and ISP types), which are designed to have stable IP addresses and ports.

Key Parameters

  • list_format: Determines how the proxies are formatted in the response

    • standard: Simple format (IP:port)
    • http: HTTP proxy URL format (http://username:password@IP:port)
    • socks5: SOCKS5 proxy URL format (socks5://username:password@IP:port)
    • socks5h: SOCKS5 with hostname resolution (socks5h://username:password@IP:port)
  • list_protocol: Specifies which proxy protocol to use

    • http: For HTTP proxies (default port 8080)
    • socks5: For SOCKS5 proxies (default port 1080)
  • list_version: Specifies the IP version to return

    • ipv4: IPv4 addresses (default)
    • ipv6: IPv6 addresses (if available)
  • list_authentication: Authentication method to use in the formatted strings

    • username_and_password: Standard authentication with your proxy user credentials
    • ip_address: IP-based authentication
    • proxy_specific: Proxy-specific authentication

Example Output

Here’s what the output might look like depending on the format you choose:

  • Standard format: 123.456.78.90:8080
  • HTTP format: http://your_username:your_password@123.456.78.90:8080
  • SOCKS5 format: socks5://your_username:your_password@123.456.78.90:1080
  • SOCKS5H format: socks5h://your_username:your_password@123.456.78.90:1080

Use Cases

  • Web scraping tools: Export proxy lists for tools like Scrapy or Selenium
  • Browser extensions: Use formatted proxies in proxy-switching extensions
  • Distributed applications: Share proxy lists with team members
  • Third-party tools: Export proxies for use in tools that require proxy lists