ledgerdata 0.1.0.dev6__tar.gz

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.
@@ -0,0 +1,220 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # uv
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs/Zensical documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
201
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
203
+ # could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LEDGER-project
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.
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.5
2
+ Name: ledgerdata
3
+ Version: 0.1.0.dev6
4
+ Summary: Python client for LEDGER database
5
+ Author-email: Luke Gloege <lucas.gloege@yale.edu>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Dist: pandas>=3.0.6
10
+ Requires-Dist: psycopg>=3.3.6
11
+ Requires-Dist: pydantic>=2.14.1
12
+ Requires-Dist: requests>=2.34.2
13
+ Requires-Dist: ruff>=0.17.2
14
+ Description-Content-Type: text/markdown
15
+
16
+ # ledgerdata: The LEDGER Python Client
17
+
18
+ This Repo contains the LEDGER Python Client
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ uv add git+https://github.com/LEDGER-project/ledgerdata.git@main
24
+ ```
25
+
26
+ or with pip
27
+
28
+ ```bash
29
+ pip install git+https://github.com/LEDGER-project/ledgerdata.git@main
30
+ ```
31
+
32
+ ## Documentation
33
+
34
+ The official documentation for the entire LEDGER project is available at: [https://ledger-project.github.io/](https://ledger-project.github.io/)
@@ -0,0 +1,19 @@
1
+ # ledgerdata: The LEDGER Python Client
2
+
3
+ This Repo contains the LEDGER Python Client
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ uv add git+https://github.com/LEDGER-project/ledgerdata.git@main
9
+ ```
10
+
11
+ or with pip
12
+
13
+ ```bash
14
+ pip install git+https://github.com/LEDGER-project/ledgerdata.git@main
15
+ ```
16
+
17
+ ## Documentation
18
+
19
+ The official documentation for the entire LEDGER project is available at: [https://ledger-project.github.io/](https://ledger-project.github.io/)
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "ledgerdata"
3
+ version = "0.1.0.dev6"
4
+ description = "Python client for LEDGER database"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Luke Gloege", email = "lucas.gloege@yale.edu" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "httpx>=0.28.1",
12
+ "pandas>=3.0.6",
13
+ "psycopg>=3.3.6",
14
+ "pydantic>=2.14.1",
15
+ "requests>=2.34.2",
16
+ "ruff>=0.17.2",
17
+ ]
18
+
19
+ [project.scripts]
20
+ ledgerdata = "ledgerdata:main"
21
+
22
+ [build-system]
23
+ requires = ["hatchling"]
24
+ build-backend = "hatchling.build"
@@ -0,0 +1,15 @@
1
+ """
2
+ Set up module access for the base package
3
+ """
4
+
5
+ from .actors import Actors
6
+ from .client import Client
7
+ from .datasource import Datasource
8
+ from .emissions import Emissions
9
+ from .gdp import GDP
10
+ from .initiatives import Initiatives
11
+ from .population import Population
12
+ from .sector import Sector
13
+ from .targets import Targets
14
+
15
+ __all__ = ["GDP", "Actors", "Client", "Datasource", "Emissions", "Initiatives", "Population", "Sector", "Targets"]
@@ -0,0 +1,204 @@
1
+ import warnings
2
+
3
+ import httpx
4
+ import requests
5
+ from pydantic.dataclasses import dataclass
6
+
7
+ from .base import Base
8
+
9
+
10
+ @dataclass
11
+ class Actors(Base):
12
+ """Provides methods to retrieve actor and actor-part data from the LEDGER API."""
13
+
14
+ def get_all_actors(self, *args, **kwargs):
15
+ """Retrieve all actors.
16
+
17
+ Sends a GET request to the `/actors` endpoint and returns the response
18
+ as a JSON dictionary.
19
+
20
+ Returns:
21
+ dict: A JSON response containing actor data.
22
+ """
23
+ endpoint = "/actor"
24
+ url = f"{self.server}{endpoint}"
25
+ headers = {"Accept": "application/json"}
26
+ # Add query parameters as a dict
27
+ response = requests.get(url, headers=headers).json()
28
+ # data_list = response.get("data", None)
29
+ return response
30
+
31
+ def parts_of_actor(self, actor_id=str, type: str | None = None, *args, **kwargs):
32
+ """Retrieve parts (sub-actors) of a given actor.
33
+
34
+ Sends a GET request to the `/parts_of/{actor_id}` endpoint and returns
35
+ the response as a JSON dictionary.
36
+
37
+ Args:
38
+ actor_id (str): The code for the actor whose parts you want to retrieve.
39
+ type (Optional[str]): Optional filter for part type.
40
+ *args: Additional positional arguments (currently unused).
41
+ **kwargs: Additional keyword arguments (currently unused).
42
+
43
+ Returns:
44
+ dict: A JSON response containing actor-part data.
45
+ """
46
+ endpoint = f"/actor/{actor_id}/parts"
47
+ url = f"{self.server}{endpoint}"
48
+ headers = {"Accept": "application/json"}
49
+ params = {"type": type} if type else {}
50
+ response = requests.get(url, headers=headers, params=params).json()
51
+ # data_list = response.get("data", None)
52
+ return response
53
+
54
+ def population(self, actor_id=str, *args, **kwargs):
55
+ """Retrieve actor population
56
+
57
+ Sends a GET request to the `/actor/{actor_id}/population` endpoint and returns
58
+ the response as a JSON dictionary.
59
+
60
+ Args:
61
+ actor_id (str): The code for the actor whose parts you want to retrieve.
62
+ *args: Additional positional arguments (currently unused).
63
+ **kwargs: Additional keyword arguments (currently unused).
64
+
65
+ Returns:
66
+ dict: A JSON response containing actor-part data.
67
+ """
68
+ endpoint = f"/actor/{actor_id}/population"
69
+ url = f"{self.server}{endpoint}"
70
+ headers = {"Accept": "application/json"}
71
+ response = requests.get(url, headers=headers).json()
72
+ return response
73
+
74
+ def gdp(self, actor_id=str, *args, **kwargs):
75
+ """Retrieve actor population
76
+
77
+ Sends a GET request to the `/actor/{actor_id}/gdp` endpoint and returns
78
+ the response as a JSON dictionary.
79
+
80
+ Args:
81
+ actor_id (str): The code for the actor whose parts you want to retrieve.
82
+ *args: Additional positional arguments (currently unused).
83
+ **kwargs: Additional keyword arguments (currently unused).
84
+
85
+ Returns:
86
+ dict: A JSON response containing actor-part data.
87
+ """
88
+ endpoint = f"/actor/{actor_id}/gdp"
89
+ url = f"{self.server}{endpoint}"
90
+ headers = {"Accept": "application/json"}
91
+ response = requests.get(url, headers=headers).json()
92
+ return response
93
+
94
+ def energy_consumption(self, actor_id=str, *args, **kwargs):
95
+ """Retrieve actor population
96
+
97
+ Sends a GET request to the `/actor/{actor_id}/energy_consumption` endpoint and returns
98
+ the response as a JSON dictionary.
99
+
100
+ Args:
101
+ actor_id (str): The code for the actor whose parts you want to retrieve.
102
+ *args: Additional positional arguments (currently unused).
103
+ **kwargs: Additional keyword arguments (currently unused).
104
+
105
+ Returns:
106
+ dict: A JSON response containing actor-part data.
107
+ """
108
+ endpoint = f"/actor/{actor_id}/energy_consumption"
109
+ url = f"{self.server}{endpoint}"
110
+ headers = {"Accept": "application/json"}
111
+ response = requests.get(url, headers=headers).json()
112
+ return response
113
+
114
+ def targets(self, actor_id=str, *args, **kwargs):
115
+ """Retrieve actor population
116
+
117
+ Sends a GET request to the `/actor/{actor_id}/targets` endpoint and returns
118
+ the response as a JSON dictionary.
119
+
120
+ Args:
121
+ actor_id (str): The code for the actor whose parts you want to retrieve.
122
+ *args: Additional positional arguments (currently unused).
123
+ **kwargs: Additional keyword arguments (currently unused).
124
+
125
+ Returns:
126
+ dict: A JSON response containing actor-part data.
127
+ """
128
+ endpoint = f"/actor/{actor_id}/targets"
129
+ url = f"{self.server}{endpoint}"
130
+ headers = {"Accept": "application/json"}
131
+ response = requests.get(url, headers=headers).json()
132
+ return response
133
+
134
+ def emissions(self, actor_id=str, ignore_warnings: bool = False, *args, **kwargs):
135
+ """Retrieve actor population
136
+
137
+ Sends a GET request to the `/actor/{actor_id}/emissions` endpoint and returns
138
+ the response as a JSON dictionary.
139
+
140
+ Args:
141
+ actor_id (str): The code for the actor whose parts you want to retrieve.
142
+ *args: Additional positional arguments (currently unused).
143
+ **kwargs: Additional keyword arguments (currently unused).
144
+
145
+ Returns:
146
+ dict: A JSON response containing actor-part data.
147
+ """
148
+ (
149
+ warnings.simplefilter("ignore")
150
+ if ignore_warnings
151
+ else warnings.simplefilter("default")
152
+ )
153
+ endpoint = f"/actor/{actor_id}/emissions"
154
+ url = f"{self.server}{endpoint}"
155
+ headers = {"Accept": "application/json"}
156
+ response = requests.get(url, headers=headers).json()
157
+ return response
158
+
159
+
160
+ def emissions_total_sector(self, actor_id=str, ignore_warnings: bool = False, *args, **kwargs):
161
+ """Retrieve actor population
162
+
163
+ Sends a GET request to the `/actor/{actor_id}/emissions_total_sector` endpoint and returns
164
+ the response as a JSON dictionary.
165
+
166
+ Args:
167
+ actor_id (str): The code for the actor whose parts you want to retrieve.
168
+ *args: Additional positional arguments (currently unused).
169
+ **kwargs: Additional keyword arguments (currently unused).
170
+
171
+ Returns:
172
+ dict: A JSON response containing actor-part data.
173
+ """
174
+ (
175
+ warnings.simplefilter("ignore")
176
+ if ignore_warnings
177
+ else warnings.simplefilter("default")
178
+ )
179
+ endpoint = f"/actor/{actor_id}/emissions_total_sector"
180
+ url = f"{self.server}{endpoint}"
181
+ headers = {"Accept": "application/json"}
182
+ response = requests.get(url, headers=headers).json()
183
+ return response
184
+
185
+ async def emissions_async(
186
+ self, actor_id: str, ignore_warnings: bool = False, *args, **kwargs
187
+ ):
188
+ """Retrieve actor emissions asynchronously."""
189
+ if ignore_warnings:
190
+ warnings.simplefilter("ignore")
191
+ else:
192
+ warnings.simplefilter("default")
193
+
194
+ endpoint = f"/actor/{actor_id}/emissions"
195
+ url = f"{self.server}{endpoint}"
196
+ headers = {
197
+ "Accept": "application/json",
198
+ "User-Agent": "python-httpx/1.0",
199
+ }
200
+
201
+ async with httpx.AsyncClient() as client:
202
+ response = await client.get(url, headers=headers)
203
+ response.raise_for_status()
204
+ return response.json()
@@ -0,0 +1,23 @@
1
+ from enum import Enum
2
+
3
+ from pydantic import HttpUrl
4
+ from pydantic.dataclasses import dataclass
5
+
6
+
7
+ class Env(str, Enum):
8
+ dev = "dev"
9
+ prod = "prod"
10
+
11
+
12
+ @dataclass
13
+ class Base:
14
+ version: str = "/api/v0"
15
+ env: Env = Env.prod
16
+
17
+ def __post_init__(self):
18
+ urls = {
19
+ Env.dev: "http://127.0.0.1:8000",
20
+ Env.prod: "https://orca-app-5ivtt.ondigitalocean.app",
21
+ }
22
+ self.base_url: HttpUrl = urls[self.env]
23
+ self.server = f"{self.base_url}{self.version}"