plastron-repo
Fedora repository resources and operations
Repository
There are several class methods on the Repository class available as
shortcuts to quickly create a Repository object.
# simple repo, no authentication
from plastron.repo import Repository
repo = Repository.from_url('http://localhost:8080/fcrepo/rest')
# repo with HTTP Basic authentication
from plastron.repo import Repository
from requests.auth import HTTPBasicAuth
repo = Repository.from_url(
url='http://localhost:8080/fcrepo/rest',
# any class that implements requests.auth.AuthBase will work here
auth=HTTPBasicAuth('username', 'password'),
)
# repo with settings from a configuration dictionary
from plastron.repo import Repository
repo = Repository.from_config({
'REST_ENDPOINT': 'http://localhost:8080/fcrepo/rest',
'RELPATH': '/',
'REPO_EXTERNAL_URL': 'http://fcrepo-local/fcrepo/rest',
'SERVER_CERT': 'path/to/cert.pem',
# authentication section
'FEDORA_USER': 'username',
'FEDORA_PASSWORD': 'password',
})
# repo with settings from a configuration YAML file;
# the structure of the YAML file is the same as the
# configuration dictionary
from plastron.repo import Repository
repo = Repository.from_config_file('config.yml')
You can always use the full constructor as well.
from requests.auth import HTTPBasicAuth
from plastron.client import Client, Endpoint
from plastron.repo import Repository
repo = Repository(
client=Client(
endpoint=Endpoint(
url='http://localhost:8080/fcrepo/rest',
default_path='/',
external_url='http://fcrepo-local/fcrepo/rest',
),
auth=HTTPBasicAuth('username', 'password'),
server_cert='path/to/cert.pem',
ua_string='my-client/3.14',
on_behalf_of='user',
)
)
Repository Resources
The repository resource classes represent a single URL-addressable HTTP
resource that is stored in a repository. The most basic of these is
RepositoryResource.
from plastron.repo import Repository, RepositoryResource
repo = Repository.from_url('http://localhost:8080/fcrepo/rest')
# Repository object support indexing with a path
resource = repo['/foo']
assert resource.url == 'http://localhost:8080/fcrepo/rest/foo'
assert isinstance(resource, RepositoryResource)
# this is merely syntactic sugar for the get_resource() method
resource = repo.get_resource('/foo')
assert resource.url == 'http://localhost:8080/fcrepo/rest/foo'
assert isinstance(resource, RepositoryResource)
When getting a resource from a Repository, you can provide a class to
instantiate (it defaults to RepositoryResource). So to get an LDP container
representation of a resource, use ContainerResource instead.
from plastron.repo import Repository, ContainerResource
repo = Repository.from_url('http://localhost:8080/fcrepo/rest')
container = repo.get_resource('/bar', ContainerResource)
assert container.url == 'http://localhost:8080/fcrepo/rest/bar'
assert isinstance(container, ContainerResource)
# you can also use slice notation to provide the class
container = repo['/bar':ContainerResource]
assert container.url == 'http://localhost:8080/fcrepo/rest/bar'
assert isinstance(container, ContainerResource)
Retrieving Data
None of the methods above actually send any HTTP requests. To connect to
the repository and retrieve data, use the read() method on a resource.
RDF Descriptions
Repository resources can be described using RDF resource classes defined using the plastron-rdf library. A resource description is an RDF resource class that shares its underlying RDFLib Graph object with a repository resource. Thus changes to the resource description object will be reflected in the repository resource's graph and will be saved when the repository resource is written back to the repository.
Here is an (extremely simplified) example of retrieving a resource, updating some properties, and writing it back to the repository.
from rdflib import Literal, URIRef
from plastron.rdfmapping.resources import RDFResource
from plastron.repo import Repository, ContainerResource
repo = Repository.from_url('http://localhost:8080/fcrepo/rest')
resource = repo['/obj/123':ContainerResource]
resource.read()
# RDFResource is a very simple RDF description class
# it maps rdf:type to rdf_type and rdfs:label to label
obj = resource.describe(RDFResource)
obj.label = Literal('Digital Object 123')
obj.rdf_type.add(URIRef('http://pcdm.org/models#Object'))
assert obj.has_changes
# sends a PATCH request to the repository with a SPARQL
# update query built from the differences between the
# graph read from the repo and the current graph
resource.update()
Binaries
Metadata
Release files for plastron-repo 4.8.3
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 |
|---|---|---|---|---|
| plastron_repo-4.8.3.tar.gz | 19.5 kB | Without provenance | Details for plastron_repo-4.8.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plastron_repo-4.8.3-py3-none-any.whl | Python 3 | none | any | Details for plastron_repo-4.8.3-py3-none-any.whl |
Total release size: 39.7 kB
Release files / plastron_repo-4.8.3.tar.gz
| Download URL | plastron_repo-4.8.3.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0199883985cbbef427b381eb05de6f427e03e1821cf08d2b17bd84dab42c942e
|
|
BLAKE2b-256 checksum How to use checksums |
bf164d8cf99e4c5ab59a9c79267a72f7cb15912c0d37af04d85bdb7d6c53d704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / plastron_repo-4.8.3-py3-none-any.whl
| Download URL | plastron_repo-4.8.3-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf1b6228572a239b6561afeca1c8a25e11aba2ee770355613054316a0bd447bc
|
|
BLAKE2b-256 checksum How to use checksums |
83ed37306819e95a8b6a6c9fcf47be922b4431b50adf59f7846c0991b38d1692
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for plastron-repo 4.8.3
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.