|
1 | 1 | # PyRepec |
2 | 2 |
|
3 | | - |
| 3 | +[](https://pypi.org/project/pyrepec/) |
| 4 | +[](https://pypi.org/project/pyrepec/) |
4 | 5 |
|
| 6 | +PyRepec is a small Python client for the [RePEc API](https://ideas.repec.org/api.html). |
| 7 | +It provides typed result models, basic in-session caching, and helpers for querying |
| 8 | +authors, publications, bibliographic references, and JEL codes. |
5 | 9 |
|
6 | | -A python client for [RePEc API](https://ideas.repec.org/api.html). |
| 10 | +Current Version: 0.2.2 |
7 | 11 |
|
8 | | -Current Version: 0.2.1 |
| 12 | +## Requirements |
9 | 13 |
|
10 | | -Report any bugs by opening an issue here: (https://github.com/TBD) |
| 14 | +- Python 3.9 or newer |
| 15 | +- A RePEc API token |
11 | 16 |
|
| 17 | +## Installation |
12 | 18 |
|
13 | | -### Usage |
| 19 | +Install the package from PyPI: |
| 20 | + |
| 21 | +```bash |
| 22 | +pip install pyrepec |
| 23 | +``` |
| 24 | + |
| 25 | +## Quick start |
| 26 | + |
| 27 | +Keep the API token outside your source code, for example in the |
| 28 | +`REPEC_TOKEN` environment variable: |
| 29 | + |
| 30 | +```bash |
| 31 | +export REPEC_TOKEN="your-token" |
| 32 | +``` |
| 33 | + |
| 34 | +Create a client and perform a request: |
14 | 35 |
|
15 | 36 | ```python |
| 37 | +import os |
| 38 | + |
16 | 39 | from pyrepec import Repec |
17 | 40 |
|
18 | | -repec = Repec("TOKEN") |
| 41 | +repec = Repec(os.environ["REPEC_TOKEN"]) |
| 42 | +result = repec.get_org_authors("RePEc:edi:bdigvit") |
19 | 43 |
|
20 | | -res = repec.get_org_authors("RePEc:edi:bdigvit") |
| 44 | +if result.error is not None: |
| 45 | + print(f"RePEc error {result.error.code}: {result.error.message}") |
| 46 | +else: |
| 47 | + for author in result.data: |
| 48 | + print(author) |
21 | 49 | ``` |
22 | 50 |
|
| 51 | +Successful responses expose their payload through `result.data`. Errors reported |
| 52 | +by RePEc are available through `result.error`; in that case, `result.data` is |
| 53 | +empty. HTTP errors are raised by `requests` in the usual way. |
23 | 54 |
|
24 | | -### Installation |
| 55 | +## Available methods |
25 | 56 |
|
26 | | -1. Installation using pip: |
| 57 | +| Method | Description | Result type | |
| 58 | +| --- | --- | --- | |
| 59 | +| `get_org_authors(org_id)` | Get the authors associated with an organization. | `RepecResultList` | |
| 60 | +| `get_author_data(author_id)` | Get the full record for an author. | `RepecSingleResult` | |
| 61 | +| `get_authors_for_item(item_id)` | Get the authors of a paper or article. | `RepecResultList` | |
| 62 | +| `get_jel_codes(item_id)` | Get the JEL codes associated with an item. | `RepecJelResult` | |
| 63 | +| `get_ref(item_id)` | Get the bibliographic references for an item. | `RepecSingleResult` | |
| 64 | +| `get_error(err_code)` | Resolve a RePEc error code into its function and description. | `tuple[str, str]` | |
| 65 | + |
| 66 | +The exact dictionaries returned in `data` follow the upstream RePEc API response |
| 67 | +format. |
| 68 | + |
| 69 | +## Development |
| 70 | + |
| 71 | +Clone the repository and install the locked development environment: |
27 | 72 |
|
28 | 73 | ```bash |
29 | | -pip install pyrepec |
| 74 | +git clone https://github.com/andrea-cap/pyrepec.git |
| 75 | +cd pyrepec |
| 76 | +uv sync --locked |
30 | 77 | ``` |
31 | 78 |
|
| 79 | +Run the test suite and code-quality checks: |
32 | 80 |
|
33 | | -### Methods |
| 81 | +```bash |
| 82 | +uv run pytest ./tests/ |
| 83 | +uv run ruff check . |
| 84 | +uv run ruff format --check . |
| 85 | +``` |
| 86 | + |
| 87 | +Integration tests require `REPEC_TOKEN`; without it, they are skipped. Unit tests |
| 88 | +do not make external API calls. |
| 89 | + |
| 90 | +Generate the changelog from the available Git history: |
| 91 | + |
| 92 | +```bash |
| 93 | +uv run gitchangelog |
| 94 | +``` |
34 | 95 |
|
35 | | -Featured methods: |
| 96 | +## Reporting issues |
36 | 97 |
|
37 | | -- get_org_authors(org_id: str) |
38 | | -- get_author_data(author_id: str) |
39 | | -- get_authors_for_item(item_id: str) |
40 | | -- get_jel_codes(item_id: str) |
41 | | -- get_error(err_code: int) |
42 | | -- get_ref(item_id: str) |
| 98 | +Report bugs and request features through the |
| 99 | +[GitHub issue tracker](https://github.com/andrea-cap/pyrepec/issues). |
0 commit comments