A Python implementation of the classic cowsay program for generating ASCII art with various characters delivering messages
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Cowpy provides 45 unique character implementations, all inheriting from the base Cowacter class. Each cowacter has its own distinctive ASCII art design while supporting the same customization options.
The foundation class that all cowacter implementations inherit from, providing message formatting, bubble generation, and customization options.
class Cowacter:
def __init__(self, eyes='default', thoughts=False, tongue=False, body=None):
"""
Initialize a cowacter with customization options.
Args:
eyes (str): Eye type from EYES dict ('default', 'borg', 'dead', 'greedy', 'paranoid', 'stoned', 'tired', 'wired', 'young')
thoughts (bool): Use thought bubble (o) instead of speech bubble (\)
tongue (bool): Display tongue ('U ') in the cowacter
body (str, optional): Custom ASCII art body, uses default cow if None
"""
def milk(self, msg):
"""
Generate cowsay output with the given message.
Args:
msg (str): Message for the cowacter to say/think. If empty/None, displays cowacter configuration info.
Returns:
str: Complete ASCII art output with speech/thought bubble and cowacter
"""Get cowacter classes by name from the registry.
def get_cow(name='default'):
"""
Get a cowacter class by name.
Args:
name (str): Name of the cowacter (case-sensitive)
Returns:
class or str: Cowacter class if found, or string 'default' if name not found
"""All cowacter classes follow the same interface as the base Cowacter class, accepting the same constructor parameters (eyes, thoughts, tongue) and providing the milk() method.
# Default cow character
class Cowacter: ...
# Animal characters
class BudFrogs: ...
class Bunny: ...
class Koala: ...
class Moose: ...
class Sheep: ...
class Squirrel: ...
class Turkey: ...
class Turtle: ...
# Fictional characters
class Beavis: ...
class Daemon: ...
class HelloKitty: ...
class Kiss: ...
class Kitty: ...
class Meow: ...
class Ren: ...
class Stimpy: ...
class Tux: ... # Linux penguin
# Fantasy/Sci-fi characters
class DragonAndCow: ...
class Ghostbusters: ...
class Kosh: ...
class LukeKoala: ... # Luke Skywalker koala
class MechAndCow: ...
class Vader: ... # Darth Vader cow
class VaderKoala: ... # Darth Vader koala
# Specialty designs
class Cheese: ...
class Cower: ...
class Eyes: ... # Many eyes design
class FlamingSheep: ...
class Milk: ... # Milk carton
class Moofasa: ... # Lion King parody
class Mutilated: ...
class Satanic: ...
class Skeleton: ...
class Small: ...
class Stegosaurus: ... # Dinosaur
class Supermilker: ...
class Surgery: ...
class ThreeEyes: ...
class Udder: ...
class www: ... # WWW cowThese cowacters contain adult content and are filtered by default in SFW mode.
# Adult content cowacters (NSFW)
class BongCow: ... # Drug reference
class HeadInCow: ... # Adult content
class Sodomized: ... # Adult content
class Telebears: ... # Adult contentfrom cowpy import cow
# Create any cowacter using its class directly
vader = cow.Vader(eyes='dead', thoughts=True)
message = vader.milk("I find your lack of faith disturbing")
print(message)
# Get cowacter by name
koala_class = cow.get_cow('koala')
koala = koala_class(tongue=True)
message = koala.milk("G'day mate!")
print(message)
# Create with different eye types
stoned_sheep = cow.Sheep(eyes='stoned')
paranoid_moose = cow.Moose(eyes='paranoid')
tired_tux = cow.Tux(eyes='tired')
# Default cowacter (classic cow)
default_cow = cow.Cowacter()
message = default_cow.milk("Moo!")
print(message)
# Empty message shows cowacter configuration
config_msg = default_cow.milk("")
print(config_msg) # Shows "Cowacter, eyes:default, tongue:False, thoughts:False"The COWACTERS dictionary contains all registered cowacter classes:
# Get all cowacter names
cowacter_names = list(cow.COWACTERS.keys())
# Access specific cowacter class
VaderClass = cow.COWACTERS['vader']
vader_instance = VaderClass(eyes='wired')The source code contains duplicate class definitions for 'koala' and 'stegosaurus' cowacters. The later definitions override the earlier ones in the COWACTERS registry, so only the final implementations are accessible.
Install with Tessl CLI
npx tessl i tessl/pypi-cowpy