Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python 3 wrapper for Pokéapi v2

License

NotificationsYou must be signed in to change notification settings

PokeAPI/pokebase

Repository files navigation

actionsPython 3.6 pypiPython >=3.8 github

pokebase is a simple but powerful Python interface to thePokeAPI database

Maintainer:GregHilmes

Installation

Version Support

pokebase 1.3.0 supports Python 3.6. Install it withpip install 'pokebase==1.3.0'

pokebase 1.4.1 drops support for Python 3.6 and adds support for Python >=3.8 <=3.12. Install it withpip install pokebase

Usage

>>>importpokebaseaspb>>>chesto=pb.APIResource('berry','chesto')>>>chesto.name'chesto'>>>chesto.natural_gift_type.name'water'>>>charmander=pb.pokemon('charmander')# Quick lookup.>>>charmander.height6>>># Now with sprites! (again!)>>>s1=pb.SpriteResource('pokemon',17)<pokebase.interface.SpriteResourceobjectat0x7f2f15660860>>>>s1.url'<https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/17.png>'>>>s2=pb.SpriteResource('pokemon',1,other=True,official_artwork=True)>>>s2.path'/home/user/.cache/pokebase/sprite/pokemon/other-sprites/official-artwork/1.png'>>>s3=pb.SpriteResource('pokemon',3,female=True,back=True)>>>s3.img_datab'x89PNGrnx1anx00x00x00rIHDRx00x00x00 ... xca^x7fxbbd\*x00x00x00x00IENDxaeB`x82'

... And it's just that simple.

Nomenclature

  • anendpoint is the results of an API call likehttp://pokeapi.co/api/v2/berry orhttp://pokeapi.co/api/v2/move
  • aresource is the actual data, from a call tohttp://pokeapi.co/api/v2/pokemon/1

Testing

Python unit tests are in a separatetests directory and can be run viapython -m tests.

Notes to the developer using this module

The quick data lookup for a Pokémon type, ispokebase.type_('type-name'), notpokebase.type('type-name'). This is because of a naming conflict with the built-intype function, were you tofrom pokebase import *.

When changing the cache, avoid importing the cache constants directly. You should only import them with the whole cache module. If you do not do this, callingset_cache will not change your local copy of the variable.

NOT THIS!

>>>frompokebase.cacheimportAPI_CACHE

Do this :)

>>>frompokebaseimportcache>>>cache.API_CACHE

[8]ページ先頭

©2009-2025 Movatter.jp