A wrapper around the vercel storage blob api
Project description
vercel-blob
A wrapper around the vercel blob api
Current status
Currently it only implements the Vercel Blob API. You can use this package as a library as well as a command line utility.
Installation
This package is still unreleased. You can only install it locally.
git clone https://github.com/misaelnieto/vercel-storage.git
cd vercel-storage
pip install -e .
Installation in development mode
Probably only useful for the author and contributors.
pip install -e '.[test]
Run tests:
pytest
Command line usage
Configuration
You must set the BLOB_READ_WRITE_TOKEN
environment variable to be able to use the library.
export BLOB_READ_WRITE_TOKEN="vercel_blob_rw_ABC1234XYz"
Put operation
$ vercel_blob put disk_dump.bin
------------------ ----------------------------------------------------------------------------------------------------
url https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/disk_dump-OTgBsduT0QQcfXImNMZky1NSy3HfML.bin
pathname disk_dump.bin
contentType application/octet-stream
contentDisposition attachment; filename="disk_dump.bin"
------------------ ----------------------------------------------------------------------------------------------------
You can also print the output information as a json:
$ vercel_blob --json put disk_dump.bin
{'url': 'https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/disk_dump-0eX9NYJnZjO31GsDiwDaQ6TR9QnWkH.bin', 'pathname': 'disk_dump.bin', 'contentType': 'text/plain', 'contentDisposition': 'attachment; filename="disk_dump.bin"'}
By default, Vercel's blob store will insert a randomly generated string to the name of your file. But you can turn off that feature:
$ vercel_blob put --no-suffix chart.png
------------------ -----------------------------------------------------------------
url https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/chart.png
pathname chart.png
contentType image/png
contentDisposition attachment; filename="chart.png"
------------------ -----------------------------------------------------------------
List operation
The list method returns a list of blob objects in a Blob store. For example, let's upload a file to the bob store:
vercel_blob put profile.png
------------------ --------------------------------------------------------------------------------------------------
url https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/profile-OtpJ1AUIxChAA6UZejVXPA1pkuBw2D.png
pathname profile.png
contentType image/png
contentDisposition attachment; filename="profile.png"
------------------ --------------------------------------------------------------------------------------------------
Now you can see your file on your blob store:
vercel_blob list
Path name Size in bytes url
----------- --------------- -------------------------------------------------------------------
profile.png 11211 https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/profile-OtpJ1AUIxChAA6UZejVXPA1pkuBw2D.png
Copy operation
$ vercel_blob copy https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/disk_dump-0eX9NYJnZjO31GsDiwDaQ6TR9QnWkH.bin file.zip
------------------ ----------------------------------------------------------------
url https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip
pathname file.zip
contentType application/octet-stream
contentDisposition attachment; filename="file.zip"
------------------ ----------------------------------------------------------------
You can also print the output information as a json:
$ vercel_blob --json copy https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/disk_dump-0eX9NYJnZjO31GsDiwDaQ6TR9QnWkH.bin file.zip
{'url': 'https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip', 'pathname': 'file.zip', 'contentType': 'application/octet-stream', 'contentDisposition': 'attachment; filename="file.zip"'}
Delete operation
The delete operation always suceeds, regardless of whether the blob exists or not. It returns a null payload.
$ vercel_blob delete https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/disk_dump-mSjTcLOIg8hlGNiWpWMUcGqVll1uST.bin
Head operation
The head operation returns a blob object's metadata.
$ vercel_blob head https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip
------------------ ----------------------------------------------------------------
url https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip
pathname file.zip
contentType application/octet-stream
contentDisposition attachment; filename="file.zip"
uploadedAt 2023-11-16T23:53:25.000Z
size 1998
cacheControl public, max-age=31536000, s-maxage=300
------------------ ----------------------------------------------------------------
As with the other commands, you can generate json output:
$ vercel_blob --json head https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip
{'url': 'https://c6zu0uktwgrh0d3g.public.blob.vercel-storage.com/file.zip', 'pathname': 'file.zip', 'contentType': 'application/octet-stream', 'contentDisposition': 'attachment; filename="file.zip"', 'uploadedAt': '2023-11-16T23:53:25.000Z', 'size': 1998, 'cacheControl': 'public, max-age=31536000, s-maxage=300'}
Using vercel_storage in your python code
List operation
Note: vercel_storage
will look for the BLOB_READ_WRITE_TOKEN
environment variable. If it is not available
it will raise an Exception.
If you have the token stored somewhere else, you can pass it directly to the put() function like this:
resp = blob.list(options={'token': 'ABCD123foobar'})
Put operation
from vercel_storage import blob
my_file = '/path/to/file.zip'
with open(my_file, 'rb') as fp:
resp = blob.put(
pathname=my_file,
body=fp.read()
)
Note: vercel_storage
will look for the BLOB_READ_WRITE_TOKEN
environment variable. If it is not available
it will raise an Exception.
If you have the token stored somewhere else, you can pass it directly to the put() function like this:
resp = blob.put(
pathname=my_file,
body=fp.read(),
options={'token': 'ABCD123foobar'}
)
Copy operation
retval = blob.copy(blob_url, to_path)
# or
retval = blob.copy(blob_url, to_path, options={"token": "ABCD123foobar"})
Delete operation
blob.delete(blob_url)
# or
blob.delete(blob_url, options={'token': 'ABCD123foobar'})
Head operation
blob.head(blob_url)
# or
blob.head(blob_url, options={'token': 'ABCD123foobar'})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file vercel_storage-0.0.1.tar.gz
.
File metadata
- Download URL: vercel_storage-0.0.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f286e9190f70fa02dd4a2ab4b3d98462d8c41cff2251bdc4ab76793f115f97e1 |
|
MD5 | 406adb7cd84cff7622e06cf298cc013e |
|
BLAKE2b-256 | a8864e26a30405e873f191bac1fc7576b68d804ffc77177dd51fc9e97b0a6fef |
File details
Details for the file vercel_storage-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: vercel_storage-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf27be00ce9c648c665c726eeebffe8e2205cc9f991ed8ca7f2d356e42c1e2c1 |
|
MD5 | 5a3ce9c40748e8940843ffd479dcf550 |
|
BLAKE2b-256 | 93bf6b879c383169117cfd5166fbba6d5cf6dacffd47689edd777991aec06279 |