Skip to main content

Simple in-memory storage for Python

Project description

# Bx

In-memory storage for Python

![build-status](https://travis-ci.org/tylucaskelley/bx-python.svg?branch=master)
![version](https://pypip.in/version/bx/badge.svg)
![downloads](https://pypip.in/download/bx/badge.svg)

---

```
__
___~~~` `~~__
___~~~ `~~_
|~_ `~_
| ~_ ___ ~~ |
| ~_ __~~~ |
| ~_ __~~~ |
| | |
| | |
| | bx |
~_ | __|
~_ | __~~~
~_ | __~~~
~|__~~~
```

bx lets you store things in memory. It has a few special features:

* Thread safe
* Setting a timeout before object is destroyed
* JSON Schema validation
* Clean & simple API
* Badass ASCII art
* Supports Python 2.7 and 3.4

## Installation

Just make sure you have Python 2.7.x or 3.4.x and pip installed:

```bash
$ pip install bx
```

## Usage

The code is pretty simple and well-commented, but here's some example usage. If
you want more detail, run `pydoc bx.Db` once you've installed it or look through
the code to get info.

```python
import bx

student = {
'title': 'student',
'type': 'object',
'required': ['name', 'major', 'gpa'],
'properties': {
'name': {
'type': 'string'
},
'major': {
'type': 'string'
},
'gpa': {
'type': 'number'
}
}
}

# The schema argument defaults to None, and there is also an optional
# debug mode (for console logging) that defaults to False
db = bx.Db(schema=student)

try:
db.put('bad', 'data')
except bx.db.ValidationError: # same as jsonschema.exceptions.ValidationError
print('This does not fit the schema!')

john = {
'name': 'John Doe',
'major': 'Computer Science',
'gpa': 3.6
}

susan = {
'name': 'Susan Jones',
'major': 'Physics',
'gpa': 3.96
}

db.put('john', john)
db.put('susan', susan)

# get average gpa
print(sum([v['gpa'] for v in db.vals()]) / len(db.vals()))

db.delete('susan')

try:
db.delete('bob')
except KeyError:
print('bob is not in the data store!')
```

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

bx-0.3.0.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file bx-0.3.0.tar.gz.

File metadata

  • Download URL: bx-0.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bx-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e940982782ce42d6e8a973af4daf64134b52cb1359336e09a5a4f8e4cf96f604
MD5 f2089f80f74f5141713112292bc690b6
BLAKE2b-256 66f853217efe538d3d7373beca30b7d48715399f6dd780e3e6ce973d0fd622f7

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