Skip to main content

A library for building and managing content blocks with standardized representation

Project description

corelab-blockkit

A library for building and managing content blocks.

Python Version License PyPI version

Overview

corelab-blockkit is a CoreLab project that provides a standardized representation of course content as discrete "blocks" that can be serialized, rendered, and extended. It's designed to be lightweight, type-safe, and easily extensible.

Features

  • Core Block Types: TextBlock, ImageBlock, VideoBlock, AudioBlock, DownloadBlock, GlossaryBlock, QuoteBlock, SupplementBlock
  • Serialization: JSON and YAML support
  • Type Registry: Extensible registry for block types
  • Block Operations: Add, remove, move, and find blocks
  • Metadata: Track creation/update times, favorites, tags, and custom metadata
  • Extensibility: Add custom block types without modifying the core library

Installation

pip install corelab-blockkit

Quick Start

from corelab_blockkit import BlockList, TextBlock, ImageBlock

# Create a block list
blocks = BlockList()

# Add a text block
text_block = TextBlock(
    text="Hello **world**! This is a *markdown* formatted text block.",
    format="markdown",
)
blocks = blocks.add(text_block)

# Add an image block
image_block = ImageBlock(
    url="https://example.com/image.jpg",
    alt_text="An example image",
    caption="Figure 1: Example image",
)
blocks = blocks.add(image_block)

# Serialize to JSON
json_str = blocks.to_json(indent=2)
print(json_str)

# Serialize to YAML
yaml_str = blocks.to_yaml()
print(yaml_str)

# Deserialize from JSON
deserialized = BlockList.from_json(json_str)

Plugin Guide

You can extend blockkit with custom block types by creating a plugin. Here's how:

  1. Create a new package with a class that inherits from BaseBlock
  2. Define an entry point in your pyproject.toml:
[project.entry-points."blockkit.blocks"]
my_block = "my_package:MyBlock"
  1. Install your package, and blockkit will automatically discover and register your block type

See the examples/plugin_example directory for a complete example.

JSON Specification

Each block is serialized to JSON with the following structure:

{
  "id": "uuid-string",
  "kind": "block-type",
  "meta": {
    "created_at": "iso-datetime",
    "updated_at": "iso-datetime",
    "is_favorite": false,
    "tags": [],
    "extra": {}
  },
  "payload": {
    // Block-specific content
  }
}

A block list is serialized as:

{
  "blocks": [
    // Array of block objects
  ]
}

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

corelab_blockkit-0.1.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

corelab_blockkit-0.1.1-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file corelab_blockkit-0.1.1.tar.gz.

File metadata

  • Download URL: corelab_blockkit-0.1.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.4.0

File hashes

Hashes for corelab_blockkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a79fc9764a95f8624c9e406246aa152262479366a1f0d499881771f2e7970231
MD5 a2538d19ac94c98cb8ce7fec87ec6c46
BLAKE2b-256 9e6f8c9de415a97fe8f42b423fd8fd386e645af4c6ca3015b3ef4ad3268fb75a

See more details on using hashes here.

File details

Details for the file corelab_blockkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: corelab_blockkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.4.0

File hashes

Hashes for corelab_blockkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db21d71046a4622fbbc280bbb3af6229e45aafcf679d8522ccd96888a7c04c3f
MD5 6f350647629e39e76fcdfc33539cbf56
BLAKE2b-256 202d292f79c1de3b68f3bf7915ced8c0be798cc73432e3fd2dbd98735e720a03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page