Build Something
Example Projects
Complete, working projects you can copy and run in minutes. Each one teaches a different concept while doing something fun with the Anagrama API.
๐ฎ
Anagram Game
Python
A terminal-based anagram game that fetches random words, scrambles them, and challenges you to unscramble. Keeps score and tracks streaks across 5 rounds.
Game Loop DesignRandom Words APIUser Input HandlingBatch API Calls
1
Create the project
Terminal
mkdir anagram-game && cd anagram-game2
Install the SDK
Terminal
pip install anagrama-sdk3
Set your API key
Terminal
export ANAGRAMA_API_KEY="ak_your_key_here"4
Write the code
Create anagram_game.py:
anagram_game.py
import random
from anagrama_sdk import Anagrama
client = Anagrama() # reads ANAGRAMA_API_KEY from env
def scramble(word: str) -> str:
"""Shuffle letters until they differ from the original."""
letters = list(word)
for _ in range(100):
random.shuffle(letters)
if "".join(letters) != word:
break
return "".join(letters).upper()
def play_round(word: str) -> bool:
"""Play one round. Returns True if the player wins."""
scrambled = scramble(word)
print(f"\n๐ค Unscramble this: {scrambled} ({len(word)} letters)")
for attempt in range(1, 4): # 3 tries
guess = input(f" Attempt {attempt}/3: ").strip().lower()
if guess == word:
print(" โ
Correct!")
return True
# Show a hint after the 2nd wrong guess
if attempt == 2:
print(f" ๐ก Hint: starts with '{word[0].upper()}'")
else:
print(" โ Try again!")
print(f" ๐ข The answer was: {word.upper()}")
return False
def main():
print("=" * 40)
print(" ๐
ฐ๏ธ ANAGRAM GAME")
print(" Unscramble words from the Anagrama API")
print("=" * 40)
score = 0
streak = 0
rounds = 5
# Fetch all words for this session in one API call
response = client.words.random(count=rounds, min_length=4, max_length=7)
words = response.words
for i, word in enumerate(words, 1):
print(f"\n--- Round {i}/{rounds} (Score: {score}, Streak: {streak}) ---")
if play_round(word):
score += 1
streak += 1
if streak >= 3:
print(f" ๐ฅ {streak}-word streak!")
else:
streak = 0
print(f"\n{'=' * 40}")
print(f" Final Score: {score}/{rounds}")
if score == rounds:
print(" ๐ Perfect game!")
elif score >= rounds // 2:
print(" ๐ Nice job!")
else:
print(" ๐ช Keep practicing!")
print(f"{'=' * 40}")
if __name__ == "__main__":
main()5
Run the game
Terminal
python anagram_game.py6
Expected output
Output
========================================
๐
ฐ๏ธ ANAGRAM GAME
Unscramble words from the Anagrama API
========================================
--- Round 1/5 (Score: 0, Streak: 0) ---
๐ค Unscramble this: EMFAL (5 letters)
Attempt 1/3: flame
โ
Correct!
--- Round 2/5 (Score: 1, Streak: 1) ---
๐ค Unscramble this: GRITE (5 letters)
Attempt 1/3: tiger
โ
Correct!The game fetches all 5 words in a single API call, then runs the rounds locally for a snappy experience.
Was this page helpful?