Skip to main content

A Python package for current U Sports basketball stats.

Project description

🏀 usports-basketball

Ruff PyPI Latest Release License Downloads Package Status

usports-basketball is a Python package that fetches and analyzes current basketball stats from the U Sports website.

With two simple functions you can easily retrieve detailed data for either the men's or women's league.

  • usport_team_stats: Fetch team stats.
  • usport_players_stats: Fetch player stats.

Each function returns a pandas DataFrame with the relevant statistics, allowing users to gather data for analysis and insights.

📥 Installation

You can install the package via pip:

pip install usports-basketball

🧩 Dependencies

This package relies on the following dependencies:

  • pandas
  • BeautifulSoup (bs4)
  • requests
  • pytest
  • playwright

Installing Chromium for Playwright

After installing the package, you'll need to install Playwright's Chromium browser. Run the following command:

playwright install chromium

Functions

usport_team_stats

This function fetches and processes team statistics data, including standings, win-loss totals, shooting percentages, and other relevant team metrics for the current U Sports basketball season.

Parameters

  • arg (str): The league for which you want to retrieve team statistics. Valid values are 'men' and 'women' or 'm' and 'w' (case-insensitive).
  • season_option (str, optional): The season type to fetch data for. Options are:
    • 'regular' (default): Regular season statistics.
    • 'playoffs': Playoff season statistics.
    • 'championship': Championship season statistics.

Returns

  • DataFrame: A pandas DataFrame containing the team statistics data.

usports_player_stats

This function fetches and processes player statistics data, including total games played, points scored, shooting percentages, rebounds, assists, turnovers, steals, blocks, and other individual player metrics for the current U Sports basketball season.

Parameters

  • arg (str): The league for which you want to retrieve team statistics. Valid values are 'men' and 'women' or 'm' and 'w' (case-insensitive).
  • season_option (str, optional): The season type to fetch data for. Options are:
    • 'regular' (default): Regular season statistics.
    • 'playoffs': Playoff season statistics.
    • 'championship': Championship season statistics.

Returns

  • DataFrame: A pandas DataFrame containing the player statistics data.

Usage

  • Fetching current stats from the league

from usports_basketball import usport_team_stats, usports_player_stats

# Fetching and processing men's team statistics
men_team_stats_df = usport_team_stats('m')

# Fetching and processing men's player statistics
men_player_stats_df = usport_players_stats('m')

# Fetch statistics for women's playoff teams
women_team_stats_df = usport_team_stats('w', 'playoffs')

# Fetch statistics for women's players playing in U Sports championship Final 8
women_player_stats_df = usport_players_stats('w', 'championship')
  • Viewing Column Names

# Use these code snippets to see all column names in each DataFrame
# For the team statistics DataFrame
print("Column names in men's player statistics DataFrame:")
print(men_player_stats_df.columns.tolist())

# For the player statistics DataFrame
print("\nColumn names in men's player statistics DataFrame:")
print(men_player_stats_df.columns.tolist())
  • Exporting DataFrame to different files

# Export the  to a CSV file using the `to_csv()` method
men_team_stats_df.to_csv('men_team_stats.csv', index=False)  # Export without row index

#Export to a HTML table representation using to_html method
men_team_stats_df.to_html('table.html')

#Export to a JSON file using the to_json() method
men_team_stats_df.to_json('men_team_stats.json', orient='records') # Export in 'records' format

#Export to a SQLite database using the to_sql() method (requires SQLAlchemy)
from sqlalchemy import create_engine

engine = create_engine('sqlite:///usports_stats.db') #Export to SQLite database
women_team_stats_df.to_sql('team_stats', con=engine, index=False) # Export without row index
women_player_stats_df.to_sql('player_stats', con=engine, index=False) # Export without row index

Explore Pandas DataFrame documentation for instructions on manipulating data and performing data analysis.

Author

This package was developed by OJ Adeyemi.

Contributing

Contributions, bug reports, and feature requests are welcome! Please feel free to open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details. for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usports_basketball-2.0.3.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usports_basketball-2.0.3-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file usports_basketball-2.0.3.tar.gz.

File metadata

  • Download URL: usports_basketball-2.0.3.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for usports_basketball-2.0.3.tar.gz
Algorithm Hash digest
SHA256 bb11c846f2b8ba0e270429afd2518914aa515cc129abd631d57ef12548cf5b35
MD5 4386aa60d7fcb484cfef07124a14fd99
BLAKE2b-256 a21ac6e9db9bf21c42d140c3d03793c146db5f69e71da8e6704d54355b7a791a

See more details on using hashes here.

Provenance

The following attestation bundles were made for usports_basketball-2.0.3.tar.gz:

Publisher: python-publish.yml on ojadeyemi/usports-basketball

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usports_basketball-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for usports_basketball-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa94cb5691ec6dc9d0faf183e80f0594542857e825a9a39f679ac81e28c1822
MD5 741543b04ef5484dd2939a2347ba0a24
BLAKE2b-256 31897353cd2d87dedb297b065cf6c3752c0d060bdb55e57a803930e5c7f028d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for usports_basketball-2.0.3-py3-none-any.whl:

Publisher: python-publish.yml on ojadeyemi/usports-basketball

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page