Skip to content

Commit b7ffa9c

Browse files
authored
feat: create/delete/enable/disable API keys (#381)
# Description <!-- Please provide a general summary of your PR changes and link any related issues or other pull requests. --> # Testing <!-- Please provide details on how you tested this code. See below. - All pull requests must be tested (unit tests where possible with accompanying cassettes, or provide a screenshot of end-to-end testing when unit tests are not possible) - New features must get a new unit test - Bug fixes/refactors must re-record existing cassettes --> # Pull Request Type Please select the option(s) that are relevant to this PR. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Improvement (fixing a typo, updating readme, renaming a variable name, etc)
1 parent f1e2b97 commit b7ffa9c

10 files changed

+520
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## v10.4.0 (2026-02-03)
4+
5+
- Adds the following functions usable by child and referral customer users:
6+
- `api_key.create`
7+
- `api_key.delete`
8+
- `api_key.enable`
9+
- `api_key.disable`
10+
311
## v10.3.0 (2025-11-24)
412

513
- Adds the following functions:

easypost/constant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flake8: noqa
22
# Library version
3-
VERSION = "10.3.0"
3+
VERSION = "10.4.0"
44
VERSION_INFO = [str(number) for number in VERSION.split(".")]
55

66
# Client defaults
Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
from typing import (
2-
Any,
3-
)
1+
from typing import Any
42

53
from easypost.constant import NO_USER_FOUND
64
from easypost.easypost_object import convert_to_easypost_object
75
from easypost.errors import FilteringError
86
from easypost.models import ApiKey
9-
from easypost.requestor import (
10-
RequestMethod,
11-
Requestor,
12-
)
7+
from easypost.requestor import RequestMethod, Requestor
138
from easypost.services.base_service import BaseService
149

1510

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

21-
def all(self) -> dict[str, Any]:
22-
"""Retrieve a list of all API keys."""
23-
url = "/api_keys"
24-
25-
response = Requestor(self._client).request(method=RequestMethod.GET, url=url)
26-
27-
return convert_to_easypost_object(response=response)
28-
2916
def retrieve_api_keys_for_user(self, id: str) -> list[ApiKey]:
3017
"""Retrieve a list of API keys (works for the authenticated User or a child User)."""
3118
api_keys = self.all()
@@ -41,3 +28,40 @@ def retrieve_api_keys_for_user(self, id: str) -> list[ApiKey]:
4128
return child.keys
4229

4330
raise FilteringError(message=NO_USER_FOUND)
31+
32+
def all(self) -> dict[str, Any]:
33+
"""Retrieve a list of all API keys."""
34+
url = "/api_keys"
35+
36+
response = Requestor(self._client).request(method=RequestMethod.GET, url=url)
37+
38+
return convert_to_easypost_object(response=response)
39+
40+
def create(self, mode: str) -> ApiKey:
41+
"""Create an API key for a child or referral customer user."""
42+
url = "/api_keys"
43+
params = {"mode": mode}
44+
45+
response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params)
46+
47+
return convert_to_easypost_object(response=response)
48+
49+
def delete(self, id: str) -> None:
50+
"""Delete an API key for a child or referral customer user."""
51+
self._delete_resource(self._model_class, id)
52+
53+
def enable(self, id: str) -> ApiKey:
54+
"""Enable a child or referral customer API key."""
55+
url = f"/api_keys/{id}/enable"
56+
57+
response = Requestor(self._client).request(method=RequestMethod.POST, url=url)
58+
59+
return convert_to_easypost_object(response=response)
60+
61+
def disable(self, id: str) -> ApiKey:
62+
"""Disable a child or referral customer API key."""
63+
url = f"/api_keys/{id}/disable"
64+
65+
response = Requestor(self._client).request(method=RequestMethod.POST, url=url)
66+
67+
return convert_to_easypost_object(response=response)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[project]
66
name = "easypost"
77
description = "EasyPost Shipping API Client Library for Python"
8-
version = "10.3.0"
8+
version = "10.4.0"
99
readme = "README.md"
1010
requires-python = ">=3.9"
1111
license = { file = "LICENSE" }
File renamed without changes.

tests/cassettes/test_api_key_lifecycle.yaml

Lines changed: 257 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)