### Install CS2 API Wrapper Source: https://github.com/tommhe14/cs2api/blob/main/README.md Installs the CS2 API wrapper library using pip. This is the first step to using the library in your Python projects. ```bash pip install cs2api ``` -------------------------------- ### Get Player Details Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves detailed profile information for a specific player using their slug. ```APIDOC ## Get Player Details ### Description Retrieves detailed profile information for a specific player using their slug. ### Method GET ### Endpoint `/players/{player_slug}` ### Parameters #### Path Parameters - **player_slug** (string) - Required - The unique slug of the player. ### Request Example ```python from cs2api import CS2 import asyncio async def get_player_profile(player_slug: str): async with CS2() as cs2: player = await cs2.get_player_details(player_slug) print(player) asyncio.run(get_player_profile("s1mple")) ``` ### Response #### Success Response (200) - **data** (object) - Contains detailed information about the player. - **nickname** (string) - The player's nickname. - **first_name** (string) - The player's first name. - **last_name** (string) - The player's last name. - **country** (object) - Information about the player's country. - **name** (string) - The name of the country. #### Response Example ```json { "data": { "nickname": "s1mple", "first_name": "Oleksandr", "last_name": "Kostyliev", "country": {"name": "Ukraine"} } } ``` ``` -------------------------------- ### Get Team Upcoming Matches Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves upcoming and currently live matches for a specific team. ```APIDOC ## Get Team Upcoming Matches ### Description Retrieves upcoming and currently live matches for a specific team. ### Method GET ### Endpoint `/teams/{team_id}/matches/upcoming` ### Parameters #### Path Parameters - **team_id** (integer) - Required - The unique ID of the team. #### Query Parameters - **limit** (integer) - Optional - The maximum number of matches to retrieve. Defaults to 10. ### Request Example ```python from cs2api import CS2 import asyncio async def get_upcoming_for_team(team_id: int): async with CS2() as cs2: matches = await cs2.get_team_upcoming_matches(team_id, limit=10) print(matches) asyncio.run(get_upcoming_for_team(12345)) ``` ### Response #### Success Response (200) - **data** (array) - A list of match objects. - **teams** (array) - The participating teams in the match. - **status** (string) - The current status of the match (e.g., "Finished", "Live", "Not Started"). #### Response Example ```json { "data": [ { "teams": [ {"name": "Team A", "score": 16}, {"name": "Team B", "score": 10} ], "status": "Finished" } ] } ``` ``` -------------------------------- ### Get Player Matches Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves match history for a specific player including finished, upcoming, and current matches. ```APIDOC ## Get Player Matches ### Description Retrieves match history for a specific player including finished, upcoming, and current matches. ### Method GET ### Endpoint `/players/{player_id}/matches` ### Parameters #### Path Parameters - **player_id** (integer) - Required - The unique ID of the player. ### Request Example ```python from cs2api import CS2 import asyncio async def get_player_match_history(player_id: int): async with CS2() as cs2: matches = await cs2.get_player_matches(player_id) print(matches) asyncio.run(get_player_match_history(31349)) ``` ### Response #### Success Response (200) - **data** (array) - A list of match objects. - **teams** (array) - The participating teams in the match. - **status** (string) - The current status of the match (e.g., "Finished", "Live", "Not Started"). - **tournament** (object) - Information about the tournament the match is part of. - **name** (string) - The name of the tournament. #### Response Example ```json { "data": [ { "teams": [ {"name": "Team A"}, {"name": "Team B"} ], "status": "Finished", "tournament": {"name": "ESL Pro League"} } ] } ``` ``` -------------------------------- ### Example Usage: Fetch Live Matches and Player Transfers Source: https://github.com/tommhe14/cs2api/blob/main/README.md Demonstrates how to use the CS2 API wrapper to fetch live match data and player transfer history. It utilizes async/await syntax and the context manager for session management. ```python from cs2api import CS2 import asyncio import json async def main(): async with CS2() as cs2: # Get live matches live_matches = await cs2.get_live_matches() print(json.dumps(live_matches, indent=4)) # Get player transfers transfers = await cs2.get_player_transfers(31349) print(json.dumps(transfers, indent=4)) asyncio.run(main()) ``` -------------------------------- ### Get Team Transfers Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves transfer history for a specific team showing player movements in and out. ```APIDOC ## Get Team Transfers ### Description Retrieves transfer history for a specific team showing player movements in and out. ### Method GET ### Endpoint `/teams/{team_id}/transfers` ### Parameters #### Path Parameters - **team_id** (integer) - Required - The unique ID of the team. #### Query Parameters - **limit** (integer) - Optional - The maximum number of transfers to retrieve. Defaults to 10. ### Request Example ```python from cs2api import CS2 import asyncio async def get_team_transfer_history(team_id: int): async with CS2() as cs2: transfers = await cs2.get_team_transfers(team_id, limit=10) print(transfers) asyncio.run(get_team_transfer_history(12345)) ``` ### Response #### Success Response (200) - **data** (array) - A list of transfer objects. - **player** (object) - Information about the player involved in the transfer. - **nickname** (string) - The player's nickname. - **team_from** (object) - Information about the team the player transferred from. - **name** (string) - The name of the team. - **team_to** (object) - Information about the team the player transferred to. - **name** (string) - The name of the team. #### Response Example ```json { "data": [ { "player": {"nickname": "PlayerName"}, "team_from": {"name": "Old Team"}, "team_to": {"name": "New Team"} } ] } ``` ``` -------------------------------- ### Get Team Upcoming Matches (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Fetches upcoming and live matches for a specified team, limited to the latest 10. Requires 'cs2api' and 'asyncio'. Prints the status and team names for each match. ```python from cs2api import CS2 import asyncio async def get_upcoming_for_team(team_id: int): async with CS2() as cs2: matches = await cs2.get_team_upcoming_matches(team_id, limit=10) for match in matches.get("data", []): teams = match.get("teams", []) status = match.get("status") print(f"[{status}] {teams[0]['name']} vs {teams[1]['name']}") asyncio.run(get_upcoming_for_team(12345)) ``` -------------------------------- ### Get Player Statistics Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves comprehensive player performance statistics including general stats, map performance, and accuracy metrics. ```APIDOC ## Get Player Statistics ### Description Retrieves comprehensive player performance statistics including general stats, map performance, and accuracy metrics. ### Method GET ### Endpoint `/players/{player_slug}/stats` ### Parameters #### Path Parameters - **player_slug** (string) - Required - The unique slug of the player. #### Query Parameters - **days** (integer) - Optional - The number of past days to retrieve statistics for. Defaults to 180. ### Request Example ```python from cs2api import CS2 import asyncio async def get_player_performance(player_slug: str): async with CS2() as cs2: stats = await cs2.get_player_stats(player_slug, days=180) print(stats) asyncio.run(get_player_performance("s1mple")) ``` ### Response #### Success Response (200) - **general_stats** (object) - Contains general performance metrics. - **map_stats** (object) - Contains statistics broken down by map. - **accuracy_stats** (object) - Contains accuracy-related metrics. #### Response Example ```json { "general_stats": { "kills": 1500, "deaths": 1200, "kdr": 1.25 }, "map_stats": { "Dust II": {"wins": 10, "losses": 5}, "Mirage": {"wins": 8, "losses": 7} }, "accuracy_stats": { "headshot_percentage": 0.55, "avg_damage_per_round": 95.2 } } ``` ``` -------------------------------- ### Get Player Details (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves detailed profile information for a player using their slug. Requires 'cs2api' and 'asyncio'. Outputs the player's nickname, full name, and country. ```python from cs2api import CS2 import asyncio async def get_player_profile(player_slug: str): async with CS2() as cs2: player = await cs2.get_player_details(player_slug) data = player.get("data", {}) print(f"Nickname: {data.get('nickname')}") print(f"Name: {data.get('first_name')} {data.get('last_name')}") print(f"Country: {data.get('country', {}).get('name')}") asyncio.run(get_player_profile("s1mple")) ``` -------------------------------- ### Get Team News Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves recent news articles related to a specific team. ```APIDOC ## Get Team News ### Description Retrieves recent news articles related to a specific team. ### Method GET ### Endpoint `/teams/{team_slug}/news` ### Parameters #### Path Parameters - **team_slug** (string) - Required - The unique slug of the team. #### Query Parameters - **limit** (integer) - Optional - The maximum number of news articles to retrieve. Defaults to 5. ### Request Example ```python from cs2api import CS2 import asyncio async def get_news_for_team(team_slug: str): async with CS2() as cs2: news = await cs2.get_team_news(team_slug, limit=5) print(news) asyncio.run(get_news_for_team("natus-vincere")) ``` ### Response #### Success Response (200) - **data** (array) - A list of news article objects. - **title** (string) - The title of the news article. - **published_at** (string) - The publication date and time of the article. #### Response Example ```json { "data": [ { "title": "Team X Wins Major Tournament", "published_at": "2023-10-27T10:00:00Z" } ] } ``` ``` -------------------------------- ### Get Player Matches (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves a player's match history, including finished, upcoming, and current matches. Requires 'cs2api' and 'asyncio'. Prints match status, tournament name, and participating teams. ```python from cs2api import CS2 import asyncio async def get_player_match_history(player_id: int): async with CS2() as cs2: matches = await cs2.get_player_matches(player_id) for match in matches.get("data", []): teams = match.get("teams", []) status = match.get("status") tournament = match.get("tournament", {}).get("name") print(f"[{status}] {tournament}: {teams[0]['name']} vs {teams[1]['name']}") asyncio.run(get_player_match_history(31349)) ``` -------------------------------- ### Get Team Transfers (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Fetches the transfer history for a team, showing player movements in and out, limited to 10 entries. Requires 'cs2api' and 'asyncio'. Prints player nicknames and team changes. ```python from cs2api import CS2 import asyncio async def get_team_transfer_history(team_id: int): async with CS2() as cs2: transfers = await cs2.get_team_transfers(team_id, limit=10) for transfer in transfers.get("data", []): player = transfer.get("player", {}) team_from = transfer.get("team_from", {}) team_to = transfer.get("team_to", {}) print(f"{player.get('nickname')}: {team_from.get('name')} -> {team_to.get('name')}") asyncio.run(get_team_transfer_history(12345)) ``` -------------------------------- ### Get Live CS2 Match Snapshot with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves a detailed real-time snapshot for a specific live CS2 match, including round-by-round information, using the CS2 API wrapper. Requires a valid match ID. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def get_match_snapshot(match_id: int): async with CS2() as cs2: snapshot = await cs2.get_live_match_snapshot(match_id) print(f"Match snapshot: {snapshot}") # Example with a match ID asyncio.run(get_match_snapshot(123456)) ``` -------------------------------- ### Get Team News (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves recent news articles for a team, limited to 5. Requires 'cs2api' and 'asyncio'. Prints the title and publication date of each article. ```python from cs2api import CS2 import asyncio async def get_news_for_team(team_slug: str): async with CS2() as cs2: news = await cs2.get_team_news(team_slug, limit=5) for article in news.get("data", []): print(f"Title: {article.get('title')}") print(f"Published: {article.get('published_at')}") print("---") asyncio.run(get_news_for_team("natus-vincere")) ``` -------------------------------- ### Get Team Statistics Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves comprehensive team performance statistics including general and advanced metrics over a specified time period. ```APIDOC ## Get Team Statistics ### Description Retrieves comprehensive team performance statistics including general and advanced metrics over a specified time period. ### Method GET ### Endpoint `/teams/{team_slug}/stats` ### Parameters #### Path Parameters - **team_slug** (string) - Required - The unique slug of the team. #### Query Parameters - **days** (integer) - Optional - The number of past days to retrieve statistics for. Defaults to 180. ### Request Example ```python from cs2api import CS2 import asyncio async def get_team_stats(team_slug: str): async with CS2() as cs2: stats = await cs2.get_team_stats(team_slug, days=180) print(stats) asyncio.run(get_team_stats("natus-vincere")) ``` ### Response #### Success Response (200) - **general_stats** (object) - Contains general performance metrics. - **advanced_stats** (object) - Contains advanced performance metrics. #### Response Example ```json { "general_stats": { "wins": 10, "losses": 5, "win_rate": 0.66 }, "advanced_stats": { "adr": 85.5, "kdr": 1.2 } } ``` ``` -------------------------------- ### Get Player Statistics (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Fetches comprehensive player statistics over the last 180 days, including general, map, and accuracy metrics. Requires 'cs2api' and 'asyncio'. Outputs the different statistical categories. ```python from cs2api import CS2 import asyncio async def get_player_performance(player_slug: str): async with CS2() as cs2: stats = await cs2.get_player_stats(player_slug, days=180) general = stats.get("general_stats", {}) map_stats = stats.get("map_stats", {}) accuracy = stats.get("accuracy_stats", {}) print(f"General: {general}") print(f"Map Stats: {map_stats}") print(f"Accuracy: {accuracy}") asyncio.run(get_player_performance("s1mple")) ``` -------------------------------- ### Get Live CS2 Matches with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves all currently live CS2 professional matches using the CS2 API wrapper. It includes team data, tournament information, AI predictions, and stream links. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio import json async def get_live_matches(): async with CS2() as cs2: live_matches = await cs2.get_live_matches() print(json.dumps(live_matches, indent=4)) # Example response structure: # { # "data": [ # { # "id": 123456, # "status": "current", # "teams": [...], # "tournament": {...}, # "ai_predictions": {...}, # "streams": [] # } # ] # } asyncio.run(get_live_matches()) ``` -------------------------------- ### Get Team Statistics (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves general and advanced statistics for a given team over the last 180 days. Requires the 'cs2api' library and 'asyncio'. Outputs general and advanced stats dictionaries. ```python from cs2api import CS2 import asyncio async def get_team_stats(team_slug: str): async with CS2() as cs2: stats = await cs2.get_team_stats(team_slug, days=180) general = stats.get("general_stats", {}) advanced = stats.get("advanced_stats", {}) print(f"General Stats: {general}") print(f"Advanced Stats: {advanced}") asyncio.run(get_team_stats("natus-vincere")) ``` -------------------------------- ### Get Today's CS2 Matches Schedule with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves all upcoming matches scheduled for today using the CS2 API wrapper. It displays the tournament name and the competing teams for each match. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def get_todays_schedule(): async with CS2() as cs2: matches = await cs2.get_todays_matches() for match in matches.get("data", []): tournament = match.get("tournament", {}) teams = match.get("teams", []) print(f"[{tournament.get('name')}] {teams[0]['name']} vs {teams[1]['name']}") asyncio.run(get_todays_schedule()) ``` -------------------------------- ### Get CS2 Team Data by Slug with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves basic team profile information for a CS2 team using its URL slug via the CS2 API wrapper. It can also specify a locale for the returned data. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def get_team_profile(team_slug: str): async with CS2() as cs2: team = await cs2.get_team_data(team_slug, locale="en") data = team.get("data", {}) print(f"Team: {data.get('name')}") print(f"Country: {data.get('country', {}).get('name')}") asyncio.run(get_team_profile("natus-vincere")) ``` -------------------------------- ### Get Finished CS2 Matches with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves recently finished CS2 professional matches using the CS2 API wrapper. It iterates through the results to print the names of competing teams. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def get_finished_matches(): async with CS2() as cs2: finished = await cs2.finished() for match in finished.get("data", []): teams = match.get("teams", []) if len(teams) >= 2: print(f"{teams[0]['name']} vs {teams[1]['name']}") asyncio.run(get_finished_matches()) ``` -------------------------------- ### Get Player Transfer History (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves and prints the transfer history for a given player ID using the CS2API library. It iterates through the transfer data, extracting team names and action dates. Requires the 'cs2api' and 'asyncio' libraries. ```python from cs2api import CS2 import asyncio async def get_player_transfer_history(player_id: int): async with CS2() as cs2: transfers = await cs2.get_player_transfers(player_id, limit=10) for transfer in transfers.get("data", []): team_from = transfer.get("team_from", {}) team_to = transfer.get("team_to", {}) action_date = transfer.get("action_date") print(f"{action_date}: {team_from.get('name', 'N/A')} -> {team_to.get('name', 'N/A')}") asyncio.run(get_player_transfer_history(31349)) ``` -------------------------------- ### Get CS2 Match Details by Slug with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Retrieves comprehensive information about a specific CS2 match using its unique slug identifier via the CS2 API wrapper. It prints the match ID, tournament name, and games played. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def get_match_info(match_slug: str): async with CS2() as cs2: details = await cs2.get_match_details(match_slug) # Access match data data = details.get("data", {}) print(f"Match: {data.get('id')}") print(f"Tournament: {data.get('tournament', {}).get('name')}") print(f"Games: {data.get('games')}") asyncio.run(get_match_info("natus-vincere-vs-g2-esports-12345")) ``` -------------------------------- ### Manual Session Management for CS2 API Source: https://github.com/tommhe14/cs2api/blob/main/README.md Illustrates manual session management for the CS2 API, including explicit opening and closing of the session. This approach requires careful handling of the session lifecycle. ```python cs2 = CS2() try: data = await cs2.get_live_matches() finally: await cs2.close() ``` -------------------------------- ### Context Manager for CS2 API Session Source: https://github.com/tommhe14/cs2api/blob/main/README.md Shows the recommended way to manage a CS2 API session using an asynchronous context manager. This ensures the session is properly opened and closed. ```python async with CS2() as cs2: data = await cs2.get_live_matches() ``` -------------------------------- ### Manual Session Management (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Demonstrates manual management of the CS2API session lifecycle, useful when the context manager pattern is not suitable. It explicitly opens and closes the API session, allowing for multiple API calls within the try-finally block. Requires 'cs2api' and 'asyncio'. ```python from cs2api import CS2 import asyncio async def manual_session_example(): cs2 = CS2() try: # Make multiple API calls live = await cs2.get_live_matches() finished = await cs2.finished() print(f"Live matches: {len(live.get('data', []))}") print(f"Finished matches: {len(finished.get('data', []))}") finally: await cs2.close() asyncio.run(manual_session_example()) ``` -------------------------------- ### Search Players (Python) Source: https://context7.com/tommhe14/cs2api/llms.txt Searches for players by name or nickname, returning up to 4 matching results with their IDs and country. Requires 'cs2api' and 'asyncio'. Outputs player ID, nickname, and country. ```python from cs2api import CS2 import asyncio async def find_player(query: str): async with CS2() as cs2: results = await cs2.search_players(query, limit=4) for player in results.get("data", []): print(f"ID: {player['id']} - Nickname: {player['nickname']}") print(f"Country: {player.get('country', {}).get('name')}") asyncio.run(find_player("s1mple")) ``` -------------------------------- ### Search Players Source: https://context7.com/tommhe14/cs2api/llms.txt Searches for players by name or nickname and returns matching results with player IDs. ```APIDOC ## Search Players ### Description Searches for players by name or nickname and returns matching results with player IDs. ### Method GET ### Endpoint `/players/search` ### Parameters #### Query Parameters - **query** (string) - Required - The name or nickname to search for. - **limit** (integer) - Optional - The maximum number of results to return. Defaults to 4. ### Request Example ```python from cs2api import CS2 import asyncio async def find_player(query: str): async with CS2() as cs2: results = await cs2.search_players(query, limit=4) print(results) asyncio.run(find_player("s1mple")) ``` ### Response #### Success Response (200) - **data** (array) - A list of player objects matching the search query. - **id** (integer) - The unique ID of the player. - **nickname** (string) - The player's nickname. - **country** (object) - Information about the player's country. - **name** (string) - The name of the country. #### Response Example ```json { "data": [ { "id": 31349, "nickname": "s1mple", "country": {"name": "Ukraine"} } ] } ``` ``` -------------------------------- ### Search CS2 Teams by Name with Python Source: https://context7.com/tommhe14/cs2api/llms.txt Searches for CS2 teams by name using the CS2 API wrapper and returns matching results, including team IDs, names, and slugs. Allows specifying a limit for the number of results. Requires Python 3.8+ and the 'cs2api' library. ```python from cs2api import CS2 import asyncio async def find_team(query: str): async with CS2() as cs2: results = await cs2.search_teams(query, limit=4) for team in results.get("data", []): print(f"ID: {team['id']} - Name: {team['name']} - Slug: {team['slug']}") asyncio.run(find_team("navi")) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.