Python
scooze.api
¶
ScoozeApi
¶
Bases: AbstractContextManager
Context manager object for doing I/O from a local database.
Example
get_card_by(property_name: str, value: Any) -> Card
¶
Search the database for the first card that matches the given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name |
str
|
The property to check. |
required |
value |
Any
|
The value to match on. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
The first matching card, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_cards_by(property_name: str, values: list[Any], paginated: bool = False, page: int = 1, page_size: int = 10) -> list[Card]
¶
Search the database for cards matching the given criteria, with options for pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name |
str
|
The property to check. |
required |
values |
list[Any]
|
A list of values to match on. |
required |
paginated |
bool
|
Whether to paginate the results. |
False
|
page |
int
|
The page to look at, if paginated. |
1
|
page_size |
int
|
The size of each page, if paginated. |
10
|
Returns:
| Type | Description |
|---|---|
list[Card]
|
A list of cards matching the search criteria, or empty list if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_card_by_name(name: str) -> Card
cached
¶
Search the database for a card with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The card name to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given name if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_card_by_oracle_id(oracle_id: str) -> Card
cached
¶
Search the database for a card with the given Oracle ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oracle_id |
str
|
The card Oracle ID to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given Oracle ID if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_card_by_scryfall_id(scryfall_id: str) -> Card
cached
¶
Search the database for a card with the given Scryfall ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scryfall_id |
str
|
The card Scryfall ID to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given Scryfall ID if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_cards_by_set(set_code: str) -> list[Card]
¶
Search the database for all cards in the given set. Expects the 3-letter set code for a set (e.g. "CMD")
Args: set_code: The set code to search for.
Returns: A list of cards from the given set, or empty list if none were found.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
get_cards_all() -> list[Card]
¶
Get all cards from the database. WARNING: may be extremely large.
Returns:
| Type | Description |
|---|---|
list[Card]
|
A list of all cards in the database. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
add_card(card: Card) -> PydanticObjectId
¶
Add a card to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card |
Card
|
The card to insert. |
required |
Returns:
| Type | Description |
|---|---|
PydanticObjectId
|
The ID of the inserted card, or None if it was unable. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
add_cards(cards: list[Card]) -> list[PydanticObjectId]
¶
Add a list of cards to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cards |
list[Card]
|
The list of card to insert. |
required |
Returns:
| Type | Description |
|---|---|
list[PydanticObjectId]
|
The IDs of the inserted cards, or empty list if unable. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
delete_card(id: str) -> bool
¶
Delete a card from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
The ID of the card to delete. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the card is deleted, False otherwise. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
delete_cards_all() -> int
¶
Delete all cards in the database.
Returns:
| Type | Description |
|---|---|
int
|
The number of cards deleted, or None if none could be deleted. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
load_card_file(file_type: ScryfallBulkFile, bulk_file_dir: str, show_progress: bool = True) -> int
¶
Loads the desired file from the given directory into a local database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type |
ScryfallBulkFile
|
The type of ScryfallBulkFile to insert into the database. |
required |
bulk_file_dir |
str
|
The path to the folder containing the ScryfallBulkFile. |
required |
show_progress |
bool
|
Flag to log progress while loading a file. |
True
|
Returns:
| Type | Description |
|---|---|
int
|
The total number of cards loaded into the database. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside a |
AsyncScoozeApi
¶
Bases: AbstractAsyncContextManager
Async context manager object for doing I/O from a local database. Most commonly used in asynchronous contexts like Jupyter Notebooks or other web applications.
Example
get_card_by(property_name: str, value: Any) -> Card
async
¶
Search the database for the first card that matches the given criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name |
str
|
The property to check. |
required |
value |
Any
|
The value to match on. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
The first matching card, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_cards_by(property_name: str, values: list[Any], paginated: bool = False, page: int = 1, page_size: int = 10) -> list[Card]
async
¶
Search the database for cards matching the given criteria, with options for pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name |
str
|
The property to check. |
required |
values |
list[Any]
|
A list of values to match on. |
required |
paginated |
bool
|
Whether to paginate the results. |
False
|
page |
int
|
The page to look at, if paginated. |
1
|
page_size |
int
|
The size of each page, if paginated. |
10
|
Returns:
| Type | Description |
|---|---|
list[Card]
|
A list of cards matching the search criteria, or empty list if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_card_by_name(name: str) -> Card
async
cached
¶
Search the database for a card with the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The card name to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given name if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_card_by_oracle_id(oracle_id: str) -> Card
async
cached
¶
Search the database for a card with the given Oracle ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oracle_id |
str
|
The card Oracle ID to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given Oracle ID if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_card_by_scryfall_id(scryfall_id: str) -> Card
async
cached
¶
Search the database for a card with the given Scryfall ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scryfall_id |
str
|
The card Scryfall ID to search for. |
required |
Returns:
| Type | Description |
|---|---|
Card
|
A card with the given Scryfall ID if found, or None if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_cards_by_set(set_code: str) -> list[Card]
async
¶
Search the database for all cards in the given set. Expects the 3-letter set code for a set (e.g. "CMD")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_code |
str
|
The set code to search for. |
required |
Returns:
| Type | Description |
|---|---|
list[Card]
|
A list of cards from the given set, or empty list if none were found. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
get_cards_all() -> list[Card]
async
¶
Get all cards from the database. WARNING: may be extremely large.
Returns:
| Type | Description |
|---|---|
list[Card]
|
A list of all cards in the database. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
add_card(card: Card) -> PydanticObjectId
async
¶
Add a card to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card |
Card
|
The card to insert. |
required |
Returns:
| Type | Description |
|---|---|
PydanticObjectId
|
The ID of the inserted card, or None if it was unable. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
add_cards(cards: list[Card]) -> list[PydanticObjectId]
async
¶
Add a list of cards to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cards |
list[Card]
|
The list of card to insert. |
required |
Returns:
| Type | Description |
|---|---|
list[PydanticObjectId]
|
The IDs of the inserted cards, or empty list if unable. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
delete_card(id: str) -> bool | None
async
¶
Delete a card from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
The ID of the card to delete. |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
True if the card is deleted, False otherwise. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
delete_cards_all() -> int | None
async
¶
Delete all cards in the database.
Returns:
| Type | Description |
|---|---|
int | None
|
The number of cards deleted, or None if none could be deleted. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |
load_card_file(file_type: ScryfallBulkFile, bulk_file_dir: str, show_progress: bool = True) -> int
async
¶
Loads the desired file from the given directory into a local database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_type |
ScryfallBulkFile
|
The type of ScryfallBulkFile to insert into the database. |
required |
bulk_file_dir |
str
|
The path to the folder containing the ScryfallBulkFile. |
required |
show_progress |
bool
|
Flag to log progress while loading a file. |
True
|
Returns:
| Type | Description |
|---|---|
int
|
The total number of cards loaded into the database. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If used outside an |