Skip to main content

🏀 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.

Metadata

Release files for usports-basketball 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usports-basketball 2.0.3
File Size Uploaded
usports_basketball-2.0.3.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for usports-basketball 2.0.3
File Interpreter ABI Platform
usports_basketball-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 39.7 kB

Release files / usports_basketball-2.0.3.tar.gz

Download URL usports_basketball-2.0.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bb11c846f2b8ba0e270429afd2518914aa515cc129abd631d57ef12548cf5b35
BLAKE2b-256 checksum
How to use checksums
a21ac6e9db9bf21c42d140c3d03793c146db5f69e71da8e6704d54355b7a791a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 20, 2024.

Transparency log

Release files / usports_basketball-2.0.3-py3-none-any.whl

Download URL usports_basketball-2.0.3-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aaa94cb5691ec6dc9d0faf183e80f0594542857e825a9a39f679ac81e28c1822
BLAKE2b-256 checksum
How to use checksums
31897353cd2d87dedb297b065cf6c3752c0d060bdb55e57a803930e5c7f028d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 20, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page