Skip to content

Commit 0ab7751

Browse files
check the 'IPDATA_API_KEY' environment variable for the API key if set
1 parent 64585aa commit 0ab7751

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ipdata/ipdata.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:class:`~.IPData` is the primary class for making API requests.
1919
"""
2020

21+
import os
2122
import ipaddress
2223
import requests
2324
import logging
@@ -99,13 +100,15 @@ class IPData(object):
99100

100101
def __init__(
101102
self,
102-
api_key,
103+
api_key=os.environ.get("IPDATA_API_KEY"),
103104
endpoint="https://api.ipdata.co/",
104105
timeout=60,
105106
retry_limit=7,
106107
retry_backoff_factor=1,
107108
debug=False,
108109
):
110+
if not api_key:
111+
raise IPDataException("API Key not set. Set an API key via the 'IPDATA_API_KEY' environment variable or see the docs for other ways to do so.")
109112
# Request settings
110113
self.api_key = api_key
111114
self.endpoint = endpoint.rstrip("/") # remove trailing /

0 commit comments

Comments
 (0)