NetrunnerDB API Client
NetrunnerDB API client module.
This module provides a client for interacting with the NetrunnerDB API to fetch card data, pack information, and decklists.
- Classes:
NetrunnerDBAPI: Main API client class. APIError: Custom exception for API-related errors.
- TypeDict Classes:
CardData: Type definition for card data. PackData: Type definition for pack data. DecklistData: Type definition for decklist data.
- class simulchip.api.netrunnerdb.CardData[source]
Bases:
TypedDict
Type definition for card data from NetrunnerDB.
- code
Unique card identifier (e.g., “01001”).
- title
Card name.
- type_code
Card type code (e.g., “agenda”, “asset”, “ice”).
- faction_code
Faction code (e.g., “haas-bioroid”, “shaper”).
- pack_code
Pack code where the card was released.
- quantity
Number of copies in a pack.
- deck_limit
Maximum copies allowed in a deck.
- image_url
URL to the card image.
- class simulchip.api.netrunnerdb.PackData[source]
Bases:
TypedDict
Type definition for pack data from NetrunnerDB.
- code
Unique pack identifier (e.g., “core”).
- name
Full pack name.
- position
Pack position in the cycle.
- cycle_code
Cycle code this pack belongs to.
- cycle
Full cycle name.
- date_release
Release date in YYYY-MM-DD format.
- class simulchip.api.netrunnerdb.DecklistData[source]
Bases:
TypedDict
Type definition for decklist data from NetrunnerDB.
- id
Unique decklist identifier.
- name
Deck name.
- description
Deck description (may include HTML).
- cards
Dictionary mapping card codes to quantities.
- exception simulchip.api.netrunnerdb.APIError[source]
Bases:
Exception
Custom exception for API-related errors.
- message
Error message describing what went wrong.
- status_code
HTTP status code if applicable.
- url
The URL that caused the error if applicable.
- class simulchip.api.netrunnerdb.NetrunnerDBAPI[source]
Bases:
object
Client for interacting with NetrunnerDB API.
Provides methods to fetch card data, pack information, and decklists from NetrunnerDB. Implements rate limiting and caching to be respectful of the API.
- BASE_URL
Base URL for the NetrunnerDB API.
- DEFAULT_RATE_LIMIT
Default delay between API calls (0.5 seconds).
- rate_limit_delay
Configured delay between API calls.
- cache
Cache manager instance for storing API responses.
Examples
Basic usage:
api = NetrunnerDBAPI() cards = api.get_all_cards() decklist = api.get_decklist("12345")
- __init__(rate_limit_delay=0.5, cache_dir=None)[source]
Initialize API client with validation.
- Parameters:
- Raises:
ValueError – If rate_limit_delay is negative
- Return type:
None
- get_all_cards()[source]
Fetch all cards from NetrunnerDB with smart caching.
Uses smart cache validation based on pack releases to minimize API calls.
- check_cache_validity()[source]
Check if cache needs refresh by fetching pack data only.
This is a lightweight check that only fetches pack information to determine if there are new releases since the cache was last updated.
- Return type:
- Returns:
True if cache is valid, False if it needs refresh
- check_cache_validity_with_reason()[source]
Check if cache needs refresh and provide detailed reason.
- set_offline_mode(offline=True)[source]
Enable or disable offline mode.
In offline mode, the API will only use cached data and won’t make any network requests.
- is_offline_mode()[source]
Check if offline mode is enabled.
- Return type:
- Returns:
True if offline mode is enabled
- get_packs_by_release_date(newest_first=True)[source]
Get all packs sorted by release date with enriched cycle names.
- get_decklist(decklist_id)[source]
Fetch a specific decklist by ID with validation.
- Parameters:
decklist_id (
str
) – NetrunnerDB decklist ID- Return type:
- Returns:
Decklist data including cards
- Raises:
ValueError – If decklist_id is invalid
APIError – If API request fails or decklist not found
- get_pack_by_code(pack_code)[source]
Get a specific pack by its code using functional approach.
- Parameters:
pack_code (
str
) – Pack code (e.g., “core”)- Return type:
- Returns:
Pack data or None if not found
- Raises:
ValueError – If pack_code is invalid
- get_cards_by_pack(pack_code)[source]
Get all cards from a specific pack.
- Parameters:
pack_code (
str
) – Pack code to filter by- Return type:
- Returns:
List of cards in the pack
- Raises:
ValueError – If pack_code is invalid