@@ -36,6 +36,19 @@ This particular implementation provides an pip package that can be used by any P
3636 poetry add typeid-python
3737 ```
3838
39+ ### Optional dependencies
40+
41+ TypeID supports schema-based ID explanations using JSON (always available) and
42+ YAML (optional).
43+
44+ To enable YAML support:
45+
46+ ```console
47+ pip install typeid-python[yaml]
48+ ```
49+
50+ If the extra is not installed, JSON schemas will still work.
51+
3952## Usage
4053
4154### Basic
@@ -109,3 +122,158 @@ This particular implementation provides an pip package that can be used by any P
109122 $ typeid encode 0188bac7 - 4afa - 78aa - bc3b- bd1eef28d881 -- prefix prefix
110123 prefix_01h2xcejqtf2nbrexx3vqjhp41
111124 ```
125+
126+ # # ✨ NEW: `typeid explain` — “What is this ID?”
127+
128+ TypeID can now ** explain a TypeID** in a human- readable way.
129+
130+ This is useful when:
131+
132+ * debugging logs
133+ * inspecting database records
134+ * reviewing production incidents
135+ * understanding IDs shared via Slack, tickets, or dashboards
136+
137+ # ## Basic usage (no schema required)
138+
139+ ```console
140+ $ typeid explain user_01h45ytscbebyvny4gc8cr8ma2
141+ ```
142+
143+ Example output:
144+
145+ ``` yaml
146+ id : user_01h45ytscbebyvny4gc8cr8ma2
147+ valid : true
148+
149+ parsed :
150+ prefix : user
151+ suffix : 01h45ytscbebyvny4gc8cr8ma2
152+ uuid : 01890bf0-846f-7762-8605-5a3abb40e0e5
153+ created_at : 2025-03-12T10:41:23Z
154+ sortable : true
155+
156+ schema :
157+ found : false
158+ ` ` `
159+
160+ Even without configuration, ` typeid explain` can:
161+
162+ * validate the ID
163+ * extract the UUID
164+ * derive creation time (UUIDv7)
165+ * determine sortability
166+
167+ # # Schema-based explanations
168+
169+ To make explanations richer, you can define a **TypeID schema** describing what each
170+ prefix represents.
171+
172+ # ## Example schema (`typeid.schema.json`)
173+
174+ ` ` ` json
175+ {
176+ "schema_version": 1,
177+ "types": {
178+ "user": {
179+ "name": "User",
180+ "description": "End-user account",
181+ "owner_team": "identity-platform",
182+ "pii": true,
183+ "retention": "7y",
184+ "links": {
185+ "logs": "https://logs.company/search?q={id}",
186+ "trace": "https://traces.company/?id={id}"
187+ }
188+ }
189+ }
190+ }
191+ ` ` `
192+
193+ # ## Explain using schema
194+
195+ ` ` ` console
196+ $ typeid explain user_01h45ytscbebyvny4gc8cr8ma2
197+ ` ` `
198+
199+ Output (excerpt) :
200+
201+ ` ` ` yaml
202+ schema:
203+ found: true
204+ name: User
205+ owner_team: identity-platform
206+ pii: true
207+ retention: 7y
208+
209+ links:
210+ logs: https://logs.company/search?q=user_01h45ytscbebyvny4gc8cr8ma2
211+ ` ` `
212+
213+ # # Schema discovery rules
214+
215+ If `--schema` is not provided, TypeID looks for a schema in the following order :
216+
217+ 1. Environment variable :
218+
219+ ` ` ` console
220+ TYPEID_SCHEMA=/path/to/schema.json
221+ ` ` `
222+ 2. Current directory :
223+
224+ * `typeid.schema.json`
225+ * `typeid.schema.yaml`
226+ 3. User config directory :
227+
228+ * `~/.config/typeid/schema.json`
229+ * `~/.config/typeid/schema.yaml`
230+
231+ If no schema is found, the command still works with derived information only.
232+
233+ # # YAML schemas (optional)
234+
235+ YAML schemas are supported if the optional dependency is installed :
236+
237+ ` ` ` console
238+ pip install typeid-python[yaml]
239+ ` ` `
240+
241+ Example (`typeid.schema.yaml`) :
242+
243+ ` ` ` yaml
244+ schema_version: 1
245+ types:
246+ user:
247+ name: User
248+ owner_team: identity-platform
249+ links:
250+ logs: "https://logs.company/search?q={id}"
251+ ` ` `
252+
253+ # # JSON output (machine-readable)
254+
255+ ` ` ` console
256+ $ typeid explain user_01h45ytscbebyvny4gc8cr8ma2 --json
257+ ` ` `
258+
259+ Useful for :
260+
261+ * scripts
262+ * CI pipelines
263+ * IDE integrations
264+
265+ # # Design principles
266+
267+ * **Non-breaking**: existing APIs and CLI commands remain unchanged
268+ * **Schema-optional**: works fully offline
269+ * **Read-only**: no side effects or external mutations
270+ * **Declarative**: meaning is defined by users, not inferred by the tool
271+
272+ You can think of `typeid explain` as :
273+
274+ > **OpenAPI — but for identifiers instead of HTTP endpoints**
275+
276+ # # License
277+
278+ MIT
279+
0 commit comments