Skip to main content

Stencila Types for Python

stencila_types

Introduction

This package provides Python classes for types in the Stencila Schema, shortcuts for easily constructing these types, and utilities for loading and saving the types to JSON.

⚡ Usage

Object types

Object types (aka product types) in the Stencila Schema are represented as a dataclass. For example, to construct an article with a single "Hello world!" paragraph, you can construct Article, Paragraph and Text:

from stencila_types.types import Article, CreativeWork, Paragraph, Text, Thing

article = Article(content=[Paragraph(content=[Text(value="Hello world!")])])

assert isinstance(article, Article)
assert isinstance(article, CreativeWork)
assert isinstance(article, Thing)

assert isinstance(article.content[0], Paragraph)

assert isinstance(article.content[0].content[0], Text)

Union types

Union types (aka sum types) in the Stencila Schema are represented as typing.Union. For example, the Block union type is defined like so:

Block = Union[
    Call,
    Claim,
    CodeBlock,
    CodeChunk,
    Division,
    Figure,
    For,
    Form,
    Heading,
...

Enumeration types

Enumeration types in the Stencila Schema are represented as StrEnum. For example, the CitationIntent enumeration is defined like so:

class CitationIntent(StrEnum):
    """
    The type or nature of a citation, both factually and rhetorically.
    """

    AgreesWith = "AgreesWith"
    CitesAsAuthority = "CitesAsAuthority"
    CitesAsDataSource = "CitesAsDataSource"
    CitesAsEvidence = "CitesAsEvidence"
    CitesAsMetadataDocument = "CitesAsMetadataDocument"
    CitesAsPotentialSolution = "CitesAsPotentialSolution"
    CitesAsRecommendedReading = "CitesAsRecommendedReading"
    CitesAsRelated = "CitesAsRelated"

Shortcuts

Constructing complex Stencila types can be more easily constructed using the shortcuts module.

from stencila_types import types as T
from stencila_types import shortcuts as S

# As above
art1 = T.Article(content=[T.Paragraph(content=[T.Text(value="Hello world!")])])

# Using shortcuts
art2 = S.art(S.p("Hello world!"))

assert art1 == art2

Basic JSON support

import json
from stencila_types.utilities import from_json, to_json

# Using shortcuts
art1 = S.art(S.p("Hello world!"))

s = to_json(art1)
assert s.startswith('{"type": "Article", "id": null,')
art2 = from_json(s)

assert art1 == art2

Metadata

Release files for stencila_types 2.18.0

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

Source distribution (sdist)

Source distribution for stencila_types 2.18.0
File Size Uploaded Provenance Actions
stencila_types-2.18.0.tar.gz 30.1 kB Without provenance Details for stencila_types-2.18.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stencila_types 2.18.0
File Interpreter ABI Platform Actions
stencila_types-2.18.0-py3-none-any.whl Python 3 none any Details for stencila_types-2.18.0-py3-none-any.whl

Total release size: 60.5 kB

Release files / stencila_types-2.18.0.tar.gz

Download URL stencila_types-2.18.0.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2212fbfca04f883e28d8d4645e58a5a58d59f3a35753ea33e937a80a48862d44
BLAKE2b-256 checksum
How to use checksums
56215ac87daa4fd59b1e83ee18816988cd48a765569a0b23dfdd06934fd51b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / stencila_types-2.18.0-py3-none-any.whl

Download URL stencila_types-2.18.0-py3-none-any.whl
Size 30.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ff0c118e6ce8a2841c31df40bf05ea9e7e699cc85c67715db9306887f7c370f
BLAKE2b-256 checksum
How to use checksums
0e5b34ac903e5ed951f88aed0044c6e42b455cbfd770a7390285c7fd27bf7c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for stencila_types 2.18.0

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.

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