Skip to main content

Look up GitHub tokens from various sources

Project description

Kokomikke

Kokomikke (koh•koh•mi•ke) is a Python library that looks up GitHub access tokens from various sources.

Installation

pip install kokomikke

Usage

Basic usage is as simple as:

import kokomikke

token = kokomikke.search()

By default, this will look for a GitHub token in the following locations, in order, returning as soon as one is found:

  1. The GITHUB_API_TOKEN environment variable
  2. The GITHUB_TOKEN environment variable
  3. The GH_TOKEN environment variable
  4. The GITHUB_PAT environment variable
  5. The GH_PATH environment variable
  6. GitHub CLI via gh auth token
  7. GitHub CLI via hosts.yml

If no token is found, kokomikke.search() will return None.

Sources

In order to search for token, Kokomikke needs sources. A source is an object of a class that inherits from kokomikke.sources.Source and implements the lookup() method:

from kokomikke.sources import Source

class MySource(Source):
    def lookup(self) -> str | None:
        # lookup logic goes here

Kokomikke comes with the following sources built-in:

kokomikke.sources.EnvironmentVariableSource

Searches a list of environment variables, in order, for a non-empty value.

It takes the following arguments:

  • variables (list[str], keyword-only, default: [GITHUB_API_TOKEN, GITHUB_TOKEN, GH_TOKEN, GITHUB_PAT, GH_PAT]): The variables to search.

kokomikke.sources.GitHubCLISource

Runs gh auth token and, if there is no error, returns its output.

It takes the following arguments:

  • hostname (str, keyword-only, default: github.com): The hostname of the GitHub instance to get a token for.

kokkomikke.sources.GitHubCLIYamlSource

Reads GitHub CLI's hosts.yml file and returns a token if one is present.

It takes the following arguments:

  • hostname (str, keyword-only, default: github.com): The hostname of the GitHub instance to get a token for.

kokomikke.sources.GitSource

Calls git credential fill and returns a token if one is present in the output.

It takes the following arguments:

  • hostname (str, keyword-only, default: github.com): The hostname of the GitHub instance to get a token for.

kokomikke.sources.CommandSource

Runs an arbitrary command and, if there is no error, returns its output.

It takes the folowing arguments:

  • command: (list, keyword-only): Command arguments.

kokomikke.search() takes an optional sources argument, which expects a list of sources, each of which will be evaluated in order. For example, to first look for a token via gh auth token, but fall back to pass if that fails:

import kokomikke
from kokomikke.sources import CommandSource, GitHubCLISource

pass_source = CommandSource(command=["pass", "github.com/mona"])

token = kokomikke.search([GitHubCLISource, pass_source])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kokomikke-0.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kokomikke-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file kokomikke-0.1.1.tar.gz.

File metadata

  • Download URL: kokomikke-0.1.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kokomikke-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fad911efff42a173f87c65febe08ee5d850e20ee57fcec4e5ce64c19e231cf6a
MD5 d06db8f4e28a285257342eea16cef971
BLAKE2b-256 6b84694086d98d64266f2bbe0d158c259e920c461690378e4bf1d38b72a7e9cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for kokomikke-0.1.1.tar.gz:

Publisher: release.yml on celsiusnarhwal/kokomikke

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kokomikke-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kokomikke-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kokomikke-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c614fce2c5525f0b50ffb4fa08dd4394df072dc9fbcf6691cb2606afb488ab1c
MD5 b79cca90436de31799ed9c6201689796
BLAKE2b-256 43d4479cc4b8bca83dfc4937ecb0016dca6b09deeff4a8594264da4cedf81feb

See more details on using hashes here.

Provenance

The following attestation bundles were made for kokomikke-0.1.1-py3-none-any.whl:

Publisher: release.yml on celsiusnarhwal/kokomikke

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page