or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/googletrans@4.0.x
tile.json

tessl/pypi-googletrans

tessl install tessl/pypi-googletrans@4.0.0

An unofficial Google Translate API for Python providing free text translation and language detection capabilities

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.01x

Baseline

Agent success rate without this tile

99%

task.mdevals/scenario-4/

Translation Service with Proxy Support

Build a Python translation service that can operate behind corporate proxies with authentication requirements.

@generates

Requirements

Your service should:

  1. Support multiple proxy configurations: unauthenticated proxies and proxies requiring basic authentication
  2. Translate text from one language to another through the configured proxy
  3. Allow switching between different proxy configurations at runtime
  4. Handle both HTTP and HTTPS proxy schemes appropriately

Implementation Details

Create a TranslatorService class that:

  • Initializes with a proxy configuration (can be a simple URL string or a dict with scheme-specific proxies)
  • Provides a method to translate text from a source language to a destination language
  • Provides a method to update the proxy configuration
  • Uses proper async context management for resource cleanup

The service should work with various proxy formats including:

  • Simple string URLs: "http://proxy.company.com:8080"
  • Dictionary-based configurations with different proxies for HTTP and HTTPS
  • Proxies with authentication credentials

Test Cases

Basic proxy configuration { .tests }

  • Creating a TranslatorService with a simple proxy URL string "http://proxy.example.com:8080" and translating "hello" to Spanish returns translated text @test

Authenticated proxy configuration { .tests }

  • Creating a TranslatorService with an authenticated proxy (using httpx.Proxy with auth tuple) and translating "good morning" to French returns translated text @test

Dictionary-based proxy configuration { .tests }

  • Creating a TranslatorService with a dict-based proxy configuration (separate HTTP and HTTPS proxies) and translating "thank you" to German returns translated text @test

Updating proxy configuration { .tests }

  • Creating a TranslatorService with one proxy, then updating to a different proxy configuration, and successfully translating text confirms the proxy was updated @test

API

from typing import Union, Dict
from httpx import Proxy

class TranslatorService:
    """Translation service that operates through configured proxies."""

    def __init__(self, proxy: Union[str, Dict[str, str], Proxy]):
        """
        Initialize the translator service with proxy configuration.

        Args:
            proxy: Proxy configuration - can be:
                - String URL: "http://proxy.com:8080"
                - Dict with scheme keys: {"http://": "...", "https://": "..."}
                - httpx.Proxy object with authentication
        """
        pass

    async def translate(self, text: str, dest: str = 'en', src: str = 'auto') -> str:
        """
        Translate text through the configured proxy.

        Args:
            text: Text to translate
            dest: Destination language code
            src: Source language code (default: 'auto' for auto-detection)

        Returns:
            Translated text
        """
        pass

    def update_proxy(self, proxy: Union[str, Dict[str, str], Proxy]):
        """
        Update the proxy configuration.

        Args:
            proxy: New proxy configuration in any supported format
        """
        pass

    async def __aenter__(self):
        """Async context manager entry."""
        pass

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        """Async context manager exit."""
        pass

Dependencies { .dependencies }

googletrans { .dependency }

Provides translation capabilities with proxy support.

@satisfied-by