def reify_python(self, alias=None): """REST call command line in python. See ``reify`` method. """ def resource_alias(resource_id): """Returns the alias if found """ if isinstance(resource_id, basestring): return alias.get(resource_id, '"%s"' % resource_id) elif isinstance(resource_id, list): alias_names = [] for resource_id_id in resource_id: alias_names.append( alias.get(resource_id_id, '"%s"' % resource_id_id)) return repr(alias_names) resource_type = get_resource_type(self.resource_id) resource_name = resource_alias(self.resource_id) resource_method_suffix = RENAMED_RESOURCES.get( resource_type, resource_type) origin_names = [resource_alias(resource_id) for resource_id in self.origins] arguments = ", ".join(origin_names) if self.suffix: arguments = "%s%s" % (arguments, self.suffix) if self.input_data: arguments = "%s, \\\n%s%s" % ( \ arguments, INDENT, pprint.pformat(self.input_data).replace("\n", "\n%s" % INDENT)) if self.args: arguments = "%s, \\\n%s%s" % (arguments, \ INDENT, \ pprint.pformat(self.args).replace("\n", "\n%s" % INDENT)) out = "%s = api.%s_%s(%s)\napi.ok(%s)\n\n" % ( resource_name, self.action, resource_method_suffix, arguments, resource_name) return out
def reify_python(self, alias=None): """REST call command line in python. See ``reify`` method. """ def resource_alias(resource_id): """Returns the alias if found """ if isinstance(resource_id, basestring): return alias.get(resource_id, '"%s"' % resource_id) elif isinstance(resource_id, list): alias_names = [] for resource_id_id in resource_id: alias_names.append( alias.get(resource_id_id, '"%s"' % resource_id_id)) return repr(alias_names) resource_type = get_resource_type(self.resource_id) resource_name = resource_alias(self.resource_id) resource_method_suffix = RENAMED_RESOURCES.get(resource_type, resource_type) origin_names = [ resource_alias(resource_id) for resource_id in self.origins ] arguments = ", ".join(origin_names) if self.input_data: arguments = "%s, \\\n%s%s" % ( \ arguments, INDENT, pprint.pformat(self.input_data).replace("\n", "\n%s" % INDENT)) if self.args: arguments = "%s, \\\n%s%s" % (arguments, \ INDENT, \ pprint.pformat(self.args).replace("\n", "\n%s" % INDENT)) out = "%s = api.%s_%s(%s)\napi.ok(%s)\n\n" % ( resource_name, self.action, resource_method_suffix, arguments, resource_name) return out
def __init__(self, username=None, api_key=None, dev_mode=False, debug=False, set_locale=False, storage=None, domain=None): """Initializes the BigML API. If left unspecified, `username` and `api_key` will default to the values of the `BIGML_USERNAME` and `BIGML_API_KEY` environment variables respectively. If `dev_mode` is set to `True`, the API will be used in development mode where the size of your datasets are limited but you are not charged any credits. If storage is set to a directory name, the resources obtained in CRU operations will be stored in the given directory. If domain is set, the api will point to the specified domain. Default will be the one in the environment variable `BIGML_DOMAIN` or `bigml.io` if missing. The expected domain argument is a string or a Domain object. See Domain class for details. """ BigMLConnection.__init__(self, username=username, api_key=api_key, dev_mode=dev_mode, debug=debug, set_locale=set_locale, storage=storage, domain=domain) ResourceHandler.__init__(self) SourceHandler.__init__(self) DatasetHandler.__init__(self) ModelHandler.__init__(self) EnsembleHandler.__init__(self) PredictionHandler.__init__(self) ClusterHandler.__init__(self) CentroidHandler.__init__(self) AnomalyHandler.__init__(self) AnomalyScoreHandler.__init__(self) EvaluationHandler.__init__(self) BatchPredictionHandler.__init__(self) BatchCentroidHandler.__init__(self) BatchAnomalyScoreHandler.__init__(self) ProjectHandler.__init__(self) SampleHandler.__init__(self) self.getters = {} for resource_type in RESOURCE_RE: method_name = RENAMED_RESOURCES.get(resource_type, resource_type) self.getters[resource_type] = getattr(self, "get_%s" % method_name) self.creaters = {} for resource_type in RESOURCE_RE: method_name = RENAMED_RESOURCES.get(resource_type, resource_type) self.creaters[resource_type] = getattr(self, "create_%s" % method_name) self.updaters = {} for resource_type in RESOURCE_RE: method_name = RENAMED_RESOURCES.get(resource_type, resource_type) self.updaters[resource_type] = getattr(self, "update_%s" % method_name) self.deleters = {} for resource_type in RESOURCE_RE: method_name = RENAMED_RESOURCES.get(resource_type, resource_type) self.deleters[resource_type] = getattr(self, "delete_%s" % method_name)