Skip to content

Commit 6e8e51c

Browse files
committed
chore: Move crypto_random_object_id to shared package
1 parent b6ee7a7 commit 6e8e51c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/apify_shared/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io
55
import json
66
import re
7+
import secrets
78
from datetime import datetime, timezone
89
from enum import Enum
910
from typing import Any, TypeVar, cast
@@ -115,3 +116,9 @@ def parse(key: str, value: object) -> object:
115116
return {key: parse(key, value) for (key, value) in data.items()}
116117

117118
return data
119+
120+
@ignore_docs
121+
def crypto_random_object_id(length: int = 17) -> str:
122+
"""Generates a random object ID."""
123+
chars = 'abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ0123456789'
124+
return ''.join(secrets.choice(chars) for _ in range(length))

0 commit comments

Comments
 (0)