|
1 |
| -# schemastorepy |
| 1 | +# schematore.py |
2 | 2 |
|
3 |
| -Contains all JSON Schemas from [schemastore.org](https://schemastore.org) |
4 |
| -catalog so you can make use of them without needing internet access. |
| 3 | +A collection of all JSON Schemas from the [schemastore.org](https://schemastore.org) catalog, installable so they may be used without internet access. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Use your favorite package manager, e.g. via: |
| 8 | + |
| 9 | + $ uv pip install schemastore |
| 10 | + |
| 11 | +or |
| 12 | + |
| 13 | + $ pip install schemastore |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Schemas are made usable as a [`referencing.Registry`](https://referencing.readthedocs.io/en/stable/api/#referencing.Registry). |
| 18 | +It is available as: |
5 | 19 |
|
6 |
| -## How to use |
7 | 20 |
|
8 | 21 | ```python
|
9 |
| -from schemastore import Store |
| 22 | +import schemastore |
| 23 | +registry = schemastore.registry() |
| 24 | +``` |
| 25 | + |
| 26 | +and use any of the API from the aforementioned referencing package to make use of the schemas, such as: |
| 27 | + |
| 28 | +```python |
| 29 | +print(registry.get_or_retrieve("https://json.schemastore.org/github-action.json").value) |
10 | 30 |
|
11 |
| -store = Store(days=30) |
12 |
| -my_schema_json = store.get('http://...') # <-- no network access happens |
13 | 31 | ```
|
14 | 32 |
|
15 |
| -The `days` parameter is optional and defaults to 30, which means that after |
16 |
| -this it will start checking if the locally cached schema is up to date and |
17 |
| -refresh it it needed. `store.catalog` would contain |
18 |
| -the content of the catalog itself. |
| 33 | +though more typically you will use the registry alongside a JSON Schema validator such as those provided by the [`jsonschema` library](https://python-jsonschema.readthedocs.io/): |
| 34 | + |
| 35 | +```python |
| 36 | +import jsonschema |
| 37 | +import schemastore |
19 | 38 |
|
20 |
| -## Stats |
21 | 39 |
|
22 |
| -- Over 500 JSON Schemas in the catalog |
23 |
| -- ~2.5Mib package size |
24 |
| -- ~30Mib installed size |
| 40 | +# Validate whether the string "foo" is a valid GitHub actions workflow (it is not.) |
| 41 | +jsonschema.validate( |
| 42 | + '"foo"', |
| 43 | + {"$ref": "https://json.schemastore.org/github-action.json"}, |
| 44 | + registry=schemastore.registry(), |
| 45 | +) |
| 46 | +``` |
0 commit comments