Package: pokeapi-sdk-demo
PokeAPI SDK for PythonThe PokeAPI SDK for Python provides a scoped demo of using Python to create an SDK for a REST api.PreambleThis is a small demo of a Pokeapi SDK written in python which covers thePokemon,NatureandStatendpoints of PokeAPI only.The main packages/tools used are:requests- to ensure code readability and maintainability when interacting with the PokeAPIpytest- for testingGitHub Actions - for automated testing and deploymentPypi - for hosting the built pip packageThe first versions I came up with for this project were returning JSON objects which, while easy to work with in Python, did not feel native enough.I therefore restructured the project to use classes for a better object-orientated experience. Code generation via ChatGPT was helpful for filling gaps, particularly as PokeAPI has a lot of nested types in the responses to thepokemonendpoint - writing this out manually would have cost a lot of time and would be prone to errors.While the main 3 methods mirror PokeAPI, I decided to add a fourth methodget_pokemon_full_detailswhich helps to amalgamate the other methods together. As previously mentioned, PokeAPI has a lot of nested types, but it does not retrieve the full details on the request for a Pokemon. This method therefore also resolves any Nature and Stat information and provides this alongside the normalPokemonobject.The basic premise of the way this repo is set up is that on each push, the package is tested then published, via GitHub Actions, to Pypi, ready to be installed via Pip. Of course, as this is only a demo it simply runs this in a dumb fashion on each push (in the real world this would be configured differently).As a little stretch goal, I did get ChatGPT to generate an OpenAPI spec based on my SDK and than ran this through SpeakEasy. The result ishere, however I have not had chance to test this yet! It would be interesting to see how this compares to my "source" SDK.InstallationThe SDK demo can be installed into your Python environment via Pip:pip install pokeapi-sdk-demoFull details can be found on thePypi project page.UsageAfter installation, you can import the package into your project withimport pokeapi_sdkat the top of your file.You can then instantiate an SDK client withclient = pokeapi_sdk.PokeAPISDK(). See below examples for how to get started with the SDK.Note that the SDK demo only covers thePokemon,NatureandStatendpoints of PokeAPI.An additional method,get_pokemon_full_details(), has been provided which combines nested retrieval of details. For example, if a Pokemon has a Nature, rather than just returning the Pokeapi URL for that Nature, this method will resolve the Nature into a Nature object.ExamplesRetrieving Pokemon details from the ID number:pokemon = client.get_pokemon(1)
print (pokemon.name)

>>> bulbasaurRetrieving Pokemon ability from the name:pokemon = client.get_pokemon('bulbasaur')
print (pokemon.abilities[0].ability.name)

>>> overgrowRetrieving Nature details from an ID number:nature = client.get_nature(1)
print (nature.name)

>>> 'hardy'Retrieving Stat information from name:stat = client.get_stat('hp')
stat.game_index

>>> 1TestingTesting is done via Pytest, which needs to be installed prior to runningpip install pytestor via the requirements filepip install -r requirements.txt.Then runpytestto run all the tests in thetestdirectory. Sample output:========================= test session starts ==========================
platform darwin -- Python 3.10.13, pytest-7.1.3, pluggy-1.0.0
rootdir: /Users/adam/GitHub/pokeapisdkdemo
plugins: testinfra-6.8.0
collected 8 items                                                      

tests/nature_test.py ..                                          [ 25%]
tests/pokemon_test.py ....                                       [ 75%]
tests/stat_test.py ..                                            [100%]

========================== 8 passed in 1.72s ===========================Testing is also automated via GitHub Actions on each push to the repo (example pipeline)