Skip to main content

schul_cloud_resources_api_v1

The resources API package allows easy access to the Schul-Cloud resources servers. To get an overview about how the api is defined, please refer to the repository.

Installation

You can install the package with pip from PyPI

pip install schul_cloud_resources_api_v1

Accessing the API

Suppose, a server runs under http://localhost:8080/v1. You can use the api to connect to it. If you do not have a server, you can get a test server from the package schul_cloud_resources_server_tests.

# import the api classes for access
from schul_cloud_resources_api_v1 import ApiClient, ResourceApi

# create the client objects
url = "http://localhost:8080/v1"
client = ApiClient(url)
api = ResourceApi(client)

The api object gives access to the server. Here, you can see how to access the api:

# import the resource examples
from schul_cloud_resources_api_v1.schema import get_valid_examples

# get a valid resource
resource = get_valid_examples()[0]
print(resource)

# add the resource to the server
response = api.add_resource(resource)

# verify the resource is on the server
all_my_resssources_on_the_server = api.get_resource_ids()
assert response.id in all_my_resssources_on_the_server

# get the resource from the server
resource_copy = api.get_resource(response.id)
assert resource_copy == resource

# delete the resource
api.delete_resource(response.id)

Authentication

There are these options for authentication:

  • no authentication: this is the default and nothing needs to be done.

  • basic authentication: authentication with user name and password

  • api_key authentication: a key is supplied to authorize the requests.

The authentication is a global state. All ApiClients use this global state. Thus, you can only authenticate at one API at a time.

import schul_cloud_resources_api_v1.auth as auth

You can remove all authentication. This is the default case.

auth.none()

You can authenticate with username and password. This is Basic Authentication <https://en.wikipedia.org/wiki/Basic_access_authentication>.

auth.basic("username", "password")

You can authenticate with an api key.

auth.api_key("your-api-key")

Verifying Resources

When you use resources, you may want to verify if they have the correct format. The format is specified in the resource-schema. This schema is included in the api.

from schul_cloud_resources_api_v1.schema import (
    get_valid_examples, get_invalid_examples, validate_resource, is_valid_resource
)

You can test if a resource is valid or not using is_valid_resource

valid_resource = get_valid_examples()[0]
assert is_valid_resource(valid_resource)

invalid_resource = get_invalid_examples()[0]
assert not is_valid_resource(invalid_resource)

If you would like to find out more about why the resource is not valid, you can use validate_resource.

validate_resource({'title': 'hello'})

Which results in an error that the url property is not present but is required.

jsonschema.exceptions.ValidationError: 'url' is a required property

Failed validating 'required' in schema:
    {'properties': {'contentCategory': {'$ref': '#/definitions/ContentCategory'},
                    'contextUrl': {'$ref': '#/definitions/URL'},
                    'curricula': {'items': {'$ref': '../curriculum/curriculum.json'},
                                  'type': 'array'},
                    'dimensions': {'$ref': '#/definitions/Dimensions'},
                    'duration': {'type': 'number'},
                    'languages': {'description': 'As described in IEEE '
                                                 'LOM, Section 1.3 '
                                                 'http://129.115.100.158/txlor/docs/IEEE_LOM_1484_12_1_v1_Final_Draft.pdf',
                                  'items': {'$ref': '#/definitions/Language'},
                                  'type': 'array'},
                    'licenses': {'items': {'$ref': '../license/license.json'},
                                 'type': 'array'},
                    'mimeType': {'description': 'https://tools.ietf.org/html/rfc2046',
                                 'example': 'text/html',
                                 'type': 'string'},
                    'size': {'format': 'int64', 'type': 'integer'},
                    'thumbnail': {'$ref': '#/definitions/URL'},
                    'title': {'description': 'The title of the resource.',
                              'example': 'Schul-Cloud',
                              'type': 'string'},
                    'url': {'$ref': '#/definitions/URL'}},
     'required': ['title',
                  'url',
                  'licenses',
                  'mimeType',
                  'contentCategory',
                  'languages'],
     'type': 'object'}

On instance:
    {'title': 'hello'}

Further Reading

Metadata

Release files for schul-cloud-ressources-api-v1 1.0.0.64

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for schul-cloud-ressources-api-v1 1.0.0.64
File Size Uploaded Provenance
schul_cloud_ressources_api_v1-1.0.0.64.tar.gz 22.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for schul-cloud-ressources-api-v1 1.0.0.64
File Interpreter ABI Platform
schul_cloud_ressources_api_v1-1.0.0.64-py3-none-any.whl Python 3 none any Details

Total release size: 72.5 kB

Release files / schul_cloud_ressources_api_v1-1.0.0.64.tar.gz

Download URL schul_cloud_ressources_api_v1-1.0.0.64.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f16f1d39365617664fc217f6aae40cc0ae92078067dad0d6d063754d9b1fd536
BLAKE2b-256 checksum
How to use checksums
5ef99cb1da02c25e11ee5de5f87ce0f9fd89408d0f0fb873d99d3b11870430af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / schul_cloud_ressources_api_v1-1.0.0.64-py3-none-any.whl

Download URL schul_cloud_ressources_api_v1-1.0.0.64-py3-none-any.whl
Size 49.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad782e636adc74d5a196b3cb55b27c3c752d2a3a363c7292ca3959a778d12762
BLAKE2b-256 checksum
How to use checksums
95bac5bcc07940e0b2125f8b1137cd0e3273a1b1a974352e6a8c16fc1ed7b85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for schul-cloud-ressources-api-v1 1.0.0.64

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.

Release history Release notifications | RSS feed

This release

1.0.0.64 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page