Utilities¶
Floating point numbers¶
Module for handling floating point numbers in ATProtocol records.
ATProtocol doesn't support floating point numbers directly, so this module provides functions to convert floats to specially formatted strings and back again.
decode_floats_in_event(event)
¶
Recursively decode all specially marked strings in an event back to floating point numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict[str, Any]
|
The event dictionary to process. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A new dictionary with all encoded strings converted back to floating point numbers. |
Source code in nebra/floats.py
encode_floats_in_event(event)
¶
Recursively encode all floating point numbers in an event as specially marked strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict[str, Any]
|
The event dictionary to process. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A new dictionary with all floating point numbers encoded as strings. |
Source code in nebra/floats.py
Time¶
These helpers can create fully AT Protocol-compliant timestamps.
atproto_timestamp_to_datetime(timestamp)
¶
Convert an ATProto timestamp string to a Python datetime object.
ATProto timestamps are a subset of ISO 8601/RFC 3339, with the format "YYYY-MM-DDTHH:MM:SS.sssZ". This function parses the timestamp and returns a timezone-aware datetime object in UTC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
str
|
An ATProto timestamp string (e.g., "1985-04-12T23:20:50.123Z"). |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
A timezone-aware datetime object in UTC. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp is not in the expected format or violates ATProto rules. |
See Also
https://atproto.com/specs/lexicon#datetime : ATProtocol datetime specification
Source code in nebra/time.py
get_atproto_utc_time()
¶
Get a maximally ATProto-compatible UTC datetime string.
This function returns a datetime string in the format specified by the ATProtocol lexicon, which is "YYYY-MM-DDTHH:MM:SS.sssZ".
Returns:
| Type | Description |
|---|---|
str
|
A datetime string in ATProtocol-compatible format. |
See Also
https://atproto.com/specs/lexicon#datetime : ATProtocol datetime specification