API Reference
Python SDKThis section provides a detailed reference for all the classes, methods, and functions available in the AwesomeAPI Python SDK.
Clients
The SDK provides client classes to interact with different aspects of the AwesomeAPI.
AwesomeAPIClient
The primary client for most operations.
Initializes the main client for interacting with the AwesomeAPI.
__init__(self, api_key: str, base_url: str = "https://api.awesomeapi.com/v1")
-
Parameters:
api_key
(str)- Your personal API key obtained from your AwesomeAPI dashboard.
base_url
(str, optional)- The base URL for the API. Defaults to "https://api.awesomeapi.com/v1".
from awesomeapi_sdk import AwesomeAPIClient
client = AwesomeAPIClient(api_key="YOUR_API_KEY")
Methods
get_user(self, user_id: str) -> dict
Retrieves information for a specific user.
user_id
(str)- The unique identifier of the user.
- Returns (dict)
- A dictionary containing user details.
user_data = client.get_user("user_12345")
print(user_data)
create_item(self, item_data: dict) -> dict
Creates a new item in the system.
item_data
(dict)- A dictionary containing the data for the new item.
- Returns (dict)
- A dictionary representing the newly created item.
new_item = client.create_item({
"name": "Gadget Pro",
"price": 99.99,
"tags": ["electronics", "new"]
})
print(new_item)
Exceptions
The SDK raises specific exceptions for different error scenarios.
AwesomeAPIError
Base class for all SDK-specific errors.
APIConnectionError
Raised when there is an issue connecting to the AwesomeAPI.
AuthenticationError
Raised when the provided API key is invalid or expired.
ResourceNotFoundError
Raised when a requested resource cannot be found.
from awesomeapi_sdk.exceptions import APIConnectionError
try:
client.get_user("non_existent_user")
except ResourceNotFoundError as e:
print(f"Error: {e}")
except APIConnectionError as e:
print(f"Connection Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Utility Functions
Helper functions for common tasks.
format_currency(amount: float, currency_code: str = "USD") -> str
Formats a numeric amount into a human-readable currency string.
amount
(float)- The numeric amount to format.
currency_code
(str, optional)- The ISO currency code (e.g., "USD", "EUR"). Defaults to "USD".
- Returns (str)
- The formatted currency string.
from awesomeapi_sdk.utils import format_currency
formatted_price = format_currency(1234.56, "EUR")
print(formatted_price) # Output: €1,234.56