python-jref
This python package implements the JSON Reference and JSON Pointer specifications in the context of processing JSON and YAML content, such as Swagger and OpenAPI specifications.
JSON Reference
JSON Reference defines a mechanism to reference and include content from the same or separate documents. This helps with maintenance of structured data and documents by reducing repetition, and allowing for the organization of larger documents across multiple files.
JSON Pointer
JSON Pointer defines a syntax for identifying specific portions of a JSON value.
In a document, a JSON Reference takes the form of an object, mapping '$ref' to a reference; other keys in the object are ignored. The reference itself takes the form of a URI. As an example:
{ "$ref": "http://example.com/example.json#/foo/bar" }
In this implementation, the URI may reference a JSON or YAML file available in the local filesystem, or served from the network over HTTP/HTTPS. The fragment portion of the URI is interpreted as a JSON Pointer.
Usage example
Find the example below also as usage-example.py in the
source repository.
import os
import textwrap
import jref.context
import jref.pointer
# All references are evaluated in a context, so start with one
ctx = jref.context.RemoteContext()
# Reference a remote document
spec = ctx.parse_reference('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml')
# Reference portions of that document
spec_title = spec.context.parse_reference('#/info/title')
spec_version = spec.context.parse_reference('#/info/version')
# Print out the references, not the content (which hasn't been loaded)
print(textwrap.dedent('''
* JSON References
Spec: {}
Title: {}
Version: {}
''')
.lstrip()
.format(spec, spec_title, spec_version))
# Expand references, triggering loading of content
print(textwrap.dedent('''
* Evaluated references
Title: {}
Version: {}
''')
.lstrip()
.format(spec_title.expand(), spec_version.expand()))
Expected output:
* JSON References
Spec: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
Title: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml#/info/title
Version: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml#/info/version
* Evaluated references
Title: Swagger Petstore
Version: 1.0.0
References
- JSON Reference, Internet Draft, https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03
- JSON Pointer, RFC 6901, https://tools.ietf.org/html/rfc6901
Metadata
Release files for jref 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jref-0.4.1.tar.gz | 18.8 kB | Without provenance | Details for jref-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jref-0.4.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for jref-0.4.1-py2.py3-none-any.whl |
Total release size: 41.9 kB
Release files / jref-0.4.1.tar.gz
| Download URL | jref-0.4.1.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea69859bdaf768feb34b1eb46ae52aefc90a4b436a6602ce7a106376373be3e8
|
|
BLAKE2b-256 checksum How to use checksums |
baea3a973f03432453b40f22356be39ae983156ea73cf637629b93fac605f555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / jref-0.4.1-py2.py3-none-any.whl
| Download URL | jref-0.4.1-py2.py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
272db831f52bc461de5b32a1c9d69d9fa9bd2b6de437174c57beea8178ad4215
|
|
BLAKE2b-256 checksum How to use checksums |
7bf3b2c5092d06f48c5eb9c509a6d9d173ebca60905136e3ef723c1bb4109e01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for jref 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.