PyCatSim User API

PyCatSim, like a lot of other Python packages, follows an object-oriented design. It sounds fancy, but it really is quite simple. What this means for you is that we’ve gone through the trouble of coding up a lot of methods that apply in various situations - so you don’t have to worry about that. These situations are described in classes, the beauty of which is called “inheritance” (see link above). Basically, it allows to define methods that will automatically apply to your use case, as long as you put your data within one of those classes. A major advantage of object-oriented design is that you, the user, can harness the power of PyCatSim in very few lines of code through the user API without ever having to get your hands dirty with our code (unless you want to, of course). The flipside is that any user would do well to understand PyCatSim classes, what they are intended for, and what methods they support.

The following describes the various classes that undergird the PyCatsim edifice.

Cat (pyCatSim.Cat)

class pyCatSim.api.cat.Cat(name, age=None, color=None, mood=0, hunger_level=0, energy=0, health=0)[source]

Represents a virtual cat with attributes like name, age, color, mood, hunger, energy, and health.

Parameters:
  • name (str) – The name of the cat.

  • age (int, optional) – The age of the cat in years. Default is None.

  • color (str, optional) – Coat color of the cat. Acceptable values are: ‘tabby’, ‘black’, ‘orange’, ‘tortoiseshell’, and ‘tuxedo’. Fuzzy matching is used to interpret close inputs. Default is None.

  • mood (int, optional) – Mood level on a scale from -10 (grumpy) to 10 (ecstatic). Default is 0.

  • hunger_level (int, optional) – Hunger level of the cat. Higher values indicate greater hunger. Default is 0.

  • energy (int, optional) – Energy level of the cat. Default is 0.

  • health (int, optional) – Health level of the cat. Default is 0.

name

The name of the cat.

Type:

str

age

The age of the cat.

Type:

int or None

color

The interpreted or validated color of the cat.

Type:

str or None

mood

The cat’s mood.

Type:

int

hunger_level

The cat’s hunger level.

Type:

int

energy

The cat’s energy level.

Type:

int

health

The cat’s health level.

Type:

int

Examples

import pyCatSim as cats
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
Color 'tortoiseshell' interpreted as 'tortoiseshell'.

Methods

make_noise([noise, play])

play([mood_boost, hunger_boost, energy_boost])

Simulates playtime with the cat.

make_noise(noise='meow', play=False)[source]
Parameters:
  • noise (string, optional) – The sound the cat makes. Valid options include “meow”, “purr”. The default is ‘meow’.

  • play (bool, optional) – Whether to play the sound (True) or print out the sound (False). The default is False.

Raises:

ValueError – Raises an error if the sound is not valid

Returns:

The sound

Return type:

str

See also

pyCatSim.utils.noises.meow

Simulates a cat meow

pyCatSim.utils.noises.purr

Simulates a cat purr

Examples

import pyCatSim as cats
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
nutmeg.make_noise()
Color 'tortoiseshell' interpreted as 'tortoiseshell'.
'Meow!'
play(mood_boost=1, hunger_boost=1, energy_boost=-1)[source]

Simulates playtime with the cat.

Parameters:
  • mood_boost (int, optional) – How much mood improves from play. Must be an integer. Default is 1.

  • hunger_boost (int, optional) – How much hunger increases from play. Must be a positive integer. Default is 1.

  • energy_boost (int, optional) – How much energy decreases from play. Must be a negative integer. Default is -1.

Raises:
  • TypeError – If any of the arguments are not integers.

  • ValueError – If hunger_boost is not positive or energy_boost is not negative.

Examples

import pyCatSim as cats
nutmeg = cats.Cat(name='Nutmeg', age = 3, color = 'tortoiseshell')
nutmeg.play()
Color 'tortoiseshell' interpreted as 'tortoiseshell'.

Owner (pyCatSim.Owner)

class pyCatSim.api.human.Owner(name, cats_owned)[source]

Represents a cat owner who can care for one or more cats.

Parameters:
  • name (str) – The name of the owner.

  • cats_owned (Cat or list of Cat) – A single Cat instance or a list of Cat instances representing the cats this owner is responsible for.

name

The name of the owner.

Type:

str

cats_owned

The list of Cat objects owned by this person.

Type:

list of Cat

Raises:

TypeError – If cats_owned is neither a Cat nor a list of Cat objects.

Examples

from pyCatSim import Cat, Owner

cat1 = Cat(name="Whiskers")
cat2 = Cat(name="Boots", color="tabby")

# Single cat
owner1 = Owner(name="Sasha", cats_owned=cat1)

# Multiple cats
owner2 = Owner(name="Liam", cats_owned=[cat1, cat2])

print(owner1.name)
print([cat.name for cat in owner2.cats_owned])
Color 'tabby' interpreted as 'tabby'.
Sasha
['Whiskers', 'Boots']