index.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. .. S3FS documentation master file, created by
  2. sphinx-quickstart on Sat Aug 5 12:55:45 2017.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. S3FS
  6. ====
  7. S3FS is a `PyFilesystem interface
  8. <https://docs.pyfilesystem.org/en/latest/reference/base.html>`_ to
  9. Amazon S3 cloud storage.
  10. As a PyFilesystem concrete class, S3FS allows you to work with S3 in the
  11. same as any other supported filesystem.
  12. Installing
  13. ==========
  14. S3FS may be installed from pip with the following command::
  15. pip install fs-s3fs
  16. This will install the most recent stable version.
  17. Alternatively, if you want the cutting edge code, you can check out
  18. the GitHub repos at https://github.com/pyfilesystem/s3fs
  19. Opening an S3 Filesystem
  20. ========================
  21. There are two options for constructing a :ref:`s3fs` instance. The simplest way
  22. is with an *opener*, which is a simple URL like syntax. Here is an example::
  23. from fs import open_fs
  24. s3fs = open_fs('s3://mybucket/')
  25. For more granular control, you may import the S3FS class and construct
  26. it explicitly::
  27. from fs_s3fs import S3FS
  28. s3fs = S3FS('mybucket')
  29. S3FS Constructor
  30. ----------------
  31. .. autoclass:: fs_s3fs.S3FS
  32. :members:
  33. Limitations
  34. ===========
  35. Amazon S3 isn't strictly speaking a *filesystem*, in that it contains
  36. files, but doesn't offer true *directories*. S3FS follows the convention
  37. of simulating directories by creating an object that ends in a forward
  38. slash. For instance, if you create a file called `"foo/bar"`, S3FS will
  39. create an S3 object for the file called `"foo/bar"` *and* an
  40. empty object called `"foo/"` which stores that fact that the `"foo"`
  41. directory exists.
  42. If you create all your files and directories with S3FS, then you can
  43. forget about how things are stored under the hood. Everything will work
  44. as you expect. You *may* run in to problems if your data has been
  45. uploaded without the use of S3FS. For instance, if you create a
  46. `"foo/bar"` object without a `"foo/"` object. If this occurs, then S3FS
  47. may give errors about directories not existing, where you would expect
  48. them to be. The solution is to create an empty object for all
  49. directories and subdirectories. Fortunately most tools will do this for
  50. you, and it is probably only required of you upload your files manually.
  51. Authentication
  52. ==============
  53. If you don't supply any credentials, then S3FS will use the access key
  54. and secret key configured on your system. You may also specify when
  55. creating the filesystem instance. Here's how you would do that with an
  56. opener::
  57. s3fs = open_fs('s3://<access key>:<secret key>@mybucket')
  58. Here's how you specify credentials with the constructor::
  59. s3fs = S3FS(
  60. 'mybucket'
  61. aws_access_key_id=<access key>,
  62. aws_secret_access_key=<secret key>
  63. )
  64. .. note::
  65. Amazon recommends against specifying credentials explicitly like
  66. this in production.
  67. S3 Info
  68. =======
  69. You can retrieve S3 info via the ``s3`` namespace. Here's an example:
  70. >>> info = s.getinfo('foo', namespaces=['s3'])
  71. >>> info.raw['s3']
  72. {'metadata': {}, 'delete_marker': None, 'version_id': None, 'parts_count': None, 'accept_ranges': 'bytes', 'last_modified': 1501935315, 'content_length': 3, 'content_encoding': None, 'request_charged': None, 'replication_status': None, 'server_side_encryption': None, 'expires': None, 'restore': None, 'content_type': 'binary/octet-stream', 'sse_customer_key_md5': None, 'content_disposition': None, 'storage_class': None, 'expiration': None, 'missing_meta': None, 'content_language': None, 'ssekms_key_id': None, 'sse_customer_algorithm': None, 'e_tag': '"37b51d194a7513e45b56f6524f2d51f2"', 'website_redirect_location': None, 'cache_control': None}
  73. URLs
  74. ====
  75. You can use the ``geturl`` method to generate an externally accessible
  76. URL from an S3 object. Here's an example:
  77. >>> s3fs.geturl('foo')
  78. 'https://fsexample.s3.amazonaws.com//foo?AWSAccessKeyId=AKIAIEZZDQU72WQP3JUA&Expires=1501939084&Signature=4rfDuqVgmvILjtTeYOJvyIXRMvs%3D'
  79. More Information
  80. ================
  81. See the `PyFilesystem Docs <https://docs.pyfilesystem.org>`_ for documentation on the rest of the PyFilesystem interface.
  82. Indices and tables
  83. ==================
  84. * :ref:`genindex`
  85. * :ref:`modindex`
  86. * :ref:`search`