pokebase Documentation

repository·master·Indexed 18 days ago

https://github.com/pokeapi/pokebase

A Python interface for the PokeAPI database that provides access to Pokémon data, resources, and sprites. It includes tools for quick lookups via functions like pb.pokemon(), as well as APIResource and SpriteResource for specific data and image retrieval.

Tokens
800
Snippets
5
Records
6
Agent score
13%

What's inside pokebase

  1. Understand Pokebase Nomenclature

    master

    To use the library effectively, understand the distinction between these two terms:

    • endpoint: The result of an API call that returns a collection or a base path (e.g., http://pokeapi.co/api/v2/berry).
    • resource: The actual data returned from a specific call to a unique identifier (e.g., http://pokeapi.co/api/v2/pokemon/1).
  2. Correctly import and use the cache module

    master

    When modifying or accessing the cache, do not import cache constants directly (e.g., from pokebase.cache import API_CACHE). If you do this, calling set_cache will not update your local reference. Instead, import the entire cache module from pokebase.

    # DO NOT DO THIS:
    # from pokebase.cache import API_CACHE
    
    # DO THIS:
    from pokebase import cache
    print(cache.API_CACHE)
  3. Install Pokebase

    master

    Install the latest version of Pokebase using pip. Note that version 1.4.1 requires Python >=3.8 and supports up to Python 3.12. If you are using Python 3.6, you must install version 1.3.0 specifically.

    # For Python >= 3.8
    pip install pokebase
    
    # For Python 3.6
    pip install 'pokebase==1.3.0'
  4. Basic Usage of Pokebase

    master

    Pokebase provides a simple interface to the PokeAPI. You can perform quick lookups using top-level functions like pb.pokemon() or access specific resources using pb.APIResource and pb.SpriteResource.

    import pokebase as pb
    
    # Quick lookup for a pokemon
    charmander = pb.pokemon('charmander')
    print(charmander.height)
    
    # Accessing specific API resources
    chesto = pb.APIResource('berry', 'chesto')
    print(chesto.natural_gift_type.name)
    
    # Accessing sprites
    s1 = pb.SpriteResource('pokemon', 17)
    print(s1.url)
    
    # Accessing specific sprite variations (e.g., official artwork)
    s2 = pb.SpriteResource('pokemon', 1, other=True, official_artwork=True)
    
    # Accessing specific gender/view variations
    s3 = pb.SpriteResource('pokemon', 3, female=True, back=True)
    print(s3.img_data)
  5. Avoid naming conflicts with type_

    master

    When performing a quick data lookup for a Pokémon type, use the function pokebase.type_('type-name') instead of pokebase.type('type-name'). This prevents a naming conflict with Python's built-in type() function if you use from pokebase import *.

    # Correct way to look up a type
    pokebase.type_('fire')