PyJokes

0.8.3 · active · verified Fri Apr 17

PyJokes is a Python library that provides one-liner jokes, primarily focusing on programmer humor. It also supports general and neutral joke categories, and multiple languages. Currently at version 0.8.3, it maintains a stable API with infrequent but consistent updates.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to fetch a single joke by category and language using `pyjokes.get_joke()`. It also shows how to handle potential issues if a specific language/category combination is unavailable.

import pyjokes

# Get a random programmer joke
programmer_joke = pyjokes.get_joke(category='programmer')
print("Programmer Joke:", programmer_joke)

# Get a random neutral joke in German
try:
    german_joke = pyjokes.get_joke(language='de', category='neutral')
    print("German Neutral Joke:", german_joke)
except Exception as e:
    print(f"Could not fetch German joke (might not be available): {e}")

# Get a list of all jokes (careful, can be long!)
# all_jokes_list = pyjokes.get_jokes(category='all', language='en')
# print(f"First 3 jokes from list: {all_jokes_list[:3]}")

view raw JSON →