Skip to content

Commit b2bac3d

Browse files
authored
Remove dotenv load (#151)
* remove autoload of env variable * update docstrings * remove dependency * format * dependencies
1 parent 8bc0917 commit b2bac3d

11 files changed

+26
-70
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [📘 Documentation](#documentation)
2929
- [Upgrading to v2.X.X](#upgrading-to-v2)
3030
- [Upgrading to v3.X.X](#upgrading-to-v3)
31+
- [Upgrading to v4.X.X](#upgrading-to-v4)
3132

3233

3334
## 🔧 Installation <a name="installation"></a>
@@ -39,7 +40,6 @@
3940
```
4041

4142
2. Sign up for a [free PDL API key](https://www.peopledatalabs.com/signup).
42-
3. Set your API key in the `PDL_API_KEY` environment variable.
4343

4444
## 🚀 Usage <a name="usage"></a>
4545

@@ -49,17 +49,13 @@ First, create the PDLPY client:
4949
from peopledatalabs import PDLPY
5050
5151
52-
# specifying an API key
52+
# specify your API key
5353
client = PDLPY(
5454
api_key="YOUR API KEY",
5555
)
5656
57-
# or leave blank if you have PDL_API_KEY set in your environment or .env file
58-
client = PDLPY()
5957
```
6058

61-
**Note:** You can provide your API key directly in code, or alternatively set a `PDL_API_KEY` variable in your environment or `.env` file.
62-
6359
Then, send requests to any PDL API Endpoint.
6460

6561
### Getting Person Data
@@ -499,3 +495,7 @@ NOTE: When upgrading to v2.X.X from vX.X.X and below, the minimum required pytho
499495
### Upgrading to v3.X.X <a name="upgrading-to-v3"></a>
500496
501497
NOTE: When upgrading to v3.X.X from vX.X.X and below, the minimum required pydantic version is now 2.
498+
499+
### Upgrading to v4.X.X <a name="upgrading-to-v4"></a>
500+
501+
NOTE: When upgrading to v4.X.X from vX.X.X and below, we no longer auto load the API key from the environment variable `PDL_API_KEY`. You must now pass the API key as a parameter to the `PDLPY` class.

poetry.lock

+4-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "peopledatalabs"
3-
version = "3.1.4"
3+
version = "4.0.0"
44
description = "Official Python client for the People Data Labs API"
55
homepage = "https://www.peopledatalabs.com"
66
repository = "https://github.com/peopledatalabs/peopledatalabs-python"
@@ -31,7 +31,6 @@ classifiers = [
3131
python = "^3.8"
3232
email-validator = ">=1.1,<3.0"
3333
pydantic = "^2"
34-
python-dotenv = "<2"
3534
requests = "^2"
3635

3736
[tool.poetry.dev-dependencies]
@@ -41,7 +40,7 @@ coverage = "^7.5.3"
4140
docformatter = "^1.7"
4241
flake8 = "^5.0.4"
4342
pylint = "^3.2.6"
44-
pytest = "^8.3.1"
43+
pytest = "^8.3.2"
4544
pyupgrade = "^3.3.2"
4645

4746
[build-system]

requirements.txt

-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ pydantic-core==2.20.1 ; python_version >= "3.8" and python_version < "4.0" \
197197
pydantic==2.8.2 ; python_version >= "3.8" and python_version < "4.0" \
198198
--hash=sha256:6f62c13d067b0755ad1c21a34bdd06c0c12625a22b0fc09c6b149816604f7c2a \
199199
--hash=sha256:73ee9fddd406dc318b885c7a2eab8a6472b68b8fb5ba8150949fc3db939f23c8
200-
python-dotenv==1.0.1 ; python_version >= "3.8" and python_version < "4.0" \
201-
--hash=sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca \
202-
--hash=sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a
203200
requests==2.32.3 ; python_version >= "3.8" and python_version < "4.0" \
204201
--hash=sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760 \
205202
--hash=sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6

requirements_dev.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,9 @@ pyflakes==2.5.0 ; python_version >= "3.8" and python_version < "4.0" \
330330
pylint==3.2.6 ; python_version >= "3.8" and python_version < "4.0" \
331331
--hash=sha256:03c8e3baa1d9fb995b12c1dbe00aa6c4bcef210c2a2634374aedeb22fb4a8f8f \
332332
--hash=sha256:a5d01678349454806cff6d886fb072294f56a58c4761278c97fb557d708e1eb3
333-
pytest==8.3.1 ; python_version >= "3.8" and python_version < "4.0" \
334-
--hash=sha256:7e8e5c5abd6e93cb1cc151f23e57adc31fcf8cfd2a3ff2da63e23f732de35db6 \
335-
--hash=sha256:e9600ccf4f563976e2c99fa02c7624ab938296551f280835ee6516df8bc4ae8c
336-
python-dotenv==1.0.1 ; python_version >= "3.8" and python_version < "4.0" \
337-
--hash=sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca \
338-
--hash=sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a
333+
pytest==8.3.2 ; python_version >= "3.8" and python_version < "4.0" \
334+
--hash=sha256:4ba08f9ae7dcf84ded419494d229b48d0903ea6407b030eaec46df5e6a73bba5 \
335+
--hash=sha256:c132345d12ce551242c87269de812483f5bcc87cdbb4722e48487ba194f9fdce
339336
pyupgrade==3.8.0 ; python_version >= "3.8" and python_version < "4.0" \
340337
--hash=sha256:08d0e6129f5e9da7e7a581bdbea689e0d49c3c93eeaf156a07ae2fd794f52660 \
341338
--hash=sha256:1facb0b8407cca468dfcc1d13717e3a85aa37b9e6e7338664ad5bfe5ef50c867

src/peopledatalabs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from .main import PDLPY
66

77

8-
__version__ = "3.1.4"
8+
__version__ = "4.0.0"
99

1010
__all__ = ["PDLPY"]

src/peopledatalabs/main.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ def api_key_not_none(cls, v):
5252
Checks an API key is passed to the Client object.
5353
"""
5454
if v is None:
55-
raise ValueError(
56-
"Please enter a value for API key, or define it either in"
57-
" your environment or .env file as PDL_API_KEY"
58-
)
55+
raise ValueError("Please enter a value for API key.")
5956
return v
6057

6158
def __post_init__(self):

src/peopledatalabs/requests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get(self):
5151
"""
5252
Executes a GET request from the specified API.
5353
54-
User's PDL_API_KEY is sent in request parameters.
54+
User's api_key is sent in request parameters.
5555
5656
Returns:
5757
A requests.Response object with the result of the HTTP call.
@@ -70,7 +70,7 @@ def post(self):
7070
"""
7171
Executes a POST request to the specified API.
7272
73-
User's PDL_API_KEY is sent as a 'X-api-key' header.
73+
User's api_key is sent as a 'X-api-key' header.
7474
7575
Returns:
7676
A requests.Response object with the result of the HTTP call.

src/peopledatalabs/settings.py

-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
"""
22
A settings singleton to share settings across different modules of the package.
3-
4-
Settings also loads environment variables eventually declared in an .env
5-
file.
63
"""
74

8-
import os
9-
10-
from dotenv import find_dotenv, load_dotenv
115
from pydantic.v1 import HttpUrl
126
from pydantic.v1.dataclasses import dataclass
137

@@ -16,11 +10,6 @@
1610
class Settings:
1711
"""
1812
Singleton holding app's settings.
19-
20-
Settings are eventually overridden if a .env file is provided, or
21-
environment variables are defined.
22-
23-
All env variables should be in the form of PDL_<setting name>
2413
"""
2514

2615
api_key: str = None
@@ -31,11 +20,5 @@ class Settings:
3120
version_re: str = r"^v[0-9]$"
3221
sandbox_base_path: HttpUrl = "https://sandbox.api.peopledatalabs.com/"
3322

34-
def __post_init__(self):
35-
load_dotenv(dotenv_path=find_dotenv(usecwd=True))
36-
for key in self.__dict__:
37-
env_key = "PDL_" + key.upper()
38-
self.__dict__[key] = os.getenv(env_key, self.__dict__[key])
39-
4023

4124
settings = Settings()

tests/client/test_client.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_version():
1919
"""
2020
Version check.
2121
"""
22-
assert __version__ == "3.1.4"
22+
assert __version__ == "4.0.0"
2323

2424

2525
@pytest.mark.usefixtures("fake_api_key")
@@ -59,11 +59,8 @@ def test_init_defaults_version_only(fake_api_key):
5959

6060
def test_init_no_api_key_raises_validation_error():
6161
"""
62-
Tests that instantiating the client without providing either an .env file
63-
or an api key explicitly, a ValidationError is raised.
64-
65-
To make this test pass either ".env" file should not exist or
66-
env_file modified in get_settings()
62+
Tests that instantiating the client without providing an api key
63+
explicitly, a ValidationError is raised.
6764
"""
6865
with pytest.raises(ValidationError):
6966
PDLPY()

tests/conftest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def fixture_fake_api_key():
2626
@pytest.fixture
2727
def client():
2828
"""
29-
Client instance loads PDL_API_KEY from .env file.
29+
Client instance loads with real API key.
3030
"""
31-
return PDLPY()
31+
return PDLPY(api_key=os.environ["PDL_API_KEY"])
3232

3333

3434
@pytest.fixture
@@ -42,9 +42,9 @@ def client_with_fake_api_key(fake_api_key):
4242
@pytest.fixture
4343
def client_sandbox_enabled():
4444
"""
45-
Client instance loads PDL_API_KEY from .env file and Sandbox enabled.
45+
Client instance loads with real API key and Sandbox enabled.
4646
"""
47-
return PDLPY(sandbox=True)
47+
return PDLPY(sandbox=True, api_key=os.environ["PDL_API_KEY"])
4848

4949

5050
@pytest.fixture

0 commit comments

Comments
 (0)