API

network

class more_ds.network.URL

Helper class for conveniently constructing URLs.

To that end the / operator has been overloaded to append path elements. Similarly the // operator has been overloaded to easily add a query string to the URL.

Being a subclass of str, instances of URL can be used anywhere a str is expected.

IMPORTANT No form of verification is performed. Meaning for instance that any string, not only those that actually make up an URL, can be use to initialize an URL instance. And one can add multiple query strings to an URL instance leading to an improperly formatted URL.

Example:

>>> from more_ds.network import URL
>>> base_url = URL("http://example.org/")
>>> api_url = base_url / "api"
>>> url = api_url / "ip" / "address" // dict(version=4)
>>> print(url)
http://example.org/api/ip/address?version=4
__truediv__(path: object)more_ds.network.url.URL

Append path element to the URL object.

It prevents accidental inclusion of too many slashes between the appended path elements should the URL end in a slash and/or the path element start with a slash.

Parameters

path – path element to append

Returns

A new URL object with the path element appended.

__floordiv__(query: Mapping)more_ds.network.url.URL

Append a query string to the URL.

Parameters

query – Mapping of values that should be converted to a query string.

Returns

a new URL object with the query appended as a query string.

time

class more_ds.time.Timer

Simple context manager for timing blocks of code.

With Timer you can create a runtime context in which a block of code code will be timed. When runtime context is exited, the Timer instance responsible for the runtime context can be queried for the duration or elapsed time.

Examples:

from time import sleep

from more_ds.time import Timer
with Timer() as t:
    # sleep for half a second
    sleep(.5)

print(t.elapsed)  # -> 0:00:00.501864
start: int

Start of time measurement expressed as time in nanoseconds.

duration: int

Duration of the time measurement expressed as elapsed nanoseconde.

property elapsed: datetime.timedelta

Return the time elapsed in Timer’s context.

Returns

Time elapsed in Timer’s context as a timedelta object.