How can I access s3 files in Python using urls?

后端 未结 6 1175
一个人的身影
一个人的身影 2020-12-14 16:44

I want to write a Python script that will read and write files from s3 using their url\'s, eg:\'s3:/mybucket/file\'. It would need to run locally and in the cloud without a

6条回答
  •  Happy的楠姐
    2020-12-14 17:01

    I haven't seen something that would work directly with S3 urls, but you could use an S3 access library (simples3 looks decent) and some simple string manipulation:

    >>> url = "s3:/bucket/path/"
    >>> _, path = url.split(":", 1)
    >>> path = path.lstrip("/")
    >>> bucket, path = path.split("/", 1)
    >>> print bucket
    'bucket'
    >>> print path
    'path/'
    

提交回复
热议问题