Python driver API reference
Connection
TypeDB
cloud_driver
static cloud_driver(addresses: Mapping[str, str] | Iterable[str] | str, credentials: Credentials, driver_options: DriverOptions) -> Driver
Creates a connection to TypeDB Cloud, authenticating with the provided credentials.
Name | Description | Type | Default Value |
---|---|---|---|
|
TypeDB server addresses as a single string, a list of strings, or as an address translation mapping. |
|
|
|
The credentials to connect with. |
|
|
|
The connection settings to connect with. |
|
Driver
core_driver
static core_driver(address: str, credentials: Credentials, driver_options: DriverOptions) -> Driver
Creates a connection to TypeDB.
Name | Description | Type | Default Value |
---|---|---|---|
|
Address of the TypeDB server. |
|
|
|
The credentials to connect with. |
|
|
|
The connection settings to connect with. |
|
Driver
Driver
Name | Type | Description |
---|---|---|
|
|
The |
|
|
The |
close
close() -> None
Closes the driver. Before instantiating a new driver, the driver that’s currently open should first be closed.
None
driver.close()
is_open
is_open() -> bool
Checks whether this connection is presently open.
bool
driver.is_open()
transaction
transaction(database_name: str, transaction_type: TransactionType) -> Transaction
Opens a communication tunnel (transaction) to the given database on the running TypeDB server.
Name | Description | Type | Default Value |
---|---|---|---|
|
The name of the database with which the transaction connects |
|
|
|
The type of transaction to be created (READ, WRITE, or SCHEMA) |
|
Transaction
driver.transaction(database, transaction_type)
Credentials
User credentials and TLS encryption settings for connecting to TypeDB Server.
credentials = Credentials(username, password)
DriverOptions
User credentials and TLS encryption settings for connecting to TypeDB Server. Arguments: 1) is_tls_enabled: Specify whether the connection to TypeDB Cloud must be done over TLS. 2) tls_root_ca_path: Path to the CA certificate to use for authenticating server certificates.
driver_options = DriverOptions(tls_enabled=True, tls_root_ca_path="path/to/ca-certificate.pem")
DatabaseManager
Provides access to all database management methods.
all
all() -> List[Database]
Retrieves all databases present on the TypeDB server
List[Database]
driver.databases.all()
contains
contains(name: str) -> bool
Checks if a database with the given name exists
Name | Description | Type | Default Value |
---|---|---|---|
|
The database name to be checked |
|
bool
driver.databases.contains(name)
Database
Name | Type | Description |
---|---|---|
|
|
The database name as a string. |
UserManager
Provides access to all user management methods.
all
all() -> List[User]
Retrieves all users which exist on the TypeDB server.
List[User]
driver.users.all()
contains
contains(username: str) -> bool
Checks if a user with the given name exists.
Name | Description | Type | Default Value |
---|---|---|---|
|
The user name to be checked |
|
bool
driver.users.contains(username)
create
create(username: str, password: str) -> None
Create a user with the given name and password.
Name | Description | Type | Default Value |
---|---|---|---|
|
The name of the user to be created |
|
|
|
The password of the user to be created |
|
None
driver.users.create(username, password)
User
TypeDB user information
Name | Type | Description |
---|---|---|
|
|
Returns the name of this user. |
Transaction
Transaction
Name | Type | Description |
---|---|---|
|
|
The transaction’s type (READ, WRITE, or SCHEMA) |
commit
commit() -> None
Commits the changes made via this transaction to the TypeDB database. Whether or not the transaction is commited successfully, it gets closed after the commit call.
None
transaction.commit()
is_open
is_open() -> bool
Checks whether this transaction is open.
bool
transaction.is_open()
on_close
on_close(function: callable) -> None
Registers a callback function which will be executed when this transaction is closed.
Name | Description | Type | Default Value |
---|---|---|---|
|
The callback function. |
|
None
transaction.on_close(function)
Answer
QueryAnswer
General answer on a query returned by a server. Can be a simple Ok response or a collection of concepts.
Name | Type | Description |
---|---|---|
|
|
Retrieves the executed query’s type of this |
as_concept_documents
as_concept_documents() -> ConceptDocumentIterator
Casts the query answer to ConceptDocumentIterator
.
ConceptDocumentIterator
query_answer.as_concept_documents()
as_concept_rows
as_concept_rows() -> ConceptRowIterator
Casts the query answer to ConceptRowIterator
.
ConceptRowIterator
query_answer.as_concept_rows()
as_ok
as_ok() -> OkQueryAnswer
Casts the query answer to OkQueryAnswer
.
OkQueryAnswer
query_answer.as_ok()
is_concept_documents
is_concept_documents() -> bool
Checks if the query answer is a ConceptDocumentIterator
.
bool
query_answer.is_concept_documents()
OkQueryAnswer
Supertypes:
-
QueryAnswer
Represents a simple Ok message as a server answer. Doesn’t contain concepts.
ConceptRowIterator
Supertypes:
-
QueryAnswer
Represents an iterator over ConceptRow
s returned as a server answer.
ConceptRow
Contains a row of concepts with a header.
Name | Type | Description |
---|---|---|
|
|
Retrieves the executed query’s type of this |
column_names
column_names() -> Iterator[str]
Produces an iterator over all column names (variables) in the header of this ConceptRow
. Shared between all the rows in a QueryAnswer.
Iterator[str]
concept_row.column_names()
concepts
concepts() -> Iterator[Concept]
Produces an iterator over all concepts in this ConceptRow, skipping empty results.
Iterator[Concept]
concept_row.concepts()
get
get(column_name: str) -> Concept | None
Retrieves a concept for a given column name (variable). Returns None
if the variable has an empty answer. Throws an exception if the variable is not present.
Name | Description | Type | Default Value |
---|---|---|---|
|
The string representation of a variable (column name from |
|
Concept | None
concept_row.get(column_name)
get_index
get_index(column_index: int) -> Concept | None
Retrieves a concept for a given index of the header (‘’column_names’’). Returns None
if the index points to an empty answer. Throws an exception if the index is not in the row’s range.
Name | Description | Type | Default Value |
---|---|---|---|
|
The column index |
|
Concept | None
concept_row.get_index(column_index)
ConceptDocumentIterator
Supertypes:
-
QueryAnswer
Represents an iterator over ConceptRow
s returned as a server answer.
QueryType
Used to specify the type of the executed query.
concept_row.query_type
Name | Value |
---|---|
|
|
|
|
|
|
Concept
Concept
as_attribute
as_attribute() -> Attribute
Casts the concept to Attribute
.
Attribute
concept.as_attribute()
as_attribute_type
as_attribute_type() -> AttributeType
Casts the concept to AttributeType
.
AttributeType
concept.as_attribute_type()
as_entity
as_entity() -> Entity
Casts the concept to Entity
.
Entity
concept.as_entity()
as_entity_type
as_entity_type() -> EntityType
Casts the concept to EntityType
.
EntityType
concept.as_entity_type()
as_instance
as_instance() -> Instance
Casts the concept to Instance
.
Instance
concept.as_instance()
as_relation
as_relation() -> Relation
Casts the concept to Relation
.
Relation
concept.as_relation()
as_relation_type
as_relation_type() -> RelationType
Casts the concept to RelationType
.
RelationType
concept.as_relation_type()
as_role_type
as_role_type() -> RoleType
Casts the concept to RoleType
.
RoleType
concept.as_role_type()
as_value
as_value() -> Value
Casts the concept to Value
.
Value
concept.as_value()
get_label
get_label() -> str
Get the label of the concept. If this is an Instance
, return the label of the type of this instance (“unknown” if type fetching is disabled). If this is a Value
, return the label of the value type of the value. If this is a Type
, return the label of the type.
str
concept.get_label()
is_attribute
is_attribute() -> bool
Checks if the concept is an Attribute
.
bool
concept.is_attribute()
is_attribute_type
is_attribute_type() -> bool
Checks if the concept is an AttributeType
.
bool
concept.is_attribute_type()
is_boolean
is_boolean() -> bool
Returns True
if the value which this Concept
holds is of type boolean
or if this Concept
is an AttributeType
of type boolean
. Otherwise, returns False
.
bool
concept.is_boolean()
is_date
is_date() -> bool
Returns True
if the value which this Concept
holds is of type date
or if this Concept
is an AttributeType
of type date
. Otherwise, returns False
.
bool
concept.is_date()
is_datetime
is_datetime() -> bool
Returns True
if the value which this Concept
holds is of type datetime
or if this Concept
is an AttributeType
of type datetime
. Otherwise, returns False
.
bool
concept.is_datetime()
is_datetime_tz
is_datetime_tz() -> bool
Returns True
if the value which this Concept
holds is of type datetime-tz
or if this Concept
is an AttributeType
of type datetime-tz
. Otherwise, returns False
.
bool
concept.is_datetime_tz()
is_decimal
is_decimal() -> bool
Returns True
if the value which this Concept
holds is of type decimal
or if this Concept
is an AttributeType
of type decimal
. Otherwise, returns False
.
bool
concept.is_decimal()
is_double
is_double() -> bool
Returns True
if the value which this Concept
holds is of type double
or if this Concept
is an AttributeType
of type double
. Otherwise, returns False
.
bool
concept.is_double()
is_duration
is_duration() -> bool
Returns True
if the value which this Concept
holds is of type duration
or if this Concept
is an AttributeType
of type duration
. Otherwise, returns False
.
bool
concept.is_duration()
is_entity
is_entity() -> bool
Checks if the concept is an Entity
.
bool
concept.is_entity()
is_entity_type
is_entity_type() -> bool
Checks if the concept is an EntityType
.
bool
concept.is_entity_type()
is_instance
is_instance() -> bool
Checks if the concept is a Instance
.
bool
concept.is_instance()
is_integer
is_integer() -> bool
Returns True
if the value which this Concept
holds is of type integer
or if this Concept
is an AttributeType
of type integer
. Otherwise, returns False
.
bool
concept.is_integer()
is_relation
is_relation() -> bool
Checks if the concept is a Relation
.
bool
concept.is_relation()
is_relation_type
is_relation_type() -> bool
Checks if the concept is a RelationType
.
bool
concept.is_relation_type()
is_role_type
is_role_type() -> bool
Checks if the concept is a RoleType
.
bool
concept.is_role_type()
is_string
is_string() -> bool
Returns True
if the value which this Concept
holds is of type string
or if this Concept
is an AttributeType
of type string
. Otherwise, returns False
.
bool
concept.is_string()
is_struct
is_struct() -> bool
Returns True
if the value which this Concept
holds is of type struct
or if this Concept
is an AttributeType
of type struct
. Otherwise, returns False
.
bool
concept.is_struct()
is_type
is_type() -> bool
Checks if the concept is a Type
.
bool
concept.is_type()
is_value
is_value() -> bool
Checks if the concept is a Value
.
bool
concept.is_value()
try_get_boolean
try_get_boolean() -> bool | None
Returns a boolean
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
bool | None
value.try_get_boolean()
try_get_date
try_get_date() -> date | None
Returns a timezone naive date
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
date | None
value.try_get_date()
try_get_datetime
try_get_datetime() -> Datetime | None
Returns a timezone naive datetime
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
Datetime | None
value.try_get_datetime()
try_get_datetime_tz
try_get_datetime_tz() -> Datetime | None
Returns a timezone naive datetime_tz
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
Datetime | None
value.try_get_datetime_tz()
try_get_decimal
try_get_decimal() -> Decimal | None
Returns a decimal
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
Decimal | None
value.try_get_decimal()
try_get_double
try_get_double() -> float | None
Returns a double
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
float | None
value.try_get_double()
try_get_duration
try_get_duration() -> Duration | None
Returns a timezone naive duration
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
Duration | None
value.try_get_duration()
try_get_iid
try_get_iid() -> str | None
Retrieves the unique id of the Concept
. Returns None
if absent.
str | None
concept.try_get_iid()
try_get_integer
try_get_integer() -> int | None
Returns a integer
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
int | None
value.try_get_integer()
try_get_label
try_get_label() -> str | None
Get the label of the concept. If this is an Instance
, return the label of the type of this instance (None
if type fetching is disabled). Returns None
if type fetching is disabled. If this is a Value
, return the label of the value type of the value. If this is a Type
, return the label of the type.
str | None
concept.try_get_label()
try_get_string
try_get_string() -> str | None
Returns a string
value of this Concept
. If it’s not a Value
or it has another type, raises an exception.
str | None
value.try_get_string()
try_get_struct
try_get_struct() -> STRUCT | None
Returns a struct
value of this Concept
represented as a map from field names to values. If it’s not a Value
or it has another type, raises an exception.
STRUCT | None
value.try_get_struct()
Schema
EntityType
Supertypes:
-
Type
Entity types represent the classification of independent objects in the data model of the business domain.
RelationType
Supertypes:
-
Type
Relation types (or subtypes of the relation root type) represent relationships between types. Relation types have roles.
Other types can play roles in relations if it’s mentioned in their definition.
A relation type must specify at least one role.
RoleType
Supertypes:
-
Type
Roles are special internal types used by relations. We can not create an instance of a role in a database. But we can set an instance of another type (role player) to play a role in a particular instance of a relation type.
Roles allow a schema to enforce logical constraints on types of role players.
AttributeType
Supertypes:
-
Type
Attribute types represent properties that other types can own.
Attribute types have a value type. This value type is fixed and unique for every given instance of the attribute type.
Other types can own an attribute type. That means that instances of these other types can own an instance of this attribute type. This usually means that an object in our domain has a property with the matching value.
Multiple types can own the same attribute type, and different instances of the same type or different types can share ownership of the same attribute instance.
Data
Instance
Supertypes:
-
Concept
as_instance
as_instance() -> Instance
Casts the concept to Instance
.
Instance
instance.as_instance()
Entity
Supertypes:
-
Instance
Instance of data of an entity type, representing a standalone object that exists in the data model independently.
Entity does not have a value. It is usually addressed by its ownership over attribute instances and/or roles played in relation instances.
as_entity
as_entity() -> Entity
Casts the concept to Entity
.
Entity
entity.as_entity()
get_iid
get_iid() -> str
Retrieves the unique id of the Entity
.
str
entity.get_iid()
Relation
Supertypes:
-
Instance
Relation is an instance of a relation type and can be uniquely addressed by a combination of its type, owned attributes and role players.
as_relation
as_relation() -> Relation
Casts the concept to Relation
.
Relation
relation.as_relation()
get_iid
get_iid() -> str
Retrieves the unique id of the Relation
.
str
relation.get_iid()
Attribute
Supertypes:
-
Instance
Attribute is an instance of the attribute type and has a value. This value is fixed and unique for every given instance of the attribute type.
Attributes can be uniquely addressed by their type and value.
as_attribute
as_attribute() -> Attribute
Casts the concept to Attribute
.
Attribute
attribute.as_attribute()
get_boolean
get_boolean() -> bool
Returns a boolean
value of the value concept that this attribute holds. If the value has another type, raises an exception.
bool
attribute.get_boolean()
get_date
get_date() -> date
Returns a timezone naive date
value of the value concept that this attribute holds. If the value has another type, raises an exception.
date
attribute.get_date()
get_datetime
get_datetime() -> Datetime
Returns a timezone naive datetime
value of the value concept that this attribute holds. If the value has another type, raises an exception.
Datetime
attribute.get_datetime()
get_datetime_tz
get_datetime_tz() -> Datetime
Returns a timezone naive datetime_tz
value of the value concept that this attribute holds. If the value has another type, raises an exception.
Datetime
attribute.get_datetime_tz()
get_decimal
get_decimal() -> Decimal
Returns a decimal
value of the value concept that this attribute holds. If the value has another type, raises an exception.
Decimal
attribute.get_decimal()
get_double
get_double() -> float
Returns a double
value of the value concept that this attribute holds. If the value has another type, raises an exception.
float
attribute.get_double()
get_duration
get_duration() -> Duration
Returns a timezone naive duration
value of the value concept that this attribute holds. If the value has another type, raises an exception.
Duration
attribute.get_duration()
get_integer
get_integer() -> int
Returns a integer
value of the value concept that this attribute holds. If the value has another type, raises an exception.
int
attribute.get_integer()
get_string
get_string() -> str
Returns a string
value of the value concept that this attribute holds. If the value has another type, raises an exception.
str
attribute.get_string()
get_struct
get_struct() -> Concept.STRUCT
Returns a struct
value of the value concept that this attribute holds represented as a map from field names to values. If the value has another type, raises an exception.
Concept.STRUCT
attribute.get_struct()
get_type
get_type() -> AttributeType
Retrieves the type which this Attribute
belongs to.
AttributeType
attribute.get_type()
get_value
get_value() -> Concept.VALUE
Retrieves the value which the Attribute
instance holds.
Concept.VALUE
attribute.get_value()
Value
Supertypes:
-
Concept
as_value
as_value() -> Value
Casts the concept to Value
.
Value
value.as_value()
get
get() -> bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]
Retrieves the value which this value concept holds.
bool | int | float | Decimal | str | date | Datetime | Duration | Dict[str, Value | None]
value.get()
get_boolean
get_boolean() -> bool
Returns a boolean
value of this value concept. If the value has another type, raises an exception.
bool
value.get_boolean()
get_date
get_date() -> date
Returns a timezone naive date
value of this value concept. If the value has another type, raises an exception.
date
value.get_date()
get_datetime
get_datetime() -> Datetime
Returns a timezone naive datetime
value of this value concept. If the value has another type, raises an exception.
Datetime
value.get_datetime()
get_datetime_tz
get_datetime_tz() -> Datetime
Returns a timezone naive datetime_tz
value of this value concept. If the value has another type, raises an exception.
Datetime
value.get_datetime_tz()
get_decimal
get_decimal() -> Decimal
Returns a decimal
value of this value concept. If the value has another type, raises an exception.
Decimal
value.get_decimal()
get_double
get_double() -> float
Returns a double
value of this value concept. If the value has another type, raises an exception.
float
value.get_double()
get_duration
get_duration() -> Duration
Returns a timezone naive duration
value of this value concept. If the value has another type, raises an exception.
Duration
value.get_duration()
get_integer
get_integer() -> int
Returns a integer
value of this value concept. If the value has another type, raises an exception.
int
value.get_integer()
get_string
get_string() -> str
Returns a string
value of this value concept. If the value has another type, raises an exception.
str
value.get_string()
get_struct
get_struct() -> Dict[str, Value | None]
Returns a struct
value of this value concept represented as a map from field names to values. If the value has another type, raises an exception.
Dict[str, Value | None]
value.get_struct()
Value
Datetime
An extension class for datetime.datetime
class to store additional information about nanoseconds. It is split to a timestamp (time zoned or not) based on the number of full seconds and a nanoseconds part.
Name | Type | Description |
---|---|---|
|
|
Return the date part. |
|
|
Return the standard library’s datetime, containing data up to microseconds. |
|
|
Return the datetime’s day (1-31). |
|
|
Return the datetime’s hour (0-23). |
|
|
Return the rounded number of microseconds. |
|
|
Return the datetime’s minute (0-59). |
|
|
Return the datetime’s month (1-12). |
|
|
Return the nanoseconds part. |
|
|
Return the timezone offset (local minus UTC) in seconds. None if an IANA name is used for the initialisation instead. |
|
|
Return the datetime’s second (0-59). |
|
|
Return the total number of seconds including the nanoseconds part as a float. ValueError – If timestamp is before the start of the epoch. |
|
|
Return the timezone IANA name. None if fixed offset is used for the initialisation instead. |
|
|
Return timezone info. |
|
|
Return the day of the week as an integer, where Monday == 0 … Sunday == 6. |
|
|
Return the datetime’s year (1-9999). |
fromstring
classmethod fromstring(datetime_str: str, tz_name: str | None = None, offset_seconds: int | None = None, datetime_fmt: str = '%Y-%m-%dT%H:%M:%S') -> Datetime
Parses a Datetime object from a string with an optional nanoseconds part with a specified tz_name
or offset_seconds
. The timestamp is adjusted to the given timezone similarly to datetime.fromtimestamp
. To save timestamp and tz without automatic adjustment, see Datetime.utcfromstring
.
Name | Description | Type | Default Value |
---|---|---|---|
|
The timezone-aware datetime string to parse. Should either be “{datetime_fmt}” or “{datetime_fmt}.{nanos}”. All digits of {nanos} after the 9th one are truncated! |
|
|
|
A timezone name. Accepts any format suitable for |
|
|
|
Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00). |
|
|
|
The format of the datetime string without the fractional (.%f) part. Default is “%Y-%m-%dT%H:%M:%S”. |
|
|
Datetime
Datetime.fromstring("2024-09-21T18:34:22", tz_name="America/New_York")
Datetime.fromstring("2024-09-21T18:34:22.009257123", tz_name="Europe/London")
Datetime.fromstring("2024-09-21", tz_name="Asia/Calcutta", datetime_fmt="%Y-%m-%d")
Datetime.fromstring("21/09/24 18:34", tz_name="Africa/Cairo", datetime_fmt="%d/%m/%y %H:%M")
fromtimestamp
classmethod fromtimestamp(timestamp_seconds: int, subsec_nanos: int, tz_name: str | None = None, offset_seconds: int | None = None)
Creates a new Datetime
based on a timestamp with a specified tz_name
or offset_seconds
. The timestamp is adjusted to the given timezone similarly to datetime.fromtimestamp
. To save timestamp and tz without automatic adjustment, see Datetime.utcfromtimestamp
.
Name | Description | Type | Default Value |
---|---|---|---|
|
Amount of full seconds since the epoch in the specified timezone ( |
|
|
|
A number of nanoseconds since the last seconds boundary. Should be between 0 and 999,999,999. |
|
|
|
A timezone name. Accepts any format suitable for |
|
|
|
Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00). |
|
|
``
offset_seconds_fromstring
classmethod offset_seconds_fromstring(offset: str) -> int
Converts a timezone offset in the format +HHMM or -HHMM to seconds.
Name | Description | Type | Default Value |
---|---|---|---|
|
A string representing the timezone offset in the format +HHMM or -HHMM. |
|
int
Datetime.fromstring("2024-09-21T18:34:22.009257123", offset_seconds=Datetime.offset_seconds_fromstring("+0100"))
utcfromstring
classmethod utcfromstring(datetime_str: str, tz_name: str | None = None, offset_seconds: int | None = None, datetime_fmt: str = '%Y-%m-%dT%H:%M:%S') -> Datetime
Parses a Datetime object from a string with an optional nanoseconds part based on a timestamp in the given timezone (tz_name
) or UTC by default. If tz_name
is passed, the timestamp is not adjusted, saving the data as is. For automatic timestamp adjustment, see Datetime.fromstring
.
Name | Description | Type | Default Value |
---|---|---|---|
|
The timezone-aware datetime string to parse. Should either be “{datetime_fmt}” or “{datetime_fmt}.{nanos}”. All digits of {nanos} after the 9th one are truncated! |
|
|
|
A timezone name. Accepts any format suitable for |
|
|
|
Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00). |
|
|
|
The format of the datetime string without the fractional (.%f) part. Default is “%Y-%m-%dT%H:%M:%S”. |
|
|
Datetime
Datetime.utcfromstring("2024-09-21T18:34:22")
Datetime.utcfromstring("2024-09-21T18:34:22.009257123")
Datetime.utcfromstring("2024-09-21T18:34:22.009257123", tz_name="Europe/London")
Datetime.utcfromstring("2024-09-21", datetime_fmt="%Y-%m-%d")
Datetime.utcfromstring("21/09/24 18:34", tz_name="Europe/London", datetime_fmt="%d/%m/%y %H:%M")
utcfromtimestamp
classmethod utcfromtimestamp(timestamp_seconds: int, subsec_nanos: int, tz_name: str | None = None, offset_seconds: int | None = None)
Creates a new Datetime
based on a timestamp in the given timezone (tz_name
) or UTC by default. If tz_name
is passed, the timestamp is not adjusted, saving the data as is. For automatic timestamp adjustment, see Datetime.fromtimestamp
.
Name | Description | Type | Default Value |
---|---|---|---|
|
Amount of full seconds since the epoch in UTC. |
|
|
|
A number of nanoseconds since the last seconds boundary. Should be between 0 and 999,999,999. |
|
|
|
A timezone name. Accepts any format suitable for |
|
|
|
Offset in seconds from UTC (e.g., 3600 for +01:00, -18000 for -05:00). |
|
|
``
Duration
A relative duration, which contains months, days, and nanoseconds. Can be used for calendar-relative durations (eg 7 days forward), or for absolute durations using the nanosecond component. Not convertible to datetime.timedelta due to the lack of months and nanos alternatives.
Name | Type | Description |
---|---|---|
|
|
The days part of the duration |
|
|
The months part of the duration |
|
|
The nanoseconds part of the duration |
fromstring
classmethod fromstring(duration_str: str) -> Duration
Parses a Duration object from a string in ISO 8601 format.
Name | Description | Type | Default Value |
---|---|---|---|
|
A string representation of the duration. Expected format: PnYnMnDTnHnMnS / PnW |
|
Duration
Duration.fromstring("P1Y10M7DT15H44M5.00394892S")
Duration.fromstring("P55W")