Skip to main content

A fun and easy way to store python objects.

Project description

Testing Pypi-Upload

Object Bucket

An easy and fun way to store python objects.


Table of contents


Description

Object Bucket is a python package that allows you to store python objects permanently in a more user friendly way.


Installation

The object-bucket package can be installed by using pip.

pip install object-bucket

Usage

  • Creating new bucket.

from object_bucket import Bucket

test_bucket = Bucket("name-of-the-bucket")
  • Adding droplets to the bucket, droplets are considered as objects that you want to save permanently.
test_obj = [1, 2, 3, 4]
test_bucket.add_droplet("droplet-name", test_obj)

Trying to add a droplet with the same name will cause an error.

  • Adding multiple droplets. To add multiple droplets you have to have a dictionary that contains all the names and objects of the droplet. To add the dictionary you can use the add_droplets method.
droplets = {
      "one": 1,
      "two": 2,
      "three": [2, 3, 4]
  }

  test_bucket.add_droplets(droplets)
  • Modifying a droplet

new_obj = {1: "a"}
test_bucket.modify_droplet("droplet-name", new_obj)

Trying to modify a droplet that does not exists will cause an error.

  • Saving a bucket

All the things mentioned above will not be added or saved permanently, to do so it is necessary to save the bucket.

test_bucket.save_bucket()
  • Retrieving values from a bucket.

from object_bucket import Bucket
test_bucket = Bucket("name-of-the-bucket")
a = test.bucker.get_droplet("droplet-name")
print(a)  # {1: "a"}

Trying to get a droplet that does not exists will cause an error.

  • Get all the runtime droplets
drop1 = [1, 2, 3, 4]
drop2 = "Hello"
drop3 = {1: "a", 2: "b"}
test_bucket.add_droplet("drop1", drop1)
test_bucket.add_droplet("drop2", drop2)
test_bucket.add_droplet("drop3", drop3)

# to get all the droplets
a = test_bucket.get_all_droplets()
print(a)

# output
{"drop1": [1, 2, 3, 4], "drop2": "Hello", "drop3": {1: "a", 2: "b"}}
  • Deleting a bucket To delete the bucket and to clear the runtime storage of all the droplets.
test_bucket.delete_bucket()
  • You can also delete a bucket using remove_bucket function
from object_bucket import remove_bucket
remove_bucket("name-of_bucket_to_be_removed")

Using the context manager.

It might be a hastle to remember to save to bucket, so you can use the context manager to avoid using the save_bucket method.

Note: Using Bucket().delete_bucket inside the context manager is useless as at the end the file will be saved automatically.

from object_bucket import Bucket

with Bucket("name-of-the-bucket") as b:
  # code to execute
  b.add_droplet("name", 1)
  # ...etc
  b.delete_bucket()  # wont work as the file will be again saved,
  # but the runtime contents will be cleared

Some more stuff

  • You can use the if statement to check whether a bucket is empty or not
from object_bucket import Bucket
t = Bucket("name")
if t:
  print("Hello")  # -> does not print anything as bucket is empty

t.add_droplet("demo", 1)
if t:
  print("Hello 2")  # -> prints "hello 2" as the bucket has at least one droplet
  • To get the number of droplets in a bucket you can use the len method
from object_bucket import Bucket
t = Bucket("name")
print(len(t)) # -> 0
t.add_droplet("demo", [1, 2, 3])
print(len(t)) # -> 1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

object-bucket-1.6.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

object_bucket-1.6.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file object-bucket-1.6.1.tar.gz.

File metadata

  • Download URL: object-bucket-1.6.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for object-bucket-1.6.1.tar.gz
Algorithm Hash digest
SHA256 e2b6c680e3619eb0588e634735c69675ab12e725b3a4bf086f8ef11b0a1390f0
MD5 851d0afdde5434b9d1522dbf0634bf82
BLAKE2b-256 2b04abba1bc8a2d5e6c6dda4dd9846a2633eabd40245349720b8306143be3d22

See more details on using hashes here.

File details

Details for the file object_bucket-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: object_bucket-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for object_bucket-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a6fb4b4a400d6623a7fc118375d7bbec4c4c96c8963cb557eec73928955fdfb
MD5 87d5630f67f1034a9266344c73ba1321
BLAKE2b-256 40451ef1bfada5b15bffa16a50e508196a63f5a65ed1bcd401088fe3d63401fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page