Skip to content

🔒 SSL

SSL certificate retrieval operations.

🚀 Quick Example

from oinker import AsyncPiglet

async with AsyncPiglet() as piglet:
    bundle = await piglet.ssl.retrieve("example.com")

    # Save the certificate chain
    with open("cert.pem", "w") as f:
        f.write(bundle.certificate_chain)

    # Save the private key
    with open("key.pem", "w") as f:
        f.write(bundle.private_key)

    # Public key is also available
    print(bundle.public_key)

Free SSL Certificates

Porkbun provides free SSL certificates for domains using their nameservers. The certificates are issued by Let's Encrypt and auto-renew.

Operations

AsyncSSLAPI

oinker.ssl.AsyncSSLAPI

AsyncSSLAPI(http: HttpClient)

Async SSL operations for the Porkbun API.

Accessed via piglet.ssl.* methods.

Initialize SSL API.

Parameters:

Name Type Description Default
http HttpClient

The HTTP client for making requests.

required
Source code in src/oinker/ssl/_api.py
def __init__(self, http: HttpClient) -> None:
    """Initialize SSL API.

    Args:
        http: The HTTP client for making requests.
    """
    self._http = http

retrieve async

retrieve(domain: str) -> SSLBundle

Retrieve the SSL certificate bundle for a domain.

Parameters:

Name Type Description Default
domain str

The domain name (e.g., "example.com").

required

Returns:

Type Description
SSLBundle

SSLBundle containing certificate chain, private key, and public key.

Raises:

Type Description
AuthenticationError

If credentials are invalid.

NotFoundError

If domain is not found or has no SSL certificate.

APIError

If the request fails.

Source code in src/oinker/ssl/_api.py
async def retrieve(self, domain: str) -> SSLBundle:
    """Retrieve the SSL certificate bundle for a domain.

    Args:
        domain: The domain name (e.g., "example.com").

    Returns:
        SSLBundle containing certificate chain, private key, and public key.

    Raises:
        AuthenticationError: If credentials are invalid.
        NotFoundError: If domain is not found or has no SSL certificate.
        APIError: If the request fails.
    """
    data = await self._http.post(f"/ssl/retrieve/{domain}")
    return SSLBundle.from_api_response(data)

SyncSSLAPI

oinker.ssl.SyncSSLAPI

SyncSSLAPI(
    async_api: AsyncAPIType, runner: Callable[..., Any]
)

Bases: SyncAPIBase['AsyncSSLAPI']

Synchronous SSL operations for the Porkbun API.

Accessed via piglet.ssl.* methods.

Source code in src/oinker/_sync_base.py
def __init__(
    self,
    async_api: AsyncAPIType,
    runner: Callable[..., Any],
) -> None:
    self._async_api = async_api
    self._run = runner

retrieve

retrieve(domain: str) -> SSLBundle

See :meth:AsyncSSLAPI.retrieve.

Source code in src/oinker/ssl/_sync.py
def retrieve(self, domain: str) -> SSLBundle:
    """See :meth:`AsyncSSLAPI.retrieve`."""
    return self._run(self._async_api.retrieve(domain))

Types

SSLBundle

oinker.SSLBundle dataclass

SSLBundle(
    certificate_chain: str,
    private_key: str,
    public_key: str,
)

SSL certificate bundle for a domain.

Attributes:

Name Type Description
certificate_chain str

The complete certificate chain (PEM format).

private_key str

The private key (PEM format).

public_key str

The public key (PEM format).

from_api_response classmethod

from_api_response(data: dict[str, Any]) -> SSLBundle

Create from API response data.

Parameters:

Name Type Description Default
data dict[str, Any]

The API response dictionary.

required

Returns:

Type Description
SSLBundle

An SSLBundle instance.

Source code in src/oinker/ssl/_types.py
@classmethod
def from_api_response(cls, data: dict[str, Any]) -> SSLBundle:
    """Create from API response data.

    Args:
        data: The API response dictionary.

    Returns:
        An SSLBundle instance.
    """
    return cls(
        certificate_chain=data.get("certificatechain", ""),
        private_key=data.get("privatekey", ""),
        public_key=data.get("publickey", ""),
    )