pg.typing.StrKey

Accessible via pg.typing.StrKey.

class StrKey(regex=None)[source]

Bases: pg.typing.NonConstKey

Class that represents a variable string key.

Example:

# Create a key spec that specifies all string keys started with 'foo'.
key = pg.typing.StrKey('foo.*')

assert key.match('foo')
assert key.match('foo1')
assert not key.match('bar')

Methods:

format(**kwargs)

Format this object.

match(key)

Whether this key spec can match against input key.

to_json(**kwargs)

Returns a plain Python value as a representation for this object.

Attributes:

regex

Returns regular expression of this key spec.

format(**kwargs)[source]

Format this object.

match(key)[source]

Whether this key spec can match against input key.

Return type:

bool

property regex[source]

Returns regular expression of this key spec.

to_json(**kwargs)[source]

Returns a plain Python value as a representation for this object.

A plain Python value are basic python types that can be serialized into JSON, e.g: bool, int, float, str, dict (with string keys), list, tuple where the container types should have plain Python values as their values.

Return type:

Dict[str, Any]

Parameters:

**kwargs – Keyword arguments as flags to control JSON conversion.

Returns:

A plain Python value.