This example demonstrates how to export a formatted list of proxies from a specific service using the list_by_search endpoint with filtering parameters. Unlike the basic search, this endpoint returns ready-to-use proxy strings in your desired format.

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 export_service_proxies(service_id):
    """
    Export a formatted list of proxies from a specific service.
    
    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"
    
    Args:
        service_id: ID of the service to export proxies from
        
    Returns:
        List of formatted proxy strings
    """
    # Set up the parameters for list_by_search
    params = {
        "service_id": service_id,
        "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
        "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}")
        print(response.text)
        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 from service {service_id}")
    return proxy_list

def export_to_file(proxy_list, service_id):
    """Export proxy list to a file."""
    # Create a default filename with timestamp
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"service_{service_id}_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__":
    # Replace with your actual service ID
    SERVICE_ID = "API-1234-5678"
    
    # Get proxies
    proxy_list = export_service_proxies(SERVICE_ID)
    
    # Export to file
    if proxy_list:
        export_to_file(proxy_list, SERVICE_ID)
    
    # Print sample output
    if proxy_list:
        print(f"\nSample output: {proxy_list[0]}")

Understanding the List Formats

When exporting proxies, you can choose from several different formats:

FormatExampleDescription
standard123.456.78.90:8080Basic format with IP:port only
httphttp://username:password@123.456.78.90:8080HTTP proxy URL format
socks5socks5://username:password@123.456.78.90:1080SOCKS5 proxy URL format
socks5hsocks5h://username:password@123.456.78.90:1080SOCKS5 with hostname resolution

Authentication Types

You can also specify the authentication method in your export:

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

Use Cases

  • Web scraping tools: Export proxy lists for tools like Scrapy, Selenium, or Puppeteer
  • Browser extensions: Generate proxy configurations for proxy-switching extensions
  • Third-party integration: Create formatted proxy lists for third-party applications
  • Team sharing: Export proxy lists to share with team members