Skip to content

Examples

AstorisTheBrave edited this page Aug 30, 2026 · 1 revision

Examples

The repository contains an executable production example for every supported language. Each creates or accepts a UUIDv7 MID, derives an order_ PID, parses it, and asserts that the original MID is recovered.

MID  019d4c72-c910-7a84-b313-53c3ac61a32f
PID  order_01kn675j8gfa2b64tkrep638sf

TypeScript / JavaScript

import { parsePublicId, publicIdFromMachineId } from "@greyfoundry/identifold";

const mid = "019d4c72-c910-7a84-b313-53c3ac61a32f";
const pid = publicIdFromMachineId(mid, "order");
const parsed = parsePublicId(pid, "order");

Run the checked-in example:

pnpm --dir examples/typescript test
pnpm --dir examples/typescript start

Python

from identifold import parse_public_id, public_id_from_machine_id

mid = "019d4c72-c910-7a84-b313-53c3ac61a32f"
pid = public_id_from_machine_id(mid, "order")
parsed = parse_public_id(pid, "order")
python examples/python/basic.py

Java

import io.greyfoundry.identifold.Identifold;

var mid = "019d4c72-c910-7a84-b313-53c3ac61a32f";
var pid = Identifold.publicIdFromMachineId(mid, "order");
var parsed = Identifold.parsePublicId(pid);

Source: examples/java/Basic.java

C#

using Greyfoundry.Identifold;

var mid = "019d4c72-c910-7a84-b313-53c3ac61a32f";
var pid = Identifiers.PublicIdFromMachineId(mid, "order");
var parsed = Identifiers.ParsePublicId(pid);
dotnet run --project examples/csharp/Identifold.Example.csproj

Go

import "github.com/greyfoundry/identifold/packages/go"

mid := "019d4c72-c910-7a84-b313-53c3ac61a32f"
pid, err := identifold.PublicIDFromMachineID(mid, "order")
parsed, err := identifold.ParsePublicID(pid)
cd examples/go
go run .

PHP

use Greyfoundry\Identifold\Identifold;

$mid = '019d4c72-c910-7a84-b313-53c3ac61a32f';
$pid = Identifold::publicIdFromMachineId($mid, 'order');
$parsed = Identifold::parsePublicId($pid);
cd examples/php
composer install
php basic.php

Kotlin

import io.greyfoundry.identifold.KotlinIdentifold

val mid = "019d4c72-c910-7a84-b313-53c3ac61a32f"
val pid = KotlinIdentifold.publicIdFromMachineId(mid, "order")
val parsed = KotlinIdentifold.parsePublicId(pid)

Source: examples/kotlin/Basic.kt

Rust

let mid = "019d4c72-c910-7a84-b313-53c3ac61a32f";
let pid = identifold::public_id_from_machine_id(mid, "order")?;
let parsed = identifold::parse_public_id(&pid)?;
cargo run --locked --manifest-path examples/rust/Cargo.toml

Ruby

require "identifold"

mid = "019d4c72-c910-7a84-b313-53c3ac61a32f"
pid = Identifold.public_id_from_machine_id(mid, "order")
parsed = Identifold.parse_public_id(pid)
cd examples/ruby
bundle install
bundle exec ruby basic.rb

Swift

import Identifold

let mid = "019d4c72-c910-7a84-b313-53c3ac61a32f"
let pid = try Identifiers.publicID(from: mid, namespace: "order")
let parsed = try Identifiers.parsePublicID(pid)
swift run IdentifoldExample

What CI proves

The TypeScript and Python examples are executed by their dedicated workflows. The other eight are executed by their corresponding language jobs. A broken public API example therefore fails one of the 17 checks required on protected main.

See the repository's production example guide for exact source paths and verification commands.

Clone this wiki locally