API Reference

Bindings

class api_object_schema.binding.ObjectAPIBinding

This class is responsible for describing how an API object field translates into a Pythonic object field - how it is fetched from the API representation and how it is rendered back to the API.

add_from_api_translator(func)

Appends a translator function to the chain of translators needed to convert a Pythonic value to an API value

add_to_api_translator(func)

Appends a translator function to the chain of translators needed to convert a Pythonic value to an API value

from_api(func)

Appends a translator function to the chain of translators needed to convert a Pythonic value to an API value

get_api_value_from_object(system, objtype, obj)

Retrieves the API representation of the field from a whole Pythonic object containing it.

By default this is implemented in terms of get_api_value_from_value()

get_api_value_from_value(system, objtype, obj, value)

Retrieves the API value from a Pythonic value

Parameters:
  • system – the system to which this object belongs
  • objtype – the type of the Pythonic object
  • obj – the object itself. May be None.
  • value – the Pythonic value for the field
get_object_value(system, objtype, obj)

Controls how a Pythonic value is fetched from a Pythonic object

get_value_from_api_object(system, objtype, obj, api_obj)

This method is used when fetching a field value from an entire API representation of the object itself

By default, it uses get_value_from_api_value() to carry out its work.

Besides api_obj, all parameters retain their meanings from get_value_from_api_value().

Parameters:api_obj – the raw API representation of the object
get_value_from_api_value(system, objtype, obj, api_value)

This method parses an API value to its Pythonic representation which eventually belongs to the Python object in question.

Parameters:
  • system – the system to which the object belongs
  • objtype – the class of the Pythonic object in question
  • obj – the object to which we are computing the field. this might be None, if the object hasn’t been constructed yet
  • api_value – the raw API value for this field
set_api_object_api_value(system, objtype, obj, api_obj, api_value)

Controls how a raw API object (or JSON dict) gets assigned a field from an API value

set_api_object_value(system, objtype, obj, api_obj, value)

Controls how a raw API object (or JSON dict) gets assigned a field from a Pythonic value

set_field(field)

Assigns this binding to a specific field

set_object_value(system, objtype, obj, value)

Controls how a Pythonic value is set for a Pythonic object

set_object_value_from_api_value(system, objtype, obj, api_value)

Controls how an API value is set for a Pythonic object

to_api(func)

Appends a translator function to the chain of translators needed to convert a Pythonic value to an API value

Field

class api_object_schema.field.Field(name, api_name=None, type=<type 'str'>, mutable=False, creation_parameter=False, is_unique=False, default=<NOTHING>, is_identity=False, is_filterable=False, is_sortable=False, binding=None, optional=False, sorting_key=None, is_visible=True)

This class represents a single field exposed by a schema

Fields

class api_object_schema.fields.Fields(field_factory=<class 'api_object_schema.field.Field'>, forbid_api_name_overrides=False, forbid_name_overrides=False)
get_all_field_names_or_fabricate(api_object_json)

Given an example of an object from the system’s API, returns the formal set of field names supported by this object type (after transformation to logical names)

TypeInfo

class api_object_schema.type_info.TypeInfo(type, api_type=None, min_length=None, max_length=None, charset=None, max=None, min=None, translator=<api_object_schema.value_translator.IdentityTranslator object>)
is_valid_value(value)

Checks if a given value is valid given the type constraints

is_valid_value_explain(value)
Returns:A tuple of (is_valid, reason)

Translators

class api_object_schema.value_translator.ValueTranslator

This is an abstract base for translator objects.

Translator objects are used to convert values to and from the system’s API layer

from_api(value)

Translates a value from the system API to its Pythonic counterpart

to_api(value)

Translates a value from Python to its API/json representation

Returns:must be JSON encodable
class api_object_schema.value_translator.FunctionTranslator(to_api=None, from_api=None)

Implements value translation with the use of functions

class api_object_schema.value_translator.IdentityTranslator