ucsschool.http_api package

Submodules

ucsschool.http_api.client module

HTTP API Client

ucsschool.http_api.client.register_resource_client_class(cls)[source]
ucsschool.http_api.client.get_resource_client_classes()[source]
ucsschool.http_api.client.register_resource_representation_class(resource_name, cls)[source]
ucsschool.http_api.client.get_resource_representation_classes(resource_name)[source]
exception ucsschool.http_api.client.ApiError(msg, status_code=None)[source]

Bases: exceptions.Exception

exception ucsschool.http_api.client.BadRequest(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

HTTP 400

exception ucsschool.http_api.client.PermissionError(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

HTTP 401|403

exception ucsschool.http_api.client.ObjectNotFound(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

HTTP 404

exception ucsschool.http_api.client.ServerError(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

HTTP 5xx

exception ucsschool.http_api.client.ConnectionError(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

Cannot establish / lost connection to server.

exception ucsschool.http_api.client.IllegalURLError(msg, status_code=None)[source]

Bases: ucsschool.http_api.client.ApiError

URLs returned from API root do not meet expectation.

class ucsschool.http_api.client._ResourceClientMetaClass[source]

Bases: type

Meta class for resource client classes. Registers them.

class ucsschool.http_api.client._ResourceRepresentationMetaClass[source]

Bases: type

Meta class for resource representation classes. Registers them.

class ucsschool.http_api.client.ResourceRepresentationIterator(resource_client, paginated_resource_list)[source]

Iterator for paginated query results.

next()[source]
class ucsschool.http_api.client.ResourceRepresentation[source]

Bases: object

Python representations of HTTP-API resources.

To add resources to the Python API create inner classes that 1. subclass _ResourceReprBase 2. use as meta class _ResourceRepresentationMetaClass 3. set a class attribute resource_name that matches the resource path in the HTTP-API

The meta class will register the resource representation class and make it available through Client objects.

client = Client(<username>, <password>, [log level]) client.school.list() # <– from SchoolResource client.userimportjob.create() # <– from UserImportJobResource

class _ResourceReprBase(resource_client, resource)[source]

Bases: object

Base class of resource representation classes.

resource_name = u''
_attribute_repr = {}
_set_attrs(resource)[source]
update()[source]
class ResourceRepresentation.SchoolResource(resource_client, resource)[source]

Bases: ucsschool.http_api.client._ResourceReprBase

resource_name = u'schools'
roles

Roles the connected user has in this school.

Returns:RoleResource objects
Return type:ResourceRepresentationIterator
user_imports

UserImportJobs that ran for this school.

Returns:UserImportJobResource objects
Return type:ResourceRepresentationIterator
class ResourceRepresentation.RoleResource(resource_client, resource)[source]

Bases: ucsschool.http_api.client._ResourceReprBase

resource_name = u'roles'
class ResourceRepresentation.ResultResource(resource_client, resource)[source]

Bases: ucsschool.http_api.client._ResourceReprBase

resource_name = u'result'
_attribute_repr = {u'date_done': <function <lambda>>}
class ResourceRepresentation.UserImportJobResource(resource_client, resource)[source]

Bases: ucsschool.http_api.client._ResourceReprBase

Representation of an import job resource.

job = client.userimportjob.get(job_id)

  • job.status
  • job.result
  • job.log_file
  • job.password_file
  • job.school
  • job.summary_file
resource_name = u'imports/users'
_attribute_repr = {u'date_created': <function <lambda>>}
log_file
password_file
school
summary_file
result
_cached_school
classmethod ResourceRepresentation.get_repr(resource_client, resource)[source]
class ucsschool.http_api.client.Client(name, password, server=None, version=1, log_level=20, ssl_verify=True, *args, **kwargs)[source]

Bases: object

HTTP-API import client.

client = Client(username, password) my_schools = client.school.list() my_roles_at_school1 = client.school.get(‘school1’).roles job_id = client.userimportjob.create() client.userimportjob.get(job_id)

UCS@school HTTP API client.

Parameters:
  • name (str) – username for connecting to HTTP-API
  • password (str) – password to use for connecting to HTTP-API
  • server (str) – FQDN of server running the HTTP-API
  • version (str) – HTTP-API version, omit to use latest version
  • log_level (int) – log level, use logging.{INFO,DEBUG,..} or Client.LOG_REQUEST to log API requests, Client.LOG_RESPONSE to log both requests and responses
LOG_REQUEST = 5
LOG_RESPONSE = 4
resource_urls
classmethod _setup_logging(log_level)[source]
call_api(method, url_end, data=None, files=None, params=None, **kwargs)[source]

Call HTTP-API.

Parameters:
  • method (str) – get, post etc
  • url_end (str) – URL path after base URL (https://<server>/api/<version>/<url_end>)
  • data (dict) – payload
  • files (dict) – {‘<key>’: (<filename>, <open file>, <mime type>)}
  • params (dict) – URL parameters
  • kwargs (dict) – additional arguments to pass to request
Returns:

server response

Return type:

dict

Raises:

ApiError

class _ResourceClient(client)[source]

Bases: object

resource_name = u''
pk_name = u''
_to_python(resource)[source]
_resource_from_url(url, **params)[source]
_get_resource(pk, **params)[source]
_list_resource(**params)[source]
get(pk)[source]

Read Resource.

Parameters:pk (str) – primary key (name, id, ..)
Returns:Resource object
Return type:_ResourceReprBase
latest(**params)[source]

Get newest Resource this user has access to.

All arguments will be passed as parameters to the request. Example: latest(dryrun=True)

Parameters:params – arguments to pass as parameters to the request
Returns:Resource object
Return type:ResourceRepresentation
list(**params)[source]

List all Resource this user has access to.

All arguments will be passed as parameters to the request. Example: list(status=[‘Aborted’, ‘Finished’], dryrun=False, ordering=’id’, limit=1)

Parameters:params – arguments to pass as parameters to the request
Returns:list of Resource objects
Return type:ResourceRepresentationIterator
class Client._School(client)[source]

Bases: ucsschool.http_api.client._ResourceClient

resource_name = u'schools'
pk_name = u'name'
class Client._Roles(client)[source]

Bases: ucsschool.http_api.client._ResourceClient

resource_name = u'roles'
pk_name = u'name'
class Client._UserImportJob(client)[source]

Bases: ucsschool.http_api.client._ResourceClient

resource_name = u'imports/users'
pk_name = u'id'
create(filename, source_uid=None, school=None, user_role=None, dryrun=True, file_obj=None)[source]

Create a UserImportJob.

Parameters:
  • filename (str) – path to a CSV file, or just a filename and read from ‘file_obj’
  • source_uid (str) – optional unique ID of school management software database
  • school (str) – optional name of a School
  • user_role (str) – optional role of user, one of staff, student, teacher, teacher_and_staff
  • dryrun (bool) – False to start a real import
  • file_obj (file) – optional file like object to read CSV data from, instead of opening ‘filename’
Returns:

the created UserImportJob resource

Return type:

_ResourceReprBase

static _get_mime_type(data)[source]

ucsschool.http_api.manage module