NCESchools is a Python package designed to search for and extract detailed information about public and private schools from the NCES (National Center for Education Statistics) website. This package allows users to search for schools by name, city, state, and zip code, and retrieve various details such as enrollment, student-teacher ratios, and more.
The NCESchools package offers the following functionalities:
- Search Schools: Search for public or private schools by name, location, and other parameters.
- Extract School Information: Extract detailed information directly from the NCES website.
- Specialized Fetchers: Handle both public and private school searches with dedicated fetchers.
This package builds on the NCES Public and Private school search pages. For more information, visit The National Center for Education Statistics (NCES).
-
The installation instructions below are tailored for Conda users. If you prefer pip, you can install the package using the command:
pip install git+https://github.com/GSU-Analytics/NCESchools.git
The easiest way to install the NCESchools package is by using Conda to set up and update the package in your existing environment:
-
Install the Package in an Existing Environment:
pip install git+https://github.com/GSU-Analytics/NCESchools.git
-
Update the Package:
pip install git+https://github.com/GSU-Analytics/NCESchools.git -U
Alternatively, you can set up the NCESchools environment using a YAML file:
-
Create the Environment:
Save the following YAML configuration as
remote_install.yaml:name: nceschools channels: - defaults dependencies: - python>=3.10 - pip - pip: - git+https://github.com/GSU-Analytics/NCESchools.git
-
Install the Environment:
conda env create -f remote_install.yaml
-
Activate the Environment:
conda activate nceschools
To customize or develop the NCESchools package, you can install it locally by following these steps:
-
Clone the Repository:
git clone https://github.com/GSU-Analytics/NCESchools.git cd NCESchools -
Create a Conda Environment:
Use the provided
local_install.ymlfile to set up the environment, which will install the necessary dependencies, such asrequests,beautifulsoup4, andpytest:conda env create -f local_install.yml
-
Activate the Environment:
conda activate nceschools
-
Install the Package in Editable Mode:
After setting up the environment, install the
NCESchoolspackage in editable mode:pip install -e .Installing in "editable" mode means any changes you make to the source code will immediately reflect in the installed package.
Here’s how to use the NCESchools package to search and extract details for both public and private schools:
from nceschools import SchoolSearcher, PublicSchoolFetcher, PrivateSchoolFetcher
def main():
# Example usage for a public school
print("Public School Search and Extraction:")
public_searcher = SchoolSearcher(school_type='public')
# Search for a public school and extract details
school_name = "Shiloh High School"
city = "Snellville"
state = "GA"
zip_code = "30039"
print(f"Searching for {school_name} in {city}, {state}, {zip_code}...")
public_nces_id = public_searcher.get_nces_id(school_name, city=city, state=state, zip_code=zip_code)
if public_nces_id:
print(f"Public School NCES ID: {public_nces_id}")
public_fetcher = PublicSchoolFetcher()
public_html = public_fetcher.get_public_school_html(public_nces_id)
school_details = public_fetcher.extract_school_details(public_html)
print("Extracted School Details:")
for key, value in school_details.items():
print(f"{key}: {value}")
else:
print(f"No public school found for {school_name} in {city}, {state}, {zip_code}.")
# Example usage for a private school
print("\nPrivate School Search and Extraction:")
private_searcher = SchoolSearcher(school_type='private')
# Search for a private school and extract details
school_name = "Fuqua School"
city = "Farmville"
state = "VA"
zip_code = "23901"
print(f"Searching for {school_name} in {city}, {state}, {zip_code}...")
private_nces_id = private_searcher.get_nces_id(school_name, city=city, state=state, zip_code=zip_code)
if private_nces_id:
print(f"Private School NCES ID: {private_nces_id}")
private_fetcher = PrivateSchoolFetcher()
private_html = private_fetcher.get_private_school_html(private_nces_id)
school_details = private_fetcher.extract_school_details(private_html)
print("Extracted School Details:")
for key, value in school_details.items():
print(f"{key}: {value}")
else:
print(f"No private school found for {school_name} in {city}, {state}, {zip_code}.")
if __name__ == "__main__":
main()To run the unit tests, use the following command:
pytest