A Python library for interacting with the Codewars API to track and analyze user progress, kata completion statistics, and generate various reports.
- Fetch user data from Codewars API
- Track daily, weekly, and monthly kata completions
- Generate completion histograms
- Export data to CSV files
- Analyze solved katas for specific kata IDs
- Support for multiple users
Main class for managing multiple Codewars users and generating aggregate statistics.
Users(users: list[str])users: List of dictionaries containingusernameandfullnamekeys
get_total_daily()- Get daily completion counts for all usersget_total_weekly()- Get weekly completion counts for all usersget_total_date(date_type)- Get completion counts by date type ("daily", "weekly", "monthly")get_total_completed()- Get total completion counts for all usersget_total_daily_completed_histogram()- Get daily completion histograms for all users
export_total_completed_to_csv(file_path)- Export total completions to CSVexport_total_daily_completed_histogram_to_csv(file_path)- Export daily histograms to CSVexport_total_count_solved_katas_by_ids(kata_ids, file_path)- Export solved kata counts to CSV
add_user(username)- Add a new user to the collection
Class for individual Codewars user data and statistics.
User(username: str, full_name: str = None, base_url: str = "https://www.codewars.com/api/v1/users/")get_total()- Get total number of completed katasget_daily()- Get number of katas completed todayget_weekly()- Get number of katas completed this weekget_monthly()- Get number of katas completed in the last 30 daysget_completed_by_date(date_str)- Get completions for a specific date (YYYY-MM-DD format)
get_honor()- Get total honor pointsget_clan()- Get clan nameget_leaderboard_position()- Get leaderboard positionget_skills()- Get list of programming skills
daily_completed_task_histogram()- Generate daily completion histogramcount_solved_katas_by_ids(kata_ids)- Count how many specific katas the user has solved
from codewars import Users, User
# Create a single user
user = User("username")
print(f"Total completed: {user.get_total()}")
print(f"Daily completed: {user.get_daily()}")
print(f"Weekly completed: {user.get_weekly()}")
# Create multiple users
users_data = [
{"username": "user1", "fullname": "John Doe"},
{"username": "user2", "fullname": "Jane Smith"}
]
users = Users(users_data)
# Get daily statistics for all users
daily_stats = users.get_total_daily()
print(daily_stats)# Export total completions to CSV
users.export_total_completed_to_csv("output/completions.csv")
# Export daily histograms to CSV
users.export_total_daily_completed_histogram_to_csv("output/daily_histogram.csv")
# Check specific kata completion
kata_ids = ["kata1", "kata2", "kata3"]
users.export_total_count_solved_katas(kata_ids, "output/solved_katas.csv")# Get completions by different time periods
daily_data = users.get_total_date("daily")
weekly_data = users.get_total_date("weekly")
monthly_data = users.get_total_date("monthly")
# Get completions for specific date
user = User("username")
completions = user.get_completed_by_date("2024-08-02")Install the required dependencies:
pip install -r requirements.txtRequired packages:
requests- For API callscsv- For CSV export functionality (built-in)datetime- For date handling (built-in)collections- For defaultdict (built-in)
The library includes error handling for:
- Invalid usernames (raises
ValueError) - API connection issues
- Invalid date types in
get_total_date()method
id,Username,Completed Tasks
1,user1,150
2,user2,120
Date,user1,user2
2024-01-01,5,3
2024-01-02,2,4
id,Username,Solved Katas
1,user1,25
2,user2,18
- User data:
https://www.codewars.com/api/v1/users/{username} - Completed challenges:
https://www.codewars.com/api/v1/users/{username}/code-challenges/completed
This project is open source and available under the MIT License.