|
| 1 | +# Whoisfreaks Python Library |
| 2 | + |
| 3 | +[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FWhoisFreaks%2Fwf-python-sdk) |
| 4 | +[](https://pypi.python.org/pypi/py-whoisfreaks) |
| 5 | + |
| 6 | +The Whoisfreaks Python library provides convenient access to the Whoisfreaks API from Python. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +```sh |
| 11 | +pip install py-whoisfreaks |
| 12 | +``` |
| 13 | + |
| 14 | +## Reference |
| 15 | + |
| 16 | +A full reference for this library is available [here](./reference.md). |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Instantiate and use the client with the following: |
| 21 | + |
| 22 | +```python |
| 23 | +from whoisfreaks import WhoisfreaksApi |
| 24 | +from whoisfreaks.environment import WhoisfreaksApiEnvironment |
| 25 | +client = WhoisfreaksApi(environment=WhoisfreaksApiEnvironment.PRODUCTION, ) |
| 26 | +client.dns.bulk_dns_lookup(api_key='YOUR_API_KEY', type='all', format='json', domain_names=['whoisfreaks.com', 'jfreaks.com'], ip_addresses=['1.1.1.1', '8.8.8.8'], ) |
| 27 | +``` |
| 28 | + |
| 29 | +## Async Client |
| 30 | + |
| 31 | +The SDK also exports an `async` client so that you can make non-blocking calls to our API. |
| 32 | + |
| 33 | +```python |
| 34 | +from whoisfreaks import AsyncWhoisfreaksApi |
| 35 | +from whoisfreaks.environment import WhoisfreaksApiEnvironment |
| 36 | +import asyncio |
| 37 | +client = AsyncWhoisfreaksApi(environment=WhoisfreaksApiEnvironment.PRODUCTION, ) |
| 38 | +async def main() -> None: |
| 39 | + await client.dns.bulk_dns_lookup(api_key='YOUR_API_KEY', type='all', format='json', domain_names=['whoisfreaks.com', 'jfreaks.com'], ip_addresses=['1.1.1.1', '8.8.8.8'], ) |
| 40 | +asyncio.run(main())``` |
| 41 | + |
| 42 | +## Exception Handling |
| 43 | + |
| 44 | +When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error |
| 45 | +will be thrown. |
| 46 | + |
| 47 | +```python |
| 48 | +from whoisfreaks.core.api_error import ApiError |
| 49 | +try: |
| 50 | + client.dns.bulk_dns_lookup(...) |
| 51 | +except ApiError as e: |
| 52 | + print(e.status_code) |
| 53 | + print(e.body) |
| 54 | +``` |
| 55 | + |
| 56 | +## Advanced |
| 57 | + |
| 58 | +### Access Raw Response Data |
| 59 | + |
| 60 | +The SDK provides access to raw response data, including headers, through the `.with_raw_response` property. |
| 61 | +The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes. |
| 62 | + |
| 63 | +```python |
| 64 | +from whoisfreaks import WhoisfreaksApi |
| 65 | +client = WhoisfreaksApi(..., ) |
| 66 | +response = client.dns.with_raw_response.bulk_dns_lookup(...) |
| 67 | +print(response.headers) # access the response headers |
| 68 | +print(response.data) # access the underlying object |
| 69 | +``` |
| 70 | + |
| 71 | +### Retries |
| 72 | + |
| 73 | +The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long |
| 74 | +as the request is deemed retryable and the number of retry attempts has not grown larger than the configured |
| 75 | +retry limit (default: 2). |
| 76 | + |
| 77 | +A request is deemed retryable when any of the following HTTP status codes is returned: |
| 78 | + |
| 79 | +- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) |
| 80 | +- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) |
| 81 | +- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) |
| 82 | + |
| 83 | +Use the `max_retries` request option to configure this behavior. |
| 84 | + |
| 85 | +```python |
| 86 | +client.dns.bulk_dns_lookup(..., request_options={ |
| 87 | + "max_retries": 1 |
| 88 | +}) |
| 89 | +``` |
| 90 | + |
| 91 | +### Timeouts |
| 92 | + |
| 93 | +The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level. |
| 94 | + |
| 95 | +```python |
| 96 | + |
| 97 | +from whoisfreaks import WhoisfreaksApi |
| 98 | +client = WhoisfreaksApi(..., timeout=20.0, ) |
| 99 | + |
| 100 | +# Override timeout for a specific method |
| 101 | +client.dns.bulk_dns_lookup(..., request_options={ |
| 102 | + "timeout_in_seconds": 1 |
| 103 | +}) |
| 104 | +``` |
| 105 | + |
| 106 | +### Custom Client |
| 107 | + |
| 108 | +You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies |
| 109 | +and transports. |
| 110 | + |
| 111 | +```python |
| 112 | +from whoisfreaks import WhoisfreaksApi |
| 113 | +import httpx |
| 114 | +client = WhoisfreaksApi(..., httpx_client=httpx.Client(proxies="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0"), ))``` |
| 115 | + |
| 116 | +## Contributing |
| 117 | + |
| 118 | +While we value open-source contributions to this SDK, this library is generated programmatically. |
| 119 | +Additions made directly to this library would have to be moved over to our generation code, |
| 120 | +otherwise they would be overwritten upon the next generated release. Feel free to open a PR as |
| 121 | +a proof of concept, but know that we will not be able to merge it as-is. We suggest opening |
| 122 | +an issue first to discuss with us! |
| 123 | + |
| 124 | +On the other hand, contributions to the README are always very welcome! |
0 commit comments