openedx.core.djangoapps.content_libraries.rest_api package#
Submodules#
openedx.core.djangoapps.content_libraries.rest_api.blocks module#
openedx.core.djangoapps.content_libraries.rest_api.collections module#
Collections API Views
- class openedx.core.djangoapps.content_libraries.rest_api.collections.LibraryCollectionsView(*args, **kwargs)#
Bases:
ModelViewSetViews to get, create and update Library Collections.
- create(request: _ForbidInit, *args, **kwargs) Response#
Create a Collection that belongs to a Content Library
- destroy(request: _ForbidInit, *args, **kwargs) Response#
Soft-deletes a Collection that belongs to a Content Library
- get_content_library() ContentLibrary#
Returns the requested ContentLibrary object, if access allows.
- get_object() Collection#
Returns the requested Collections, if access allows.
This method may raise exceptions; these are handled by the @convert_exceptions wrapper on the views.
- get_queryset() QuerySet#
Returns a queryset for the requested Collections, if access allows.
This method may raise exceptions; these are handled by the @convert_exceptions wrapper on the views.
- list(request: _ForbidInit, *args, **kwargs) Response#
List Collections that belong to Content Library
- lookup_field = 'collection_code'#
- lookup_url_kwarg = 'key'#
- partial_update(request: _ForbidInit, *args, **kwargs) Response#
Update a Collection that belongs to a Content Library
- restore(request: _ForbidInit, *args, **kwargs) Response#
Restores a soft-deleted Collection that belongs to a Content Library
- retrieve(request: _ForbidInit, *args, **kwargs) Response#
Retrieve the Content Library Collection
- serializer_class#
alias of
ContentLibraryCollectionSerializer
- update_items(request: _ForbidInit, *args, **kwargs) Response#
Adds (PATCH) or removes (DELETE) items to/from a Collection.
Collection and items must all be part of the given library/learning package.
openedx.core.djangoapps.content_libraries.rest_api.containers module#
REST API views for containers (sections, subsections, units) in content libraries
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerChildrenView(**kwargs)#
Bases:
GenericAPIViewView to get or update children of specific container (a section, subsection, or unit)
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- delete(request, container_key: LibraryContainerLocator)#
Remove items from container Example: DELETE /api/libraries/v2/containers/<container_key>/children/ Request body: {“usage_keys”: [‘lb:CL-TEST:containers:problem:Problem1’, ‘lb:CL-TEST:containers:html:Html1’]}
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request, container_key: LibraryContainerLocator)#
Get children of given container Example: GET /api/libraries/v2/containers/<container_key>/children/ Result: [
- {
‘block_type’: ‘problem’, ‘can_stand_alone’: True, ‘collections’: [], ‘created’: ‘2025-03-21T13:53:55Z’, ‘def_key’: None, ‘display_name’: ‘Blank Problem’, ‘has_unpublished_changes’: True, ‘id’: ‘lb:CL-TEST:containers:problem:Problem1’, ‘last_draft_created’: ‘2025-03-21T13:53:55Z’, ‘last_draft_created_by’: ‘Bob’, ‘last_published’: None, ‘modified’: ‘2025-03-21T13:53:55Z’, ‘published_by’: None,
}, {
‘block_type’: ‘html’, ‘can_stand_alone’: False, ‘collections’: [], ‘created’: ‘2025-03-21T13:53:55Z’, ‘def_key’: None, ‘display_name’: ‘Text’, ‘has_unpublished_changes’: True, ‘id’: ‘lb:CL-TEST:containers:html:Html1’, ‘last_draft_created’: ‘2025-03-21T13:53:55Z’, ‘last_draft_created_by’: ‘Bob’, ‘last_published’: None, ‘modified’: ‘2025-03-21T13:53:55Z’, ‘published_by’: None,
}
]
- patch(request, container_key: LibraryContainerLocator)#
Replace items in container, can be used to reorder items as well. Example: PATCH /api/libraries/v2/containers/<container_key>/children/ Request body: {“usage_keys”: [‘lb:CL-TEST:containers:problem:Problem1’, ‘lb:CL-TEST:containers:html:Html1’]}
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request, container_key: LibraryContainerLocator)#
Add items to container Example: POST /api/libraries/v2/containers/<container_key>/children/ Request body: {“usage_keys”: [‘lb:CL-TEST:containers:problem:Problem1’, ‘lb:CL-TEST:containers:html:Html1’]}
- serializer_class#
alias of
LibraryXBlockMetadataSerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerCollectionsView(**kwargs)#
Bases:
GenericAPIViewView to set collections for a container.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- patch(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Sets Collections for a Component.
Collection and Components must all be part of the given library/learning package.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerCopyView(**kwargs)#
Bases:
GenericAPIViewView to copy a container to clipboard
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Copy a Container to clipboard
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerCreationEntryView(**kwargs)#
Bases:
APIViewView to get the creation entry for a library container.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Get the creation entry for a library container (the moment it was first saved).
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
LibraryHistoryEntrySerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerDraftHistoryView(**kwargs)#
Bases:
GenericAPIViewView to get the draft change history of a library container.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Get the draft change history for a library containers since its last publication.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
LibraryHistoryEntrySerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerHierarchy(**kwargs)#
Bases:
GenericAPIViewView to return the full hierarchy of containers that contain and are contained by a library container.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Fetches and returns the full container hierarchy for the given library block.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
ContainerHierarchySerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerPublishHistoryView(**kwargs)#
Bases:
GenericAPIViewView to get the publish history of a library container as a list of publish events.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Get the publish history for a library container, ordered most-recent-first.
Each group in the response represents one publish event for one entity (the container itself or a descendant component). Use entity_key from each group together with the publish_history_entries/ endpoint to fetch the individual draft change entries for that group.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
LibraryPublishHistoryGroupSerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerPublishView(**kwargs)#
Bases:
GenericAPIViewView to publish a container, or revert to last published.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request: _ForbidInit, container_key: LibraryContainerLocator) Response#
Publish the container and its children
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerRestore(**kwargs)#
Bases:
GenericAPIViewView to restore soft-deleted library containers.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request, container_key: LibraryContainerLocator) Response#
Restores a soft-deleted library container
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainerView(**kwargs)#
Bases:
GenericAPIViewView to retrieve, delete or update data about a specific container (a section, subsection, or unit)
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- delete(request, container_key: LibraryContainerLocator)#
Delete a Container (soft delete).
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- get(request, container_key: LibraryContainerLocator)#
Get information about a container
- patch(request, container_key: LibraryContainerLocator)#
Update a Container.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
LibraryContainerMetadataSerializer
- class openedx.core.djangoapps.content_libraries.rest_api.containers.LibraryContainersView(**kwargs)#
Bases:
GenericAPIViewViews to work with Containers in a specific content library.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- dispatch(request, *args, **kwargs)#
.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- post(request, lib_key_str)#
Create a new Container in this content library
- serializer_class#
alias of
LibraryContainerMetadataSerializer
openedx.core.djangoapps.content_libraries.rest_api.libraries module#
openedx.core.djangoapps.content_libraries.rest_api.serializers module#
Serializers for the content libraries REST API
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.CollectionMetadataSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for CollectionMetadata
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContainerHierarchyMemberSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for the members of a hierarchy, which can be either Components or Containers.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContainerHierarchySerializer(*args, **kwargs)#
Bases:
SerializerSerializer which represents the full hierarchy of containers and components that contain and are contained by a given library container or library block.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryAddPermissionByEmailSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for adding a new user and granting their access level via their email address.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryCollectionSerializer(*args, **kwargs)#
Bases:
ModelSerializerSerializer for a Content Library Collection
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryCollectionUpdateSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for updating a Collection in a Content Library
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryFilterSerializer(*args, **kwargs)#
Bases:
SerializerBase serializer for filtering listings on the content library APIs.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryItemCollectionsUpdateSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for adding/removing Collections to/from a Library Item (component, unit, etc..).
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryItemContainerKeysSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for adding/removing items to/from a Container.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryItemKeysSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for adding/removing items to/from a Collection.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryMetadataSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for ContentLibraryMetadata
- get_can_edit_library(obj)#
Verifies if the user in request has permission to edit a library.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryPermissionLevelSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for the “Access Level” of a ContentLibraryPermission object.
This is used when updating a user or group’s permissions re some content library.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryPermissionSerializer(*args, **kwargs)#
Bases:
ContentLibraryPermissionLevelSerializerSerializer for a ContentLibraryPermission object, which grants either a user or a group permission to view a content library.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.ContentLibraryUpdateSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for updating an existing content library
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.DirectPublishedEntitySerializer(*args, **kwargs)#
Bases:
SerializerSerializer for one entity the user directly requested to publish (direct=True).
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryBackupResponseSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for the response after requesting a backup of a content library.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryBackupTaskStatusSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for checking the status of a library backup task.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryContainerMetadataSerializer(*args, **kwargs)#
Bases:
PublishableItemSerializerSerializer for Containers like Sections, Subsections, Units
Converts from ContainerMetadata to JSON-compatible data
- to_internal_value(data: dict)#
Convert JSON-ish data back to native python types. Returns a dictionary, not a ContainerMetadata instance.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryContainerUpdateSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for updating metadata for Containers like Sections, Subsections, Units
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryHistoryContributorSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for a contributor in a publish history group.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryHistoryEntrySerializer(*args, **kwargs)#
Bases:
SerializerSerializer for a single entry in the history of a library item.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryPublishHistoryGroupSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for a publish event summary in the publish history of a library item.
- get_published_by(obj) str | None#
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryRestoreFileSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for restoring a library from a backup file.
- validate_file(value)#
Validate that the uploaded file is a ZIP file.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryRestoreTaskRequestSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for requesting the status of a library restore task.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryRestoreTaskResultSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for the result of a library restore task.
- classmethod from_task_status(task_status, request)#
Build serializer input from task status object.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockCreationSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for adding a new XBlock to a content library
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockMetadataSerializer(*args, **kwargs)#
Bases:
PublishableItemSerializerSerializer for LibraryXBlockMetadata
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockOlxSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for representing an XBlock’s OLX
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockStaticFileSerializer(*args, **kwargs)#
Bases:
SerializerSerializer representing a static file associated with an XBlock
Serializes a LibraryXBlockStaticFile (or a BundleFile)
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockStaticFilesSerializer(*args, **kwargs)#
Bases:
SerializerSerializer representing a static file associated with an XBlock
Serializes a LibraryXBlockStaticFile (or a BundleFile)
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.LibraryXBlockTypeSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for LibraryXBlockType
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.OpaqueKeySerializer(*args, **kwargs)#
Bases:
BaseSerializerSerializes a OpaqueKey with the correct class.
- to_internal_value(value: str) OpaqueKey#
Returns a LibraryUsageLocatorV2 or a LibraryContainerLocator from the string value.
Raises ValidationError if invalid UsageKeyV2 or LibraryContainerLocator.
- to_representation(value: OpaqueKey) str#
Returns the OpaqueKey value as a string.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.PublishableItemSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for any PublishableItem in a library (XBlock, Container, etc.)
- get_id(obj) str#
Get a unique ID for this PublishableItem
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.RestoreSuccessDataSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for the data returned upon successful restoration of a library.
- get_created_by(obj)#
Get the user information of the archive creator, if available.
The information is stored in the backup metadata of the archive and references a user that may not exist in the system where the restore is being performed.
- get_org(obj) str#
The org code/slug, as parsed from archive_package_ref, or “unknown” if unparseable.
- get_slug(obj) str#
The library code/slug, as parsed from archive_package_ref, or “unknown” if unparseable.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.UnionLibraryMetadataSerializer(*args, **kwargs)#
Bases:
SerializerUnion serializer for swagger api response.
- class openedx.core.djangoapps.content_libraries.rest_api.serializers.UsageKeyV2Serializer(*args, **kwargs)#
Bases:
BaseSerializerSerializes a library Component (XBlock) key.
- to_internal_value(value: str) LibraryUsageLocatorV2#
Returns a LibraryUsageLocatorV2 from the string value.
Raises ValidationError if invalid LibraryUsageLocatorV2.
- to_representation(value: LibraryUsageLocatorV2) str#
Returns the LibraryUsageLocatorV2 value as a string.
openedx.core.djangoapps.content_libraries.rest_api.url_converters module#
URL pattern converters https://docs.djangoproject.com/en/5.1/topics/http/urls/#registering-custom-path-converters
- class openedx.core.djangoapps.content_libraries.rest_api.url_converters.LibraryContainerLocatorConverter#
Bases:
object- Converter that matches library container IDs like:
lct:CL-TEST:containers:unit:u1
- regex = '[\\w-]+(:[\\w\\-.]+)+'#
- to_python(value: str) LibraryContainerLocator#
- to_url(value: LibraryContainerLocator) str#
openedx.core.djangoapps.content_libraries.rest_api.utils module#
REST API utilities for content libraries
- openedx.core.djangoapps.content_libraries.rest_api.utils.convert_exceptions(fn)#
Catch any Content Library API exceptions that occur and convert them to DRF exceptions so DRF will return an appropriate HTTP response