Skip to content

Commit

Permalink
Fix Bulk and SecretStr issues (#50)
Browse files Browse the repository at this point in the history
* fix bulk

* update version

* ignore pydantic

* lint

* undo one change
  • Loading branch information
vvillait88 authored May 15, 2023
1 parent 6c69ab7 commit e0c2efe
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
ignore:
- dependency-name: "pydantic"
update-types: ["version-update:semver-major", "version-update:semver-minor", "version-update:semver-patch"]

14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "peopledatalabs"
version = "1.1.4"
version = "1.1.5"
description = "Official Python client for the People Data Labs API"
homepage = "https://www.peopledatalabs.com"
repository = "https://github.com/peopledatalabs/peopledatalabs-python"
Expand Down
2 changes: 1 addition & 1 deletion src/peopledatalabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
from .main import PDLPY


__version__ = "1.1.4"
__version__ = "1.1.5"

__all__ = ["PDLPY"]
3 changes: 1 addition & 2 deletions src/peopledatalabs/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pydantic import (
BaseModel,
HttpUrl,
SecretStr,
StrictStr,
)
from pydantic.dataclasses import dataclass
Expand Down Expand Up @@ -36,7 +35,7 @@ class Endpoint:
API endpoint.
"""

api_key: SecretStr
api_key: str
base_path: HttpUrl
section: str = None

Expand Down
3 changes: 1 addition & 2 deletions src/peopledatalabs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from pydantic import (
HttpUrl,
SecretStr,
constr,
validator,
)
Expand Down Expand Up @@ -42,7 +41,7 @@ class PDLPY:
log_level (:obj:`str`, optional): The logger level.
"""

api_key: SecretStr = settings.api_key
api_key: str = settings.api_key
base_path: HttpUrl = None
version: constr(regex=settings.version_re) = settings.version
log_level: str = None
Expand Down
5 changes: 5 additions & 0 deletions src/peopledatalabs/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BaseModel,
EmailStr,
root_validator,
conint,
validator,
)

Expand Down Expand Up @@ -44,6 +45,10 @@ class PersonBaseModel(BaseModel):
school: Optional[Union[List[str], str]]
street_address: Optional[str]
pdl_id: Optional[str]
min_likelihood: Optional[conint(ge=1, le=10)]
required: Optional[str]
data_include: Optional[str]
include_if_matched: Optional[bool]

@root_validator(pre=True)
def at_least_one(cls, value):
Expand Down
11 changes: 4 additions & 7 deletions src/peopledatalabs/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
from pydantic import (
BaseModel,
HttpUrl,
SecretStr,
)
from pydantic.dataclasses import dataclass
import requests

from . import utils
from .logger import get_logger


Expand All @@ -36,7 +34,7 @@ class Request:
validator: The validator to use to validate params.
"""

api_key: SecretStr
api_key: str
url: HttpUrl
headers: Dict[str, str]
params: dict
Expand All @@ -63,9 +61,8 @@ def get(self):
logger.info(
"Calling %s with params: %s",
self.url,
json.dumps(self.params, indent=2, default=utils.json_defaults),
json.dumps(self.params, indent=2),
)
self.params["api_key"] = self.params["api_key"].get_secret_value()
return requests.get(
self.url, params=self.params, headers=self.headers, timeout=None
)
Expand All @@ -79,11 +76,11 @@ def post(self):
Returns:
A requests.Response object with the result of the HTTP call.
"""
self.headers["X-api-key"] = self.api_key.get_secret_value()
self.headers["X-api-key"] = self.api_key
logger.info(
"Calling %s with params: %s",
self.url,
json.dumps(self.params, indent=2, default=utils.json_defaults),
json.dumps(self.params, indent=2),
)
return requests.post(
self.url, json=self.params, headers=self.headers, timeout=None
Expand Down
4 changes: 2 additions & 2 deletions src/peopledatalabs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os

from dotenv import find_dotenv, load_dotenv
from pydantic import HttpUrl, SecretStr
from pydantic import HttpUrl
from pydantic.dataclasses import dataclass


Expand All @@ -23,7 +23,7 @@ class Settings:
All env variables should be in the form of PDL_<setting name>
"""

api_key: SecretStr = None
api_key: str = None
base_path: HttpUrl = "https://api.peopledatalabs.com/"
log_level: str = None
log_format: str = "{asctime} [{levelname}] - {name}.{funcName}: {message}"
Expand Down
10 changes: 0 additions & 10 deletions src/peopledatalabs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import functools

from pydantic import SecretStr

from .errors import EmptyParametersException


Expand All @@ -22,11 +20,3 @@ def _check(ref, *args, **kwargs):
return func(ref, *args, **kwargs)

return _check


def json_defaults(value):
"""
JSON default callback to serialize different types of data.
"""
mapping = {SecretStr: str}
return mapping[type(value)](value)
2 changes: 1 addition & 1 deletion tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_version():
"""
Version check.
"""
assert __version__ == "1.1.4"
assert __version__ == "1.1.5"


@pytest.mark.usefixtures("fake_api_key")
Expand Down

0 comments on commit e0c2efe

Please sign in to comment.