Skip to main content

Apifreaks Python SDK

fern shield pypi shield python shield

The Apifreaks Python library provides convenient access to the Apifreaks APIs from Python applications.

Table of Contents

Installation

Install the package from PyPI:

pip install apifreaks

Or add it with Poetry:

poetry add apifreaks

Or add it with uv:

uv add apifreaks

The package supports Python >=3.8.

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

import os

from apifreaks import ApifreaksApi
from apifreaks.core.api_error import ApiError

client = ApifreaksApi()

try:
    response = client.geolocation_lookup(
        api_key=os.environ["APIFREAKS_API_KEY"],
        ip="8.8.8.8",
    )
    print(response)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Example domain WHOIS lookup:

import os

from apifreaks import ApifreaksApi
from apifreaks.core.api_error import ApiError

client = ApifreaksApi()

try:
    response = client.domain_whois_lookup(
        api_key=os.environ["APIFREAKS_API_KEY"],
        domain_name="example.com",
    )
    print(response)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Example bulk geolocation lookup:

import os

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.bulk_geolocation_lookup(
    api_key=os.environ["APIFREAKS_API_KEY"],
    ips=["8.8.8.8", "1.1.1.1"],
)

print(response)

Async Usage

The SDK also provides an async client:

import asyncio
import os

from apifreaks import AsyncApifreaksApi
from apifreaks.core.api_error import ApiError

async def main() -> None:
    client = AsyncApifreaksApi()

    try:
        response = await client.geolocation_lookup(
            api_key=os.environ["APIFREAKS_API_KEY"],
            ip="8.8.8.8",
        )
        print(response)
    except ApiError as e:
        print(e.status_code)
        print(e.body)

asyncio.run(main())

Environments

This SDK allows you to configure the API environment for requests.

from apifreaks import ApifreaksApi
from apifreaks.environment import ApifreaksApiEnvironment

client = ApifreaksApi(
    environment=ApifreaksApiEnvironment.DEFAULT,
)

You can also override the base URL directly:

from apifreaks import ApifreaksApi

client = ApifreaksApi(
    base_url="https://api.apifreaks.com",
)

Errors

When the API returns a non-success status code, the SDK raises an API error.

from apifreaks import ApifreaksApi
from apifreaks.core.api_error import ApiError

client = ApifreaksApi()

try:
    response = client.geolocation_lookup(
        api_key="your_api_key",
        ip="8.8.8.8",
    )
    print(response)
except ApiError as e:
    print(f"Status code: {e.status_code}")
    print(f"Response body: {e.body}")

Request Types

The SDK exports generated request and response types from the apifreaks package.

from apifreaks import GeolocationLookupResponse

# Returned from client.geolocation_lookup(...)
response: GeolocationLookupResponse

Most endpoints accept keyword arguments directly, so you usually do not need to manually instantiate request objects.

Advanced

Retries

The SDK is instrumented with automatic retries. By default, failed requests are retried up to 2 times when the request is considered retryable.

You can configure retries globally on the client:

from apifreaks import ApifreaksApi

client = ApifreaksApi(max_retries=3)

You can also configure retries for a single request:

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.geolocation_lookup(
    api_key="your_api_key",
    ip="8.8.8.8",
    request_options={"max_retries": 3},
)

Timeouts

The SDK defaults to a 60 second timeout.

Configure the timeout globally:

from apifreaks import ApifreaksApi

client = ApifreaksApi(timeout=30)

Configure the timeout for a single request:

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.geolocation_lookup(
    api_key="your_api_key",
    ip="8.8.8.8",
    request_options={"timeout_in_seconds": 30},
)

Additional Headers

You can add custom headers to a request using request_options.

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.geolocation_lookup(
    api_key="your_api_key",
    ip="8.8.8.8",
    request_options={
        "additional_headers": {
            "X-Custom-Header": "custom-value",
        },
    },
)

Additional Query String Parameters

You can add custom query parameters using request_options.

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.geolocation_lookup(
    api_key="your_api_key",
    ip="8.8.8.8",
    request_options={
        "additional_query_parameters": {
            "filter": "active",
        },
    },
)

Raw Responses

Use with_raw_response when you need access to raw response metadata.

from apifreaks import ApifreaksApi

client = ApifreaksApi()

response = client.with_raw_response.geolocation_lookup(
    api_key="your_api_key",
    ip="8.8.8.8",
)

print(response.status_code)
print(response.headers)
print(response.data)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Metadata

Release files for apifreaks 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apifreaks 1.1.1
File Size Uploaded Provenance
apifreaks-1.1.1.tar.gz 333.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apifreaks 1.1.1
File Interpreter ABI Platform
apifreaks-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / apifreaks-1.1.1.tar.gz

Download URL apifreaks-1.1.1.tar.gz
Size 333.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5500293a75af34893c78013cc350ba2a5183c6e635800291eebe8d6c587596f3
BLAKE2b-256 checksum
How to use checksums
e445c92225b09c3f3e97168915d5d491cd1396007915307f1a6f64cb9f24915c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.13.15 Linux/6.17.0-1022-azure

Release files / apifreaks-1.1.1-py3-none-any.whl

Download URL apifreaks-1.1.1-py3-none-any.whl
Size 765.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c21d24328e249680fc5fd224443c728b7a4ac0e0665443dc64f8701733d987a1
BLAKE2b-256 checksum
How to use checksums
c25ab4268c93271bfefb34b963fb1fb4ee93b43868c79699a12fdcb31b005377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.13.15 Linux/6.17.0-1022-azure

Security for apifreaks 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page