Skip to content

Proxy Model

swiftshadow.models.Proxy dataclass

Class representing a Proxy object.

Attributes:

Name Type Description
ip str

IP Address of the proxy.

port int

Port associated with the proxy.

protocol Literal['http', 'https']

Protocol type of the proxy.

Source code in swiftshadow/models.py
@dataclass
class Proxy:
    """
    Class representing a Proxy object.

    Attributes:
        ip: IP Address of the proxy.
        port: Port associated with the proxy.
        protocol: Protocol type of the proxy.

    """

    ip: str
    protocol: Literal["http", "https"]
    port: int

    def as_requests_dict(self) -> dict[Literal["http", "https"], str]:
        """
        Return proxy in requests commpatible dict format.

        Returns:
            dict: Dict representation of Proxy class.
        """
        return {self.protocol: f"{self.ip}:{self.port}"}

    def as_string(self) -> str:
        """
        Return proxy in a string of format
        <protocol>://<ip>:<port>

        Returns:
            string: Proxy in string format.
        """
        return f"{self.protocol}://{self.ip}:{self.port}"

as_requests_dict()

Return proxy in requests commpatible dict format.

Returns:

Name Type Description
dict dict[Literal['http', 'https'], str]

Dict representation of Proxy class.

Source code in swiftshadow/models.py
def as_requests_dict(self) -> dict[Literal["http", "https"], str]:
    """
    Return proxy in requests commpatible dict format.

    Returns:
        dict: Dict representation of Proxy class.
    """
    return {self.protocol: f"{self.ip}:{self.port}"}

as_string()

Return proxy in a string of format ://:

Returns:

Name Type Description
string str

Proxy in string format.

Source code in swiftshadow/models.py
def as_string(self) -> str:
    """
    Return proxy in a string of format
    <protocol>://<ip>:<port>

    Returns:
        string: Proxy in string format.
    """
    return f"{self.protocol}://{self.ip}:{self.port}"