GithubHelp home page GithubHelp logo

alexkruegger / nodb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miserlou/nodb

0.0 2.0 0.0 37 KB

NoDB isn't a database.. but it sort of looks like one.

Home Page: https://blog.zappa.io/posts/introducing-nodb-pythonic-data-store-s3

Python 98.35% Shell 1.65%

nodb's Introduction

NoDB

Build Status Coverage PyPI Slack Gun.io Patreon

NoDB isn't a database.. but it sort of looks like one!

NoDB an incredibly simple, Pythonic object store based on Amazon's S3 static file storage.

It's useful for prototyping, casual hacking, and (maybe) even low-traffic server-less backends for Zappa apps!

Features

  • Schema-less!
  • Server-less!
  • Uses S3 as a datastore.
  • Loads to native Python objects with cPickle
  • Can use JSON as a serialization format for untrusted data
  • Cheap(ish)!
  • Fast(ish)! (Especially from Lambda)

Installation

NoDB can be installed easily via pip, like so:

$ pip install nodb

Warning!

NoDB is insecure by default! Do not use it for untrusted data before setting serializer to "json"!

Usage

NoDB is super easy to use!

You simply make a NoDB object, point it to your bucket and tell it what field you want to index on.

from nodb import NoDB

nodb = NoDB()
nodb.bucket = "my-s3-bucket"
nodb.index = "name"

After that, you can save and load literally anything you want, whenever you want!

# Save an object!
user = {"name": "Jeff", "age": 19}
nodb.save(user) # True

# Load our object!
user = nodb.load("Jeff")
print user.age # 19

# Delete our object
nodb.delete("Jeff") # True

By default, you can save and load any Python object.

Here's the same example, but with a class. Note the import and configuration is the same!

class User(object):
    name = None
    age = None

    def print_name(self):
        print "Hi, I'm " + self.name + "!"

new_user = User()
new_user.name = "Jeff"
new_user.age = 19
nodb.save(new_user) # True

jeff = nodb.load("Jeff")
jeff.print_name() # Hi, I'm Jeff!

Advanced Usage

Different Serializers

To use a safer, non-Pickle serializer, just set JSON as your serializer:

nodb = NoDB()
nodb.serializer = "json"

Note that for this to work, your object must be JSON-serializable.

Object Metadata

You can get metainfo (datetime and UUID) for a given object by passing metainfo=True to load, like so:

# Load our object and metainfo!
user, datetime, uuid = nodb.load("Jeff", metainfo=True)

Human Readable Indexes

By default, the indexes are hashed. If you want to be able to debug through the AWS console, set human_readable_indexes to True:

nodb.human_readable_indexes = True

TODO (Maybe?)

  • Tests with Placebo
  • Python3 support
  • Local file storage
  • Quering ranges (numberic IDs only), etc.
  • Different serializers
  • Custom serializers
  • Multiple indexes
  • Compression
  • Bucket management
  • Pseudo-locking
  • Performance/load testing

Related Projects

  • Zappa - Python's server-less framework!
  • K.E.V. - a Python ORM for key-value stores based on Redis, S3, and a S3/Redis hybrid backend.

Contributing

This project is still young, so there is still plenty to be done. Contributions are more than welcome!

Please file tickets for discussion before submitting patches. Pull requests should target master and should leave NoDB in a "shippable" state if merged.

If you are adding a non-trivial amount of new code, please include a functioning test in your PR. For AWS calls, we use the placebo library, which you can learn to use in their README. The test suite will be run by Travis CI once you open a pull request.

Please include the GitHub issue or pull request URL that has discussion related to your changes as a comment in the code (example). This greatly helps for project maintainability, as it allows us to trace back use cases and explain decision making.

License

(C) Rich Jones 2017, MIT License.


Made by Gun.io

nodb's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.