Skip to main content

Creates COinS tags from CFF files. Can be used to help Zotero cite your software and datasets.

Project description

cff2coins

Creates COinS tags from CFF files. Can be used to help Zotero cite your software and datasets.

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install cff2coins

Usage

This module allows software developers to generate COinS tags, which are HTML span tags containing citation metadata, from CFF files (e.g., CITATION.cff). They can embed these COinS tags into the views of their web applications so that their software and datasets are citable by citation managers, like Zotero. You can embed multiple COinS tag on a single page and then Zotero will read these tags and allow the user to select which items to import. This module uses the coins-parser module, which can also be used to dynamically create COinS tags for different resources in Python applications.

Convert CFF to a COinS tag

from cff2coins import CffCoinSpan
from pathlib import Path


# print COinS tag from CITATION.cff (e.g., your software or dataset) 
# if you add this span element to your HTML page, then Zotero can read it.
c: CffCoinSpan = CffCoinSpan.from_cff(cff_file_path = Path('CITATION.cff'))
print(c.to_html_string())

Convert CFF references to COinS tags

# print COinS span elements for references in CITATION.cff (e.g., the software dependencies of your software). if you add these span elements to your HTML page, 
# then Zotero can read them and users can pick which resources they want to add to Zotero.

for r in c.references:
    # r is also a CffCoinSpan
    print(r.to_html_string())

Create COinS tags directly

You can also create a CffCoinSpan object directly from a list of tuples containing the metadata. CffCoinSpan uses the CoinSpan type from coins-parser. The CoinSpan is equivalent to list[tuple[str, str]].

from cff2coins import CoinSpan
coin_span: CoinSpan = [
    ("url_ver", "Z39.88-2004"),
    ("ctx_ver", "Z39.88-2004"),
    ("rfr_id", "info:sid/zotero.org:2"),
    ("rft_val_fmt", "info:ofi/fmt:kev:mtx:dc"),
    ("rft.type", "computerProgram"),
    ("rft.title", "MyApp"),
    ("rft.publisher", "Some Company"),
    ("rft.description", "This is an example dummy software for testing."),
    ("rft.identifier", "https://zenodo.org/records/somenumber1"),
    ("rft.aufirst", "Willa"),
    ("rft.aulast", "Biley"),
    ("rft.au", "Willa Biley"),
    ("rft.au", "Wilò Rilü"),
    ("rft.au", "Jil van Hilo"),
    ("rft.date", "2025-04-15"),
]

cff_coin_span: CffCoinSpan = CffCoinSpan.from_coin_span(coin_span=coin_span)

Parse COinS tags from HTML

You can use the CoinsParser class from the coins-parser module directly to parse COinS metadata from an html tag.

from cff2coins import CoinsParser, CoinSpanList

# note that this returns a list of lists, 
# where each list is data for a coins span.
coin_spans: CoinSpanList = CoinsParser.parse(html)
for coin_span in coin_spans:
    cff_coin_span = CffCoinSpan.from_coin_span(coin_span=coin_span)
    print(cff_coin_span.to_html_string())

License

cff2coins is distributed under the terms of the Apache 2.0 license

Contribution

Contributions in the form of feature requests, bug reports, bug fixes, tests, and feature implementations are welcome. To contribute code, please fork the project, and then do a pull request.

Developer Notes

Building Locally

To build the tool locally, please follow the general advice from here.

python3 -m pip install --upgrade build
python3 -m build

Deploying

To deploy the tool, use the Github Action defined in .github/workflows/python-publish.yml

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

cff2coins-1.0.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

cff2coins-1.0.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file cff2coins-1.0.0.tar.gz.

File metadata

  • Download URL: cff2coins-1.0.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for cff2coins-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d55eb424d13e31281e7546353fc577bbfed3dba974163d2ffd11251b2817bae7
MD5 ae4525d7d6af084b31d4c577361e14c4
BLAKE2b-256 911006367a9c920927415bc89e8e570a63c47c69ac99009e9c914e3772650663

See more details on using hashes here.

File details

Details for the file cff2coins-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cff2coins-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for cff2coins-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de0772555456962267250e355ac02a30884857541d1a2ac7740411043c283705
MD5 f0a79815e26c76aba2f16db6ed4e3672
BLAKE2b-256 a3770aafc458249839efd75e02607f0b13afe2f9cf578dad8fec39a19245a7fc

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