Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v10.4.0 (2026-02-03)

- Adds the following functions usable by child and referral customer users:
- `api_key.create`
- `api_key.delete`
- `api_key.enable`
- `api_key.disable`

## v10.3.0 (2025-11-24)

- Adds the following functions:
Expand Down
2 changes: 1 addition & 1 deletion easypost/constant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa
# Library version
VERSION = "10.3.0"
VERSION = "10.4.0"
VERSION_INFO = [str(number) for number in VERSION.split(".")]

# Client defaults
Expand Down
54 changes: 39 additions & 15 deletions easypost/services/api_key_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from typing import (
Any,
)
from typing import Any

from easypost.constant import NO_USER_FOUND
from easypost.easypost_object import convert_to_easypost_object
from easypost.errors import FilteringError
from easypost.models import ApiKey
from easypost.requestor import (
RequestMethod,
Requestor,
)
from easypost.requestor import RequestMethod, Requestor
from easypost.services.base_service import BaseService


Expand All @@ -18,14 +13,6 @@ def __init__(self, client):
self._client = client
self._model_class = ApiKey.__name__

def all(self) -> dict[str, Any]:
"""Retrieve a list of all API keys."""
url = "/api_keys"

response = Requestor(self._client).request(method=RequestMethod.GET, url=url)

return convert_to_easypost_object(response=response)

def retrieve_api_keys_for_user(self, id: str) -> list[ApiKey]:
"""Retrieve a list of API keys (works for the authenticated User or a child User)."""
api_keys = self.all()
Expand All @@ -41,3 +28,40 @@ def retrieve_api_keys_for_user(self, id: str) -> list[ApiKey]:
return child.keys

raise FilteringError(message=NO_USER_FOUND)

def all(self) -> dict[str, Any]:
"""Retrieve a list of all API keys."""
url = "/api_keys"

response = Requestor(self._client).request(method=RequestMethod.GET, url=url)

return convert_to_easypost_object(response=response)

def create(self, mode: str) -> ApiKey:
"""Create an API key for a child or referral customer user."""
url = "/api_keys"
params = {"mode": mode}

response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params)

return convert_to_easypost_object(response=response)

def delete(self, id: str) -> None:
"""Delete an API key for a child or referral customer user."""
self._delete_resource(self._model_class, id)

def enable(self, id: str) -> ApiKey:
"""Enable a child or referral customer API key."""
url = f"/api_keys/{id}/enable"

response = Requestor(self._client).request(method=RequestMethod.POST, url=url)

return convert_to_easypost_object(response=response)

def disable(self, id: str) -> ApiKey:
"""Disable a child or referral customer API key."""
url = f"/api_keys/{id}/disable"

response = Requestor(self._client).request(method=RequestMethod.POST, url=url)

return convert_to_easypost_object(response=response)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "easypost"
description = "EasyPost Shipping API Client Library for Python"
version = "10.3.0"
version = "10.4.0"
readme = "README.md"
requires-python = ">=3.9"
license = { file = "LICENSE" }
Expand Down
257 changes: 257 additions & 0 deletions tests/cassettes/test_api_key_lifecycle.yaml

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

Loading