SDB DB Reference — boto v2.25.0

### Navigation

- index
- modules |
- next |
- previous |
- boto v2.25.0 »

# SDB DB Reference

This module offers an ORM-like layer on top of SimpleDB.

## boto.sdb.db

## boto.sdb.db.blob

class `boto.sdb.db.blob.` `Blob`(value=None, file=None, id=None)

  Blob object

  `file`
  `next`()
  `read`()
  `readline`()
  `size`

## boto.sdb.db.key

class `boto.sdb.db.key.` `Key`(encoded=None, obj=None)
  `app`()
  classmethod `from_path`(*args, **kwds)
  `has_id_or_name`()
  `id`()
  `id_or_name`()
  `kind`()
  `name`()
  `parent`()

## boto.sdb.db.manager

`boto.sdb.db.manager.` `get_manager`(cls)

  Returns the appropriate Manager class for a given Model class. It does this by looking in the boto config for a section like this:

      [DB]
      db_type = SimpleDB
      db_user = <aws access key id>
      db_passwd = <aws secret access key>
      db_name = my_domain
      [DB_TestBasic]
      db_type = SimpleDB
      db_user = <another aws access key id>
      db_passwd = <another aws secret access key>
      db_name = basic_domain
      db_port = 1111

  The values in the DB section are “generic values” that will be used if nothing more specific is found. You can also create a section for a specific Model class that gives the db info for that class. In the example above, TestBasic is a Model subclass.

## boto.sdb.db.manager.sdbmanager

class `boto.sdb.db.manager.sdbmanager.` `SDBConverter`(manager)

  Responsible for converting base Python types to format compatible with underlying database. For SimpleDB, that means everything needs to be converted to a string when stored in SimpleDB and from a string when retrieved.

  To convert a value, pass it to the encode or decode method. The encode method will take a Python native value and convert to DB format. The decode method will take a DB format value and convert it to Python native format. To find the appropriate method to call, the generic encode/decode methods will look for the type-specific method by searching for a method called”encode_<type name>” or “decode_<type name>”.

  `decode`(item_type, value)
  `decode_blob`(value)
  `decode_bool`(value)
  `decode_date`(value)
  `decode_datetime`(value)

    Handles both Dates and DateTime objects

  `decode_float`(value)
  `decode_int`(value)
  `decode_list`(prop, value)
  `decode_long`(value)
  `decode_map`(prop, value)
  `decode_map_element`(item_type, value)

    Decode a single element for a map

  `decode_prop`(prop, value)
  `decode_reference`(value)
  `decode_string`(value)

    Decoding a string is really nothing, just return the value as-is

  `decode_time`(value)

    converts strings in the form of HH:MM:SS.mmmmmm (created by datetime.time.isoformat()) to datetime.time objects.

    Timzone-aware strings (“HH:MM:SS.mmmmmm+HH:MM”) won’t be handled right now and will raise TimeDecodeError.

  `encode`(item_type, value)
  `encode_blob`(value)
  `encode_bool`(value)
  `encode_date`(value)
  `encode_datetime`(value)
  `encode_float`(value)

    See http://tools.ietf.org/html/draft-wood-ldapext-float-00.

  `encode_int`(value)
  `encode_list`(prop, value)
  `encode_long`(value)
  `encode_map`(prop, value)
  `encode_prop`(prop, value)
  `encode_reference`(value)
  `encode_string`(value)

    Convert ASCII, Latin-1 or UTF-8 to pure Unicode

  `encode_time`(value)

class `boto.sdb.db.manager.sdbmanager.` `SDBManager`(cls, db_name, db_user, db_passwd, db_host, db_port, db_table, ddl_dir, enable_ssl, consistent=None)
  `count`(cls, filters, quick=True, sort_by=None, select=None)

    Get the number of results that would be returned in this query

  `decode_value`(prop, value)
  `delete_key_value`(obj, name)
  `delete_object`(obj)
  `domain`
  `encode_value`(prop, value)
  `get_blob_bucket`(bucket_name=None)
  `get_key_value`(obj, name)
  `get_object`(cls, id, a=None)
  `get_object_from_id`(id)
  `get_property`(prop, obj, name)
  `get_raw_item`(obj)
  `get_s3_connection`()
  `load_object`(obj)
  `query`(query)
  `query_gql`(query_string, *args, **kwds)
  `save_object`(obj, expected_value=None)
  `sdb`
  `set_key_value`(obj, name, value)
  `set_property`(prop, obj, name, value)

exception `boto.sdb.db.manager.sdbmanager.` `TimeDecodeError`

## boto.sdb.db.manager.xmlmanager

class `boto.sdb.db.manager.xmlmanager.` `XMLConverter`(manager)

  Responsible for converting base Python types to format compatible with underlying database. For SimpleDB, that means everything needs to be converted to a string when stored in SimpleDB and from a string when retrieved.

  To convert a value, pass it to the encode or decode method. The encode method will take a Python native value and convert to DB format. The decode method will take a DB format value and convert it to Python native format. To find the appropriate method to call, the generic encode/decode methods will look for the type-specific method by searching for a method called “encode_<type name>” or “decode_<type name>”.

  `decode`(item_type, value)
  `decode_bool`(value)
  `decode_datetime`(value)
  `decode_int`(value)
  `decode_long`(value)
  `decode_password`(value)
  `decode_prop`(prop, value)
  `decode_reference`(value)
  `encode`(item_type, value)
  `encode_bool`(value)
  `encode_datetime`(value)
  `encode_int`(value)
  `encode_long`(value)
  `encode_password`(value)
  `encode_prop`(prop, value)
  `encode_reference`(value)
  `get_text_value`(parent_node)

class `boto.sdb.db.manager.xmlmanager.` `XMLManager`(cls, db_name, db_user, db_passwd, db_host, db_port, db_table, ddl_dir, enable_ssl)
  `decode_value`(prop, value)
  `delete_key_value`(obj, name)
  `delete_object`(obj)
  `encode_value`(prop, value)
  `get_doc`()
  `get_key_value`(obj, name)
  `get_list`(prop_node, item_type)
  `get_object`(cls, id)
  `get_object_from_doc`(cls, id, doc)
  `get_property`(prop, obj, name)
  `get_props_from_doc`(cls, id, doc)

    Pull out the properties from this document Returns the class, the properties in a hash, and the id if provided as a tuple :return: (cls, props, id)

  `get_raw_item`(obj)
  `get_s3_connection`()
  `load_object`(obj)
  `marshal_object`(obj, doc=None)
  `new_doc`()
  `query`(cls, filters, limit=None, order_by=None)
  `query_gql`(query_string, *args, **kwds)
  `reset`()
  `save_list`(doc, items, prop_node)
  `save_object`(obj, expected_value=None)

    Marshal the object and do a PUT

  `set_key_value`(obj, name, value)
  `set_property`(prop, obj, name, value)
  `unmarshal_object`(fp, cls=None, id=None)
  `unmarshal_props`(fp, cls=None, id=None)

    Same as unmarshalling an object, except it returns from “get_props_from_doc”

## boto.sdb.db.model

class `boto.sdb.db.model.` `Expando`(id=None, **kw)

class `boto.sdb.db.model.` `Model`(id=None, **kw)
  classmethod `all`(limit=None, next_token=None)
  `delete`()
  `delete_attributes`(attrs)

    Delete just these attributes, not the whole object.

    Parameters: | attrs (list) – Attributes to save, as a list of string names
    Returns: | self
    Return type: | `boto.sdb.db.model.Model`

  classmethod `find`(limit=None, next_token=None, **params)
  classmethod `find_property`(prop_name)
  classmethod `find_subclass`(name)

    Find a subclass with a given name

  classmethod `from_xml`(fp)
  classmethod `get_by_id`(ids=None, parent=None)
  classmethod `get_by_ids`(ids=None, parent=None)
  classmethod `get_by_key_name`(key_names, parent=None)
  classmethod `get_lineage`()
  classmethod `get_or_insert`(key_name, **kw)
  classmethod `get_xmlmanager`()
  `id` = None
  `key`()
  classmethod `kind`()
  `load`()
  classmethod `properties`(hidden=True)
  `put`(expected_value=None)

    Save this object as it is, with an optional expected value

    Parameters: | expected_value (tuple or list) – Optional tuple of Attribute, and Value that must be the same in order to save this object. If this condition is not met, an SDBResponseError will be raised with a Confict status code.
    Returns: | This object
    Return type: | `boto.sdb.db.model.Model`

  `put_attributes`(attrs)

    Save just these few attributes, not the whole object

    Parameters: | attrs (dict) – Attributes to save, key->value dict
    Returns: | self
    Return type: | `boto.sdb.db.model.Model`

  `reload`()
  `save`(expected_value=None)

    Save this object as it is, with an optional expected value

    Parameters: | expected_value (tuple or list) – Optional tuple of Attribute, and Value that must be the same in order to save this object. If this condition is not met, an SDBResponseError will be raised with a Confict status code.
    Returns: | This object
    Return type: | `boto.sdb.db.model.Model`

  `save_attributes`(attrs)

    Save just these few attributes, not the whole object

    Parameters: | attrs (dict) – Attributes to save, key->value dict
    Returns: | self
    Return type: | `boto.sdb.db.model.Model`

  `set_manager`(manager)
  `to_dict`()
  `to_xml`(doc=None)

class `boto.sdb.db.model.` `ModelMeta`(name, bases, dict)

  Metaclass for all Models

## boto.sdb.db.property

`boto.sdb.db.property.` `BlobProperty`

`boto.sdb.db.property.` `BooleanProperty`

`boto.sdb.db.property.` `CalculatedProperty`

`boto.sdb.db.property.` `DateProperty`

`boto.sdb.db.property.` `DateTimeProperty`

  This class handles both the datetime.datetime object And the datetime.date objects. It can return either one, depending on the value stored in the database

`boto.sdb.db.property.` `FloatProperty`

`boto.sdb.db.property.` `IntegerProperty`

`boto.sdb.db.property.` `ListProperty`

`boto.sdb.db.property.` `LongProperty`

`boto.sdb.db.property.` `MapProperty`

`boto.sdb.db.property.` `PasswordProperty`

  Hashed property whose original value can not be retrieved, but still can be compared.

  Works by storing a hash of the original value instead of the original value. Once that’s done all that can be retrieved is the hash.

  The comparison

  > obj.password == ‘foo’

  generates a hash of ‘foo’ and compares it to the stored hash.

  Underlying data type for hashing, storing, and comparing is boto.utils.Password. The default hash function is defined there ( currently sha512 in most cases, md5 where sha512 is not available )

  It’s unlikely you’ll ever need to use a different hash function, but if you do, you can control the behavior in one of two ways:

  > 1. Specifying hashfunc in PasswordProperty constructor

  >    import hashlib

  >    class MyModel(model):

  >      password = PasswordProperty(hashfunc=hashlib.sha224)

  > 2. Subclassing Password and PasswordProperty

  >    class SHA224Password(Password):

  >      hashfunc=hashlib.sha224

  >    class SHA224PasswordProperty(PasswordProperty):

  >      data_type=MyPassword type_name=”MyPassword”

  >    class MyModel(Model):

  >      password = SHA224PasswordProperty()

`boto.sdb.db.property.` `Property`

`boto.sdb.db.property.` `ReferenceProperty`

`boto.sdb.db.property.` `S3KeyProperty`

`boto.sdb.db.property.` `StringProperty`

`boto.sdb.db.property.` `TextProperty`

`boto.sdb.db.property.` `TimeProperty`

`boto.sdb.db.property.` `validate_string`(value)

## boto.sdb.db.query

class `boto.sdb.db.query.` `Query`(model_class, limit=None, next_token=None, manager=None)
  `count`(quick=True)
  `fetch`(limit, offset=0)

    Not currently fully supported, but we can use this to allow them to set a limit in a chainable method

  `filter`(property_operator, value)
  `get_next_token`()
  `get_query`()
  `next`()
  `next_token`
  `order`(key)
  `set_next_token`(token)
  `to_xml`(doc=None)

### Navigation

- index
- modules |
- next |
- previous |
- boto v2.25.0 »