🐍 Python Bindings
ACORN seeks to meet scientists where they are in all aspects. This includes the programming languages they use. The acorn-py package provides Python bindings to the core ACORN functionalities provided by the acorn-lib Rust crate.
Installation
- See the PyPI page for installation and usage instructions
- Use
acorn-libfunctions in Pythonfrom acorn.schema.validate import is_ark, is_doi, is_orcid, is_ror assert is_ark("ark:/1234/w5678") assert is_doi("10.11578/dc.20250604.1") assert is_orcid("https://orcid.org/0000-0002-2057-9115") assert is_ror("01qz5mb56")
Working with scientific artifact identifiers
The acorn-py package provides tools to work with common scientific artifact identifiers such as DOIs, ARKs, ORCIDs, and RORs and other indirectly related identifiers such as patent numbers and books (e.g., ISBNs). You can validate these identifiers, work with their components, and even extract them from text!
Tip
See the acorn-lib documentation for more details on persistent identifiers and how to work with them in your code.
Example
Find all patent numbers in a string
🐍 Python
from acorn.schema.pid import Patent
text = "The patent number for my work is US1234567B1."
values = Patent.find_all(text)
patent = values[0]
assert str(patent) == "US 1234567 B1"
assert patent.country_code == "US"
assert patent.serial_number == "1234567"
assert patent.kind_code == "B1"
🦀 Rust
#![allow(unused)]
fn main() {
use acorn::schema::pid::Patent;
let text = "The patent number for my work is US1234567B1.";
let values = Patent::find_all(&text);
let patent = values[0];
assert_eq!(patent.to_string(), "US 1234567 B1");
}
API Consistency
The acorn-py API strives to adhere to the Rust API as closely as possible. If you know acorn-lib, you know acorn-py.
Validate DOIs
🦀 Rust
#![allow(unused)]
fn main() {
use acorn::schema::validate::DOI;
assert!("10.11578/dc.20250604.1".is_doi());
}
🐍 Python
from acorn.schema.validate import is_doi
assert is_doi("10.11578/dc.20250604.1")
Find all DOI values in a string
🦀 Rust
#![allow(unused)]
fn main() {
use acorn::schema::pid::DOI;
let pid = "https://doi.org/10.11578/dc.20250604.1";
let text = format!("The DOI for ACORN is: {pid}");
let values = DOI::find_all(&text);
assert_eq!(values[0].identifier(), "10.11578/dc.20250604.1");
}
🐍 Python
from acorn.schema.pid import DOI
pid = "https://doi.org/10.11578/dc.20250604.1"
text = f"The DOI for ACORN is: {pid}"
values = DOI.find_all(text)
assert values[0].identifier == "10.11578/dc.20250604.1"