10 This creates a connection so that you can interact with the server:
12 .. code-block:: python
15 user = 'account_name:username'
18 conn = swiftclient.Connection(
21 authurl='https://objects.dreamhost.com/auth',
28 This creates a new container called ``my-new-container``:
30 .. code-block:: python
32 container_name = 'my-new-container'
33 conn.put_container(container_name)
39 This creates a file ``hello.txt`` from the file named ``my_hello.txt``:
41 .. code-block:: python
43 with open('hello.txt', 'r') as hello_file:
44 conn.put_object(container_name, 'hello.txt',
45 contents= hello_file.read(),
46 content_type='text/plain')
52 This gets a list of containers that you own, and prints out the container name:
54 .. code-block:: python
56 for container in conn.get_account()[1]:
57 print container['name']
59 The output will look something like this::
65 List a Container's Content
66 ==========================
68 This gets a list of objects in the container, and prints out each
69 object's name, the file size, and last modified date:
71 .. code-block:: python
73 for data in conn.get_container(container_name)[1]:
74 print '{0}\t{1}\t{2}'.format(data['name'], data['bytes'], data['last_modified'])
76 The output will look something like this::
78 myphoto1.jpg 251262 2011-08-08T21:35:48.000Z
79 myphoto2.jpg 262518 2011-08-08T21:38:01.000Z
85 This downloads the object ``hello.txt`` and saves it in
88 .. code-block:: python
90 obj_tuple = conn.get_object(container_name, 'hello.txt')
91 with open('my_hello.txt', 'w') as my_hello:
92 my_hello.write(obj_tuple[1])
98 This deletes the object ``hello.txt``:
100 .. code-block:: python
102 conn.delete_object(container_name, 'hello.txt')
109 The container must be empty! Otherwise the request won't work!
111 .. code-block:: python
113 conn.delete_container(container_name)