[openstack-dev] Swift App

Adrian Smith adrian at 17od.com
Wed Oct 17 08:36:36 UTC 2012


Hi Rugwiro,

Are you having a problem setting up PyDev or writing the code to interact
with Swift?

I'm not familiar with Python on Windows but assuming you're using pip you
can install the Swift Python bindings like this,

  pip install python-swiftclient

Here's some sample Python to carry out various operations,

--------------------------------------------------------------------------------
from swiftclient.client import get_auth, put_object, put_container, \
    get_object, delete_object, delete_container

AUTH_URL = 'http://127.0.0.1:8080/auth/v1.0'
USER = 'test:tester'
PASSWORD = 'testing'

if __name__ == '__main__':
    # authenticate
    (url, token) = get_auth(AUTH_URL, USER, PASSWORD)

    # create a container
    container = "docs"
    put_container(url, token, container)

    # upload an object
    filename = "helloworld"
    obj_file = open('/tmp/%s' % filename)
    put_object(url, token, container, filename, obj_file)
    obj_file.close()

    # Download the object
    (headers, obj_contents) = get_object(url, token, container, filename)
    downloaded_obj = open('/tmp/%s_downloaded' % filename, 'w')
    downloaded_obj.write(obj_contents)
    downloaded_obj.close()

    # Delete the object
    delete_object(url, token, container, filename)

    # Delete the container
    delete_container(url, token, container)
--------------------------------------------------------------------------------



On 17 October 2012 02:37, Rugwiro Ulysse <rugwiro05 at yahoo.com> wrote:

> Dear John Dickinson
>
>  I would like to ask a favor from you,i followed the instruction you gave
> me on how to apload quickly file on swift but i couldnt run and test you
> code .could you guide me step by step on how i should do it?? i am using
> windows 7 OS and PyDev
>
>  Thanks a lot!!
>
>
> --- On *Mon, 10/8/12, John Dickinson <me at not.mn>* wrote:
>
>
> From: John Dickinson <me at not.mn>
> Subject: Re: [openstack-dev] Swift App
> To: "OpenStack Development Mailing List" <
> openstack-dev at lists.openstack.org>
> Date: Monday, October 8, 2012, 6:20 PM
>
>
> "Advice on swift application development" could cover a lot of ground and
> fill a lot of pages of text. However, here are some getting started places.
>
> First, check out the swift API docs at http://docs.openstack.org. Swift's
> API is HTTP, so any client or library that speaks HTTP can talk to swift.
> I've published some examples of using Python's httplib to talk to swift at
> http://programmerthoughts.com/programming/quickly-uploading-to-cloud-files-part-2/
> .
>
> If you are looking for language bindings, check out either
> https://github.com/openstack/python-swiftclient (the official Python
> language bindings) or https://github.com/rackspace/python-cloudfiles).
> There are bindings for other languages as well.
>
> As a general guide for building a client app, first, know your data. Try
> to use concurrency when talking to swift (instead of sending each request
> serially). Also, for large data sets, shard your data across many
> containers. Try to target 1-10 million objects in each container (although
> this is affected by your hardware deployment choices). Swift is designed
> for high throughput using many concurrent connections, so take advantage of
> that.
>
> --John
>
>
>
>
>
> On Oct 8, 2012, at 9:03 AM, Rugwiro Ulysse <rugwiro05 at yahoo.com<http://us.mc1129.mail.yahoo.com/mc/compose?to=rugwiro05@yahoo.com>>
> wrote:
>
> > Hello everyone !!
> >
> > I would like your advice on swift application development.
> >
> > " How a client can talk directly to a swift cluster without a web
> service invorved?"
> >
> > This question have been in my mind for long and i dont seem to have
> figured out how to make such application in python. any ideas??
> >
> > Regards!!
> > _______________________________________________
> > OpenStack-dev mailing list
> > OpenStack-dev at lists.openstack.org<http://us.mc1129.mail.yahoo.com/mc/compose?to=OpenStack-dev@lists.openstack.org>
> > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
> -----Inline Attachment Follows-----
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org<http://us.mc1129.mail.yahoo.com/mc/compose?to=OpenStack-dev@lists.openstack.org>
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20121017/5cdb60e2/attachment-0001.html>


More information about the OpenStack-dev mailing list