Celerium.PokeAPI
Buy me a coffee
Whether you use this project, have learned something from it, or just like it, please consider supporting it by buying me a coffee, so I can dedicate more time on open-source projects like this :)
About The Project
The Celerium.PokeAPI PowerShell wrapper offers a way to read data from PokeAPI, a free, open, read-only RESTful API with highly detailed data about the Pokemon video game franchise: Pokemon, their moves, abilities, types, egg groups, items, games, locations, and much more. No API key or account is needed. This module serves to abstract away the details of interacting with PokeAPI’s endpoints in such a way that is consistent with PowerShell nomenclature.
- :book: Celerium.PokeAPI project documentation can be found on Github Pages
- :book: PokeAPI’s documentation can be found at pokeapi.co/docs/v2 & the OpenAPI spec is published at github.com/PokeAPI/pokeapi
A function exists for every endpoint in the PokeAPI documentation & OpenAPI spec (PokeAPI-2.10.0.json) and every endpoint is tracked in the endpoints.csv file.
In order to maintain PowerShell best practices, only approved verbs are used and PowerShell’s verb-noun nomenclature is respected. PokeAPI is a consumption-only API, so every endpoint function is a Get-Poke* function (GET -> Get-Poke*). The module functions (base URI, settings, cache, & request helpers) use the PokeAPI prefix, such as Add-PokeAPIBaseURI & Invoke-PokeAPIRequest.
For example, one might access the /pokemon/{name} endpoint by running the following PowerShell command:
Get-PokePokemon -Name ditto
- Most functions cover three endpoints with parameter sets: the resource list (
Get-PokeBerry), a resource by id (Get-PokeBerry -Id 1), & a resource by name (Get-PokeBerry -Name cheri) - Lists return the PokeAPI response (
count,next,previous,results).-Limit&-Offsetpage through a list &-AllResultsfollows every next page link (100 resources per page unless-Limitis used) and returns the same shape with every result combined - Successful responses are cached in memory for one hour as the PokeAPI fair use policy asks, use
-NoCacheto skip the cache - Rate limited (429) & temporary server errors (502, 503, 504) are retried up to 3 times, every request sends a descriptive
Celerium.PokeAPI/<version>User-Agent
Install
This module can be installed directly from the PowerShell Gallery with the following command:
Install-Module -Name Celerium.PokeAPI
- :information_source: This module supports Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS. Every change is tested on all of them by the CI workflow.
- :information_source: If PowerShellGet is unavailable, you can manually download the main branch and place the latest version of Celerium.PokeAPI from the build folder into the (default)
C:\Program Files\WindowsPowerShell\Modulesfolder.
Celerium.PokeAPI project documentation can be found on Github Pages
- A full list of functions can be retrieved by running
Get-Command -Module Celerium.PokeAPI. - Help info and a list of parameters can be found by running
Get-Help <command name>, such as:
Get-Help Get-PokePokemon
Get-Help Get-PokePokemon -Full
Initial Setup
PokeAPI does not use API keys, the module is ready to use as soon as it is imported.
- [optional] Run
Add-PokeAPIBaseURI- By default, PokeAPI’s
https://pokeapi.co/api/v2uri is used - For a self-hosted PokeAPI use
Add-PokeAPIBaseURI -BaseURI http://localhost/api/v2
- By default, PokeAPI’s
- [optional] Run
Export-PokeAPIModuleSettings- This will create a config file at
%UserProfile%\PokeAPI(~/.PokeAPIon Linux & macOS) that holds the base uri. - Next time you run
Import-Module -Name Celerium.PokeAPI, this configuration file will automatically be loaded.
- This will create a config file at
Environment variables (recommended for CI\CD, Linux, & macOS) are loaded when the module is imported and take precedence over the configuration file:
$env:POKEAPI_BASE_URI = 'http://localhost/api/v2' # Optional, a self-hosted PokeAPI
Import-Module -Name Celerium.PokeAPI
Usage
# By name or by id
Get-PokePokemon -Name ditto
Get-PokePokemon -Id 25
# The first 20 resources (the PokeAPI default)
Get-PokeBerry
# Page through resources
Get-PokePokemon -Limit 100 -Offset 150
# Every resource, following the next page links (100 resources per page unless -Limit is defined)
Get-PokePokemonType -AllResults
# The pipeline works with lists and by property name
(Get-PokeGameGeneration).results | Get-PokeGameGeneration
# Resources related to a Pokemon
Get-PokePokemonEncounter -Name ditto
Get-PokePokemonSpecies -Name pikachu
# Skip the cache for one request or clear the cache
Get-PokePokemon -Name ditto -NoCache
Remove-PokeAPICache
- Names are lowercased and may only contain letters, numbers, and dashes because PokeAPI blocks requests with any other character in the path
- The
-Queryparameter of the list functions (a case-insensitive name search) is only available on a self-hosted PokeAPI - A resource that does not exist writes an error, use
-ErrorAction Stopto catch it:
try { Get-PokePokemon -Name notapokemon -ErrorAction Stop } catch { $_.Exception.Message }
The examples folder has basic examples and two report scripts (CSV & HTML) built with the module.
Supported functions
The module has 53 public functions in 12 categories that cover all 149 endpoints tracked in endpoints.csv. Every endpoint function is a read-only Get- function.
| Category | Functions |
|---|---|
| Berry | Get-PokeBerry Get-PokeBerryFirmness Get-PokeBerryFlavor |
| Contest | Get-PokeContestType Get-PokeContestEffect Get-PokeContestSuperEffect |
| Currency | Get-PokeCurrency |
| Encounter | Get-PokeEncounterMethod Get-PokeEncounterCondition Get-PokeEncounterConditionValue |
| Evolution | Get-PokeEvolutionChain Get-PokeEvolutionTrigger Get-PokeEvolutionVariable |
| Game | Get-PokeGameGeneration Get-PokeGamePokedex Get-PokeGameVersion Get-PokeGameVersionGroup |
| Item | Get-PokeItem Get-PokeItemAttribute Get-PokeItemCategory Get-PokeItemFlingEffect Get-PokeItemPocket |
| Location | Get-PokeLocation Get-PokeLocationArea Get-PokeLocationPalParkArea Get-PokeLocationRegion |
| Machine | Get-PokeMachine |
| Move | Get-PokeMove Get-PokeMoveAilment Get-PokeMoveBattleStyle Get-PokeMoveCategory Get-PokeMoveDamageClass Get-PokeMoveLearnMethod Get-PokeMoveTarget |
| Pokemon | Get-PokePokemon Get-PokePokemonAbility Get-PokePokemonCharacteristic Get-PokePokemonColor Get-PokePokemonEggGroup Get-PokePokemonEncounter Get-PokePokemonForm Get-PokePokemonGender Get-PokePokemonGrowthRate Get-PokePokemonHabitat Get-PokePokemonNature Get-PokePokemonPokeathlonStat Get-PokePokemonShape Get-PokePokemonSpecies Get-PokePokemonStat Get-PokePokemonType |
| Utility | Get-PokeLanguage Get-PokeEndpoint Get-PokeMeta |
| Internal | Add-PokeAPIBaseURI Get-PokeAPIBaseURI Remove-PokeAPIBaseURI Export-PokeAPIModuleSettings Get-PokeAPIModuleSettings Import-PokeAPIModuleSettings Initialize-PokeAPIModuleSettings Remove-PokeAPIModuleSettings Remove-PokeAPICache Invoke-PokeAPIRequest Get-PokeAPIResponse ConvertTo-PokeAPIQueryString Get-PokeAPIMetaData |
Every function of the module is exported, including the internal helpers.
Some endpoints do not support names and only accept an -Id (Get-PokeMachine, Get-PokeContestEffect, Get-PokeContestSuperEffect, Get-PokeEvolutionChain, Get-PokePokemonCharacteristic).
Development
The module is built from the files in this repository with the scripts in the build folder. The same steps are run by the GitHub Actions workflows in .github/workflows.
| Script | Description |
|---|---|
| Install-Prerequisites.ps1 | Installs the latest ModuleBuilder, Pester, Microsoft.PowerShell.PlatyPS, PSScriptAnalyzer, & powershell-yaml |
| New-PublicFunctions.ps1 | Regenerates the public functions, the manifest entries, & docs/endpoints.csv from build/EndpointDefinitions.psd1 |
| Get-PokeAPISpec.ps1 | (PowerShell 7+) Downloads the online spec (YAML) & saves it as docs/PokeAPI-<version>.json |
| Compare-PokeAPISpec.ps1 | Compares the newest local spec in docs with the online spec & optionally updates it |
| Invoke-ModuleBuild.ps1 | Builds the module & the spec into build/Celerium.PokeAPI/<version> |
| Invoke-PesterTests.ps1 | Runs the Pester tests against the source or built module |
| Invoke-HelpContent.ps1 | Regenerates the GitHub pages documentation in docs with Microsoft.PowerShell.PlatyPS |
| Publish-CeleriumModule.ps1 | Publishes the built module to the PowerShell Gallery |
PokeAPI endpoints all share the same shape (list, by id, by name), so the public functions are generated from the small build/EndpointDefinitions.psd1 table instead of the spec. New-PublicFunctions.ps1 validates the table against the newest spec in docs (every spec path must have a definition) and documents the response schema of each function. Get-PokeEndpoint & Get-PokeMeta are hand written. The scripts never delete files, public functions that are no longer generated are moved to build/Archive/<date>.
./build/Install-Prerequisites.ps1
./build/New-PublicFunctions.ps1
./build/Invoke-PesterTests.ps1 -Version 3.0.0 -BuildTarget notBuilt
./build/Invoke-ModuleBuild.ps1 -Version 3.0.0
./build/Invoke-PesterTests.ps1 -Version 3.0.0 -BuildTarget built
./build/Invoke-HelpContent.ps1
To support a newer version of PokeAPI, run ./build/Compare-PokeAPISpec.ps1 to see what changed in the online spec compared with the newest spec in docs. Run ./build/Get-PokeAPISpec.ps1 to download the online spec as docs/PokeAPI-<version>.json (a different file with the same name is first copied to build/Archive), add any new endpoint to build/EndpointDefinitions.psd1, then run ./build/New-PublicFunctions.ps1.
Live tests make about 12 real, read-only GET requests to PokeAPI (spaced 500 ms apart). They are excluded unless the Live tag is included, the optional POKEAPI_BASE_URI environment variable points them at a self-hosted PokeAPI:
./build/Invoke-PesterTests.ps1 -Version 3.0.0 -IncludeTag Live -ExcludeTag Online
Contributing
Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
See the CONTRIBUTING guide for more information about contributing.
License
Distributed under the MIT license. See LICENSE for more information.
Pokemon and Pokemon character names are trademarks of Nintendo. This project is not affiliated with PokeAPI.