Skip to main content

cite_exchange

A Python library for parsing and working with CITE EXchange (CEX) format data.

Overview

cite_exchange provides tools for reading and processing data in CITE EXchange format, a line-oriented text format for managing structured data about scholarly resources. CEX files are organized into labeled blocks, where each block contains tabular data relevant to a specific resource type.

Installation

pip install cite_exchange

Requirements

  • Python 3.13.7+

Quick Start

from cite_exchange.blocks import CexBlock

# Parse from a string
with open('data.cex', 'r') as f:
    content = f.read()
all_blocks = CexBlock.from_text(content)

# Parse directly from a file
all_blocks = CexBlock.from_file('data.cex')

# Parse directly from a URL
all_blocks = CexBlock.from_url('https://example.com/data.cex')

# Filter by label
ctsdata_blocks = CexBlock.from_file('data.cex', label='ctsdata')

# Access block data
for block in ctsdata_blocks:
    print(f"Label: {block.label}")
    print(f"Data lines: {len(block.data)}")
    for line in block.data:
        print(f"  {line}")

API Reference

CexBlock

A dataclass representing a labeled block of text data from a CEX source.

marimo + WASM

The package is pure Python and can be used in marimo notebooks compiled to HTML/WASM.

In a marimo notebook, install from a wheel URL (or local wheel served over HTTP):

import micropip
await micropip.install("https://<your-host>/cite_exchange-0.2.0-py3-none-any.whl")

from cite_exchange import CexBlock

For browser environments, prefer CexBlock.from_text(...) with already-loaded content.

An example marimo notebook script is included at examples/marimo_wasm_notebook.py.

Run locally:

marimo edit examples/marimo_wasm_notebook.py

Then export with your installed marimo HTML/WASM export command (this can vary by version).

Attributes

  • label (str): The label identifier for this block (without the #! prefix)
  • data (list[str]): List of data lines in this block, excluding empty lines and comments

Methods

CexBlock.from_text(src: str, label: str = None) -> list[CexBlock]

Parse CEX-formatted text and create CexBlock instances.

Parameters:

  • src (str): The CEX-formatted text to parse
  • label (str, optional): If specified, only return blocks matching this label

Returns: A list of CexBlock instances

Parsing Rules:

  • Label lines begin with #! and define the start of a new block
  • Data lines are non-empty and don't start with // (comments are ignored)
  • Multiple blocks can have the same label type
  • Empty lines and comment lines are excluded from block data

Example:

# Parse all blocks
blocks = CexBlock.from_text(cex_content)

# Parse only specific label type
catalog_blocks = CexBlock.from_text(cex_content, label='ctscatalog')

Utility Functions

labels(s: str) -> list[str]

Extract all unique labels from a CEX-formatted string.

Returns: Sorted list of unique label names

from cite_exchange.blocks import labels

with open('data.cex', 'r') as f:
    content = f.read()

label_list = labels(content)
print(label_list)  # ['citecollections', 'citedata', 'citeproperties', ...]

valid_label(label: str) -> bool

Check if a label is valid according to CEX format specification.

Valid labels:

  • cexversion
  • citelibrary
  • ctsdata
  • ctscatalog
  • citecollections
  • citeproperties
  • citedata
  • imagedata
  • datamodels
  • citerelationset
  • relationsetcatalog
from cite_exchange.blocks import valid_label

print(valid_label('ctsdata'))    # True
print(valid_label('invalid'))    # False

CEX Format Overview

CEX (CITE EXchange) is a line-oriented format for exchanging data about scholarly resources. Key features:

  • Line-oriented structure: Data organized into lines and blocks
  • Labeled blocks: Each block starts with a #!label line
  • Tabular data: Blocks contain pipe-delimited (|) or other delimited data
  • Comments: Lines starting with // are comments and ignored
  • Empty lines: Empty lines are ignored

Example CEX Content

#!ctscatalog
urn|citationScheme|groupName|workTitle
urn:cts:greekLit:tlg0012.tlg001:|book|Homer|Iliad

#!ctsdata
urn:cts:greekLit:tlg0012.tlg001:1.1|Μῆνις ἀ εἴδε θεά
urn:cts:greekLit:tlg0012.tlg001:1.2|Πηληϊάδεω Ἀχιλῆος

Testing

The package includes comprehensive unit tests covering all functionality:

python -m pytest test/test_blocks.py

Test data files are included in test/data/:

  • burneysample.cex: Sample CEX data from the Homer Multitext project
  • laxlibrary1.cex: Sample CITE collection data

License

See LICENSE file for details.

References

Release files for cite-exchange 0.3.2

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

Source distribution (sdist)

Source distribution for cite-exchange 0.3.2
File Size Uploaded
cite_exchange-0.3.2.tar.gz 25.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cite-exchange 0.3.2
File Interpreter ABI Platform
cite_exchange-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 42.6 kB

Release files / cite_exchange-0.3.2.tar.gz

Download URL cite_exchange-0.3.2.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7498280e80130fb65813ec6220100502b15a673039ef21d6297fc89df13bbb2f
BLAKE2b-256 checksum
How to use checksums
48a4f111e38b90719afe5f416a7b893c0a0e5358d9c6257007ffa86273d0fba3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 5, 2026.

Transparency log

Release files / cite_exchange-0.3.2-py3-none-any.whl

Download URL cite_exchange-0.3.2-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ebb3e8e51120125d65b70e3a583f4f60d399c34d02b7de7ba9cd79b5afe0b55
BLAKE2b-256 checksum
How to use checksums
596cffde024b13d574045e5cef02bc31816d217cdfb15d0c2a0a268e2638ef45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

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