pokeapi Documentation

Python api & beginner-friendly repository by @PokeAPI. Model Context Protocol (MCP) server & tools with 5.3k stars.

5,289 stars Python Python 1 file · ~3,472 tokens #api#beginner-friendly#graphql#hacktoberfest#pokeapi#pokemon
RAW Doc

Docker & Self-Hosted Deployment Verified OCI

Deploy pokeapi on any server, homelab, or cloud container platform.

1-Click Terminal Command
bash (docker run)
docker run -d --name pokeapi --restart always pokeapi/pokeapi:master
Configured Services & Ports
⚙️ cache
image: build locally
⚙️ app
image: pokeapi/pokeapi:master
⚙️ web
image: build locally
⚙️ graphql-engine
image: build locally
⚙️ graphiql
image: pokeapi/graphiql:v1beta2-2.1.0
docker-compose.yml
yaml (docker-compose.yml)
services:
  cache:
    restart: "no"

  app:
    image: pokeapi/pokeapi:master
    env_file: .env
    restart: "no"

  web:
    depends_on:
      graphiql:
        condition: service_started
      graphql-engine:
        condition: service_healthy
    logging:
      driver: gcplogs
      options:
        gcp-project: 'pokeapi-215911'

  graphql-engine:
    cpus: 0.7
    memswap_limit: 3g
    mem_limit: 700m
    environment:
      HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL: 0
      HASURA_GRAPHQL_EVENTS_HTTP_POOL_SIZE: 10
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true"

  graphiql:
    image: pokeapi/graphiql:v1beta2-2.1.0
    expose:
      - 80
    depends_on:
      - graphql-engine
    restart: always

File: README.md

A RESTful API for Pokémon - pokeapi.co

Beta GraphQL support is rolling out! Check out the GraphQL paragraph for more info.

Table of Contents

Setup   [](https://www.python.org/downloads/release/python-3137/)

  • Download this source code into a working directory, be sure to use the flag --recurse-submodules to clone also our submodules.

  • Install uv for Python environment management.

  • Install the requirements using the Makefile commands:

    sh
    make install
    # This will install all the required packages and libraries for using PokeAPI
  • Install the pre-commit hooks using the Makefile commands (optional but recommended):

    sh
    make pre-commit-install

    [!NOTE]
    Pre-commit hooks are optional but recommended for maintaining code quality and consistency. If you do not want it to automatically run on every commit, you can run it manually with make pre-commit before commiting and pushing your changes.

  • Lint, format, and typecheck your code changes:

    sh
    make lint-check   # or: uv run ruff check .
    make format       # or: uv run ruff format .
    make typecheck    # or: uv run ty check

[!NOTE]
As of right now we are not strictly enforcing linting and typechecking, but we will be in the future. Please try to make sure your code passes these checks.

  • Set up the local development environment using the following command:

    sh
    make setup
  • Run the server on port 8000 using the following command:

    sh
    make serve

Database setup

To build or rebuild the database by applying any CSV file update, run

sh
make build-db

Visit localhost:8000/api/v2/ to see the running API!

Each time the build-db script is run, it will iterate over each table in the database, wipe it, and rewrite each row using the data found in data/v2/csv.

If you ever need to wipe the database use this command:

sh
make wipe-sqlite-db

If the database schema has changed, generate any outstanding migrations and apply them

sh
make make-migrations
make migrate

Run make help to see all tasks.

Docker and Compose   [](https://hub.docker.com/r/pokeapi/pokeapi)

There is also a multi-container setup, managed by Docker Compose V2. This setup allows you to deploy a production-like environment, with separate containers for each service, and is recommended if you need to simply spin up PokéAPI.

Start everything by

sh
make docker-setup

If you don't have make on your machine you can use the following commands

sh
docker compose up -d
docker compose exec -T app python manage.py migrate --settings=config.docker_compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose'

Browse localhost/api/v2/ or localhost/api/v2/pokemon/bulbasaur/ on port 80.

To rebuild the database and apply any CSV file updates, run

sh
make docker-build-db

If the database schema has changed, generate the migrations and apply those

sh
make docker-make-migrations
make docker-migrate

GraphQL   [](https://github.com/hasura/graphql-engine)

When you start PokéAPI with the above Docker Compose setup, an Hasura Engine server is started as well. It's possible to track all the PokeAPI tables and foreign keys by simply

sh
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/2.0/hasura-cli/install-hasura-cli
# hasura cli's version has to greater than v2.48.1
make hasura-apply

When finished browse http://localhost:8080 and you will find the admin console. The GraphQL endpoint will be hosted at http://localhost:8080/v1/graphql.

A free public GraphiQL console is browsable at the address https://beta.pokeapi.co/graphql/console/. The relative GraphQL endpoint is accessible at https://beta.pokeapi.co/graphql/v1beta

A set of examples is provided in the directory /graphql/examples of this repository.

Kubernetes   [](https://github.com/PokeAPI/pokeapi/actions/workflows/docker-k8s.yml)

Kustomize files are provided in the folder https://github.com/PokeAPI/pokeapi/tree/master/Resources/k8s/kustomize/base/. Create and change your secrets:

sh
cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env
cp Resources/k8s/kustomize/base/secrets/graphql.env.sample Resources/k8s/kustomize/base/secrets/graphql.env
cp Resources/k8s/kustomize/base/config/pokeapi.env.sample Resources/k8s/kustomize/base/config/pokeapi.env
# Edit the newly created files

Configure kubectl to point to a cluster and then run the following commands to start a PokéAPI service.

sh
kubectl apply -k Resources/k8s/kustomize/base/
kubectl config set-context --current --namespace pokeapi # (Optional) Set pokeapi ns as the working ns
# Wait for the cluster to spin up
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker_compose # Migrate the DB
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose' # Build the db
kubectl wait --namespace pokeapi --timeout=120s --for=condition=complete job/load-graphql # Wait for Graphql configuration job to finish

This k8s setup creates all k8s resources inside the Namespace pokeapi, run kubectl delete namespace pokeapi to delete them. It also creates a Service of type LoadBalancer which is exposed on port 80 and 443. Data is persisted on 12Gi of ReadWriteOnce volumes.

Wrappers

Official wrapper Repository Features
Node server-side PokeAPI/pokedex-promise-v2 Auto caching
Browser client-side PokeAPI/pokeapi-js-wrapper Auto caching, Image caching
Java/Kotlin PokeAPI/pokekotlin
Python 2/3 PokeAPI/pokepy Auto caching
Python 3 PokeAPI/pokebase Auto caching, Image caching
Wrapper Repository Features
.Net Standard mtrdp642/PokeApiNet Auto caching
Dart prathanbomb/pokedart
Go mtslzr/pokeapi-go Auto caching
Go JoshGuarino/PokeGo Auto caching
Godot UbeJelly/PokeDot
Haxe KinoCreatesGames/poke-api Auto caching
PHP lmerotta/phpokeapi Auto caching, lazy loading
PowerShell Celerium/PokeAPI-PowerShellWrapper
Python beastmatser/aiopokeapi Auto caching, asynchronous
Ruby rdavid1099/poke-api-v2
Rust lunik1/pokerust Auto caching
Scala juliano/pokeapi-scala Auto caching
Spring Boot dlfigueira/spring-pokeapi Auto caching
Swift kinkofer/PokemonAPI
Typescript server-side/client-side Gabb-c/Pokenode-ts Auto caching

Donations

Help to keep PokéAPI running! If you're using PokéAPI as a teaching resource or for a project, consider sending us a donation to help keep the service up. We get 1+ billion requests a month!

Thank you to all our backers! Become a backer

Join Us On Discord!

We have a Discord server. It is a simple place where people can chat with each other in a respecful manner. Not all maintainers/code contributors are signed up and your question might not be answered. Consider opening an issue if you want more visibility or you want to talk to the maintainers. Be excellent to each other :smile:

Contributing

This project exists thanks to all the people who contribute

All contributions are welcome: bug fixes, data contributions, and recommendations.

Please see the issues on GitHub before you submit a pull request or raise an issue, someone else might have beat you to it.

To contribute to this repository:

  • Fork the project to your own GitHub profile

  • Download the forked project using git clone:

    sh
    git clone --recurse-submodules [email protected]:<YOUR_USERNAME>/pokeapi.git
  • Create a new branch with a descriptive name:

    sh
    git checkout -b my_new_branch
  • Write some code, fix something, and add a test to prove that it works. No pull request will be accepted without tests passing, or without new tests if new features are added.

  • Commit your code and push it to GitHub

  • Open a new pull request and describe the changes you have made.

  • We'll accept your changes after review.

Simple!


File: graphql/v1beta2/examples/go/README.md

Go examples

`pokemon.go`

Fetches details about a Pokémon and prints an unformatted JSON to the stdout. The name of the Pokémon is passed as a variable.

sh
go run pokemon.go # | jq

File: graphql/v1beta2/examples/node/README.md

Node examples

`pokemon.js`

Fetches info about Staryu using node-fetch.

sh
npm i
node pokemon.js

File: graphql/v1beta2/examples/README.md

GraphQL examples

You can use all the .gql examples in our console at https://beta.pokeapi.co/graphql/console/.

Inside the folders you find GraphQL queries implemented in different languages, frameworks and libraries.


File: graphql/v1beta/examples/go/README.md

Go examples

`pokemon.go`

Fetches details about a Pokémon and prints an unformatted JSON to the stdout. The name of the Pokémon is passed as a variable.

sh
go run pokemon.go # | jq

File: graphql/v1beta/examples/node/README.md

Node examples

`pokemon.js`

Fetches info about Staryu using node-fetch.

sh
npm i
node pokemon.js

File: graphql/v1beta/examples/README.md

GraphQL examples

You can use all the .gql examples in our console at https://beta.pokeapi.co/graphql/console/.

Inside the folders you find GraphQL queries implemented in different languages, frameworks and libraries.


File: Resources/docker/app/README.md

Quick reference

pokeapi uses python:3.14-alpine as base image.

What is PokeAPI?

PokeAPI is a full RESTful API linked to an extensive database detailing everything about the Pokémon main game series.

pokeapi.co

How to use this image

This container connects to a Postgres database via the environment variables POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT.

The container connects to a Redis cache via the environment variable REDIS_CONNECTION_STRING.

Run the container

The container exposes port 80. It needs a PostgreSQL and a Redis instance to connect to. Refer to the section How to use this image for mapping the environment variables.

It's recommended to use the provided docker-compose.yml to start a container from this image.

Build the data

Pokémon data isn't automatically present in this image. All Pokémon data is persisted in a PostgreSQL database and thus needs to be built.

When the container is up and running, run the following shell commands:

sh
docker exec pokeapi python manage.py migrate --settings=config.docker_compose
docker exec pokeapi sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker_compose'