buildstock-fetch 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of buildstock-fetch might be problematic. Click here for more details.

File without changes
@@ -0,0 +1,85 @@
1
+ import json
2
+ import os
3
+ from dataclasses import asdict, dataclass
4
+ from pathlib import Path
5
+
6
+ import requests
7
+
8
+
9
+ @dataclass
10
+ class BuildingID:
11
+ bldg_id: int
12
+ release_number: str = "1"
13
+ release_year: str = "2022"
14
+ res_com: str = "resstock"
15
+ weather: str = "tmy3"
16
+ upgrade_id: str = "0"
17
+
18
+ def get_download_url(self) -> str:
19
+ """Generate the S3 download URL for this building."""
20
+ return (
21
+ "https://oedi-data-lake.s3.amazonaws.com/nrel-pds-building-stock/"
22
+ f"end-use-load-profiles-for-us-building-stock/{self.release_year}/"
23
+ f"{self.res_com}_{self.weather}_release_{self.release_number}/"
24
+ f"building_energy_models/upgrade={self.upgrade_id}/"
25
+ f"bldg{self.bldg_id:07}-up0{self.upgrade_id}.zip"
26
+ )
27
+
28
+ def to_json(self) -> str:
29
+ """Convert the building ID object to a JSON string."""
30
+ return json.dumps(asdict(self))
31
+
32
+
33
+ def fetch_bldg_ids(state: str) -> list[BuildingID]:
34
+ """Fetch a list of Building ID's
35
+
36
+ Provided a state, returns a list of building ID's for that state.
37
+
38
+ Args:
39
+ state: The state to fetch building ID's for.
40
+
41
+ Returns:
42
+ A list of building ID's for the given state.
43
+ """
44
+ if state == "MA":
45
+ return [
46
+ BuildingID(bldg_id=7),
47
+ BuildingID(bldg_id=8),
48
+ BuildingID(bldg_id=9),
49
+ ]
50
+
51
+ else:
52
+ raise NotImplementedError(f"State {state} not supported")
53
+
54
+
55
+ def fetch_bldg_data(bldg_ids: list[BuildingID]) -> list[Path]:
56
+ """Download building data for a given list of building ids
57
+
58
+ Downloads the data for the given building ids and returns list of paths to the downloaded files.
59
+
60
+ Args:
61
+ bldg_ids: A list of BuildingID objects to download data for.
62
+
63
+ Returns:
64
+ A list of paths to the downloaded files.
65
+ """
66
+ data_dir = Path(__file__).parent.parent / "data"
67
+ downloaded_paths = []
68
+ os.makedirs(data_dir, exist_ok=True)
69
+
70
+ for bldg_id in bldg_ids:
71
+ response = requests.get(bldg_id.get_download_url(), timeout=30)
72
+ response.raise_for_status()
73
+
74
+ output_path = data_dir / f"{bldg_id.bldg_id:07}_upgrade{bldg_id.upgrade_id}.zip"
75
+ with open(output_path, "wb") as file:
76
+ file.write(response.content)
77
+
78
+ downloaded_paths.append(output_path)
79
+ return downloaded_paths
80
+
81
+
82
+ if __name__ == "__main__": # pragma: no cover
83
+ tmp_ids = fetch_bldg_ids("MA")
84
+ tmp_data = fetch_bldg_data(tmp_ids)
85
+ print(f"Downloaded files: {[str(path) for path in tmp_data]}")
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: buildstock-fetch
3
+ Version: 0.1.0
4
+ Summary: This library simplifies downloading building characteristics and load curve data from NREL's ResStock and ComStock projects.
5
+ Project-URL: Homepage, https://switchbox-data.github.io/buildstock-fetch/
6
+ Project-URL: Repository, https://github.com/switchbox-data/buildstock-fetch
7
+ Project-URL: Documentation, https://switchbox-data.github.io/buildstock-fetch/
8
+ Author-email: Switchbox <bryan@switch.box>
9
+ License-File: LICENSE
10
+ Keywords: python
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: <4.0,>=3.9
21
+ Requires-Dist: requests>=2.32.3
22
+ Description-Content-Type: text/markdown
23
+
24
+ # buildstock-fetch
25
+
26
+ [![Release](https://img.shields.io/github/v/release/switchbox-data/buildstock-fetch)](https://img.shields.io/github/v/release/switchbox-data/buildstock-fetch)
27
+ [![Build status](https://img.shields.io/github/actions/workflow/status/switchbox-data/buildstock-fetch/main.yml?branch=main)](https://github.com/switchbox-data/buildstock-fetch/actions/workflows/main.yml?query=branch%3Amain)
28
+ [![Commit activity](https://img.shields.io/github/commit-activity/m/switchbox-data/buildstock-fetch)](https://img.shields.io/github/commit-activity/m/switchbox-data/buildstock-fetch)
29
+ [![License](https://img.shields.io/github/license/switchbox-data/buildstock-fetch)](https://img.shields.io/github/license/switchbox-data/buildstock-fetch)
30
+
31
+ This library simplifies downloading building characteristics and load curve data from NREL's ResStock and ComStock projects.
32
+
33
+ - **Github repository**: <https://github.com/switchbox-data/buildstock-fetch/>
34
+ - **Documentation** <https://switchbox-data.github.io/buildstock-fetch/>
35
+
36
+ ## Getting start with the project
37
+
38
+ ### 1. Set Up Your Development Environment
39
+
40
+ The easiest way to set up the library's dev environment is to use devcontainers. To do so, open up the repo in VSCode or a VSCode fork like Cursor or Positron. The editor will auto-detect the presence of the repo's devcontainer (configured in `.devcontainer/devcontainer.json`). Click "Reopen in Container" to launch the devcontainer.
41
+
42
+ Alternatively, you can install the environment and the pre-commit hooks on your laptop with
43
+
44
+ ```bash
45
+ make install
46
+ ```
47
+
48
+ You are now ready to start development on the library!
49
+ The github action CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
50
+
51
+ ### 2. Set up PyPI publishing
52
+
53
+ To finalize the set-up for publishing to PyPI, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/publishing/#set-up-for-pypi).
54
+
55
+ ### 3. Activate automatic documentation
56
+ For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/mkdocs/#enabling-the-documentation-on-github).
57
+
58
+ ## Releasing a new version
59
+
60
+ - Create an API Token on [PyPI](https://pypi.org/).
61
+ - Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/switchbox-data/buildstock-fetch/settings/secrets/actions/new).
62
+ - Create a [new release](https://github.com/switchbox-data/buildstock-fetch/releases/new) on Github.
63
+ - Create a new tag in the form `*.*.*`.
64
+
65
+ For more details, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/cicd/#how-to-trigger-a-release).
66
+
67
+ ---
68
+
69
+ Repository initiated with [fpgmaas/cookiecutter-uv](https://github.com/fpgmaas/cookiecutter-uv).
@@ -0,0 +1,6 @@
1
+ buildstock_fetch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ buildstock_fetch/main.py,sha256=Jl-sQ0n8bnelK5RfZSIX5VkcxwPye0VHWV5U-GvfkII,2535
3
+ buildstock_fetch-0.1.0.dist-info/METADATA,sha256=SXBeRuWWJ8mnMagcMy7TLDPbu4ZtG1tFHcKwrT4Hp_0,3803
4
+ buildstock_fetch-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ buildstock_fetch-0.1.0.dist-info/licenses/LICENSE,sha256=TJeh2yvO8__8Rbamd8r48-zvlFCINAsu9nOo5QdMRX8,1066
6
+ buildstock_fetch-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Switchbox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.