### Navigation

- index
- modules |
- next |
- previous |
- pycassa 1.11.1 documentation »
- API Documentation »

# `pycassa.system_manager` – Manage Schema Definitions

`pycassa.system_manager.``SIMPLE_STRATEGY` = 'SimpleStrategy'

  Replication strategy that simply chooses consecutive nodes in the ring for replicas

`pycassa.system_manager.``NETWORK_TOPOLOGY_STRATEGY` = 'NetworkTopologyStrategy'

  Replication strategy that puts a number of replicas in each datacenter

`pycassa.system_manager.``OLD_NETWORK_TOPOLOGY_STRATEGY` = 'OldNetworkTopologyStrategy'

  Original replication strategy for putting a number of replicas in each datacenter. This was originally called ‘RackAwareStrategy’.

`pycassa.system_manager.``KEYS_INDEX` = 0

  A secondary index type where each indexed value receives its own row

class `pycassa.system_manager.``SystemManager`(server='localhost:9160', credentials=None, framed_transport=True, timeout=30, socket_factory=<function default_socket_factory at 0x7f1b00c241b8>, transport_factory=<function default_transport_factory at 0x7f1affd06488>)

  Lets you examine and modify schema definitions as well as get basic information about the cluster.

  This class is mainly designed to be used manually in a python shell, not as part of a program, although it can be used that way.

  All operations which modify a keyspace or column family definition will block until the cluster reports that all nodes have accepted the modification.

  Example Usage:

      >>> from pycassa.system_manager import *
      >>> sys = SystemManager('192.168.10.2:9160')
      >>> sys.create_keyspace('TestKeyspace', SIMPLE_STRATEGY, {'replication_factor': '1'})
      >>> sys.create_column_family('TestKeyspace', 'TestCF', super=False,
      ...                          comparator_type=LONG_TYPE)
      >>> sys.alter_column_family('TestKeyspace', 'TestCF', key_cache_size=42, gc_grace_seconds=1000)
      >>> sys.drop_keyspace('TestKeyspace')
      >>> sys.close()

  `close`()

    Closes the underlying connection

  `get_keyspace_column_families`(keyspace, use_dict_for_col_metadata=False)

    Returns a raw description of the keyspace, which is more useful for use in programs than `describe_keyspace()`.

    If use_dict_for_col_metadata is `True`, the CfDef’s column_metadata will be stored as a dictionary where the keys are column names instead of a list.

    Returns a dictionary of the form `{column_family_name: CfDef}`

  `get_keyspace_properties`(keyspace)

    Gets a keyspace’s properties.

    Returns a `dict` with ‘strategy_class’ and ‘strategy_options’ as keys.

  `list_keyspaces`()

    Returns a list of all keyspace names.

  `describe_ring`(keyspace)

    Describes the Cassandra cluster

  `describe_token_map`()

    List tokens and their node assignments.

  `describe_cluster_name`()

    Gives the cluster name

  `describe_version`()

    Gives the server’s API version

  `describe_schema_versions`()

    Lists what schema version each node has

  `describe_partitioner`()

    Gives the partitioner that the cluster is using

  `describe_snitch`()

    Gives the snitch that the cluster is using

  `create_keyspace`(name, replication_strategy='SimpleStrategy', strategy_options=None, durable_writes=True, **ks_kwargs)

    Creates a new keyspace. Column families may be added to this keyspace after it is created using `create_column_family()`.

    replication_strategy determines how replicas are chosen for this keyspace. The strategies that Cassandra provides by default are available as `SIMPLE_STRATEGY`, `NETWORK_TOPOLOGY_STRATEGY`, and `OLD_NETWORK_TOPOLOGY_STRATEGY`.

    strategy_options is a dictionary of strategy options. For NetworkTopologyStrategy, the dictionary should look like `{'Datacenter1': '2', 'Datacenter2': '1'}`. This maps each datacenter (as defined in a Cassandra property file) to a replica count. For SimpleStrategy, you can specify the replication factor as follows: `{'replication_factor': '1'}`.

    Example Usage:

        >>> from pycassa.system_manager import *
        >>> sys = SystemManager('192.168.10.2:9160')
        >>> # Create a SimpleStrategy keyspace
        >>> sys.create_keyspace('SimpleKS', SIMPLE_STRATEGY, {'replication_factor': '1'})
        >>> # Create a NetworkTopologyStrategy keyspace
        >>> sys.create_keyspace('NTS_KS', NETWORK_TOPOLOGY_STRATEGY, {'DC1': '2', 'DC2': '1'})
        >>> sys.close()

  `alter_keyspace`(keyspace, replication_strategy=None, strategy_options=None, durable_writes=None, **ks_kwargs)

    Alters an existing keyspace.

    Warning

    Don’t use this unless you know what you are doing.

    Parameters are the same as for `create_keyspace()`.

  `drop_keyspace`(keyspace)

    Drops a keyspace from the cluster.

  `create_column_family`(keyspace, name, column_validation_classes=None, **cf_kwargs)

    Creates a new column family in a given keyspace. If a value is not supplied for any of optional parameters, Cassandra will use a reasonable default value.

    keyspace should be the name of the keyspace the column family will be created in. name gives the name of the column family.

  `alter_column_family`(keyspace, column_family, column_validation_classes=None, **cf_kwargs)

    Alters an existing column family.

    Parameter meanings are the same as for `create_column_family()`.

  `drop_column_family`(keyspace, column_family)

    Drops a column family from the keyspace.

  `alter_column`(keyspace, column_family, column, value_type)

    Sets a data type for the value of a specific column.

    value_type is a string that determines what type the column value will be. By default, `LONG_TYPE`, `INT_TYPE`, `ASCII_TYPE`, `UTF8_TYPE`, `TIME_UUID_TYPE`, `LEXICAL_UUID_TYPE` and `BYTES_TYPE` are provided. Custom types may be used as well by providing the class name; if the custom comparator class is not in `org.apache.cassandra.db.marshal`, the fully qualified class name must be given.

    For super column families, this sets the subcolumn value type for any subcolumn named column, regardless of the super column name.

  `create_index`(keyspace, column_family, column, value_type, index_type=0, index_name=None)

    Creates an index on a column.

    This allows efficient for index usage via `get_indexed_slices()`

    column specifies what column to index, and value_type is a string that describes that column’s value’s data type; see `alter_column()` for a full description of value_type.

    index_type determines how the index will be stored internally. Currently, `KEYS_INDEX` is the only option. index_name is an optional name for the index.

    Example Usage:

        >>> from pycassa.system_manager import *
        >>> sys = SystemManager('192.168.2.10:9160')
        >>> sys.create_index('Keyspace1', 'Standard1', 'birthdate', LONG_TYPE, index_name='bday_index')
        >>> sys.close

  `drop_index`(keyspace, column_family, column)

    Drops an index on a column.

### Navigation

- index
- modules |
- next |
- previous |
- pycassa 1.11.1 documentation »
- API Documentation »