Skip to content

Commit

Permalink
Add Python package (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee authored Mar 29, 2023
1 parent 32107eb commit 54400a9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[lib]
name = "uuid_utils"
name = "_uuid_utils"
crate-type = ["cdylib"]

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const RFC_4122: &str = "specified in RFC 4122";
pub const RESERVED_MICROSOFT: &str = "reserved for Microsoft compatibility";
pub const RESERVED_FUTURE: &str = "reserved for future definition";

#[pyclass(subclass)]
#[pyclass(subclass, module="uuid_utils")]
#[derive(Clone, Debug)]
struct UUID {
uuid: Uuid,
Expand Down Expand Up @@ -324,7 +324,7 @@ fn uuid8(bytes: &PyBytes) -> PyResult<UUID> {
}

#[pymodule]
fn uuid_utils(_py: Python, m: &PyModule) -> PyResult<()> {
fn _uuid_utils(_py: Python, m: &PyModule) -> PyResult<()> {
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
m.add_class::<UUID>()?;
m.add_function(wrap_pyfunction!(uuid1, m)?)?;
Expand Down
37 changes: 37 additions & 0 deletions uuid_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from _uuid_utils import (
NAMESPACE_DNS,
NAMESPACE_OID,
NAMESPACE_URL,
NAMESPACE_X500,
RESERVED_FUTURE,
RESERVED_MICROSOFT,
RESERVED_NCS,
RFC_4122,
UUID,
__version__,
uuid1,
uuid4,
uuid5,
uuid6,
uuid7,
uuid8,
)

__all__ = [
"NAMESPACE_DNS",
"NAMESPACE_OID",
"NAMESPACE_URL",
"NAMESPACE_X500",
"RESERVED_FUTURE",
"RESERVED_MICROSOFT",
"RESERVED_NCS",
"RFC_4122",
"UUID",
"__version__",
"uuid1",
"uuid4",
"uuid5",
"uuid6",
"uuid7",
"uuid8",
]
51 changes: 51 additions & 0 deletions uuid_utils.pyi → uuid_utils/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,57 @@ class SafeUUID(Enum):
unknown: None

class UUID:
"""Instances of the UUID class represent UUIDs as specified in RFC 4122.
UUID objects are immutable, hashable, and usable as dictionary keys.
Converting a UUID to a string with str() yields something in the form
'12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
five possible forms: a similar string of hexadecimal digits, or a tuple
of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
48-bit values respectively) as an argument named 'fields', or a string
of 16 bytes (with all the integer fields in big-endian order) as an
argument named 'bytes', or a string of 16 bytes (with the first three
fields in little-endian order) as an argument named 'bytes_le', or a
single 128-bit integer as an argument named 'int'.
UUIDs have these read-only attributes:
bytes the UUID as a 16-byte string (containing the six
integer fields in big-endian byte order)
bytes_le the UUID as a 16-byte string (with time_low, time_mid,
and time_hi_version in little-endian byte order)
fields a tuple of the six integer fields of the UUID,
which are also available as six individual attributes
and two derived attributes:
time_low the first 32 bits of the UUID
time_mid the next 16 bits of the UUID
time_hi_version the next 16 bits of the UUID
clock_seq_hi_variant the next 8 bits of the UUID
clock_seq_low the next 8 bits of the UUID
node the last 48 bits of the UUID
time the 60-bit timestamp
clock_seq the 14-bit sequence number
hex the UUID as a 32-character hexadecimal string
int the UUID as a 128-bit integer
urn the UUID as a URN as specified in RFC 4122
variant the UUID variant (one of the constants RESERVED_NCS,
RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
version the UUID version number (1 through 5, meaningful only
when the variant is RFC_4122)
is_safe An enum indicating whether the UUID has been generated in
a way that is safe for multiprocessing applications, via
uuid_generate_time_safe(3).
"""

def __init__(
self,
hex: str | None = None,
Expand Down

0 comments on commit 54400a9

Please sign in to comment.