Skip to main content

A lightweight, file-based NoSQL key-value database using sqlite3, designed for simple and practical uses without external dependencies.

Project description

keyv

A lightweight, file-based NoSQL key-value database designed for simple and practical uses. It requires no external dependencies and stores all data locally in a single file. Perfect for applications needing a straightforward and efficient storage solution.

pip install keyv

How it works

keyv uses sqlite3 as its engine, thereby benefiting from its power, integrity, and practicality. This looks strange but it works like a charm.

Usage

import keyv

# initialize the database
db = keyv.connect('db.keyv') # or .db, or .anything, you choose

# insert a key-value pair
db.put('key1', 'value1')

# by default the .put method is unique safe, i.e. it raises an error
# if the key already exists. if you don't want that behavior you can
# use replace_if_exists=True.
db.put('key1', 'value1', replace_if_exists=True)

# retrieve a value by key
db.get('key1')
# output: 'value1'
# note: the get method returns None for non-existing keys

# update a value
db.update('key1', 123)
db.get('key1')
# output: 123

# delete a key-value pair
db.delete('key1')

# search for keys by value
db.put('key2', 'common_value')
db.put('key3', 'common_value')
db.search('common_value')
# output: ['key2', 'key3']

# retrieve all keys
db.keys()
# output: ['key2', 'key3']

Collections

Collections allow you to organize your data into separate namespaces within the same database file. In practice, they are tables inside the SQLite file. Here's how you can use them:

# Create a new collection
collection = db.collection('my_collection')

# Insert a key-value pair into the collection
collection.put('key1', 'value1')

# Retrieve a value by key from the collection
collection.get('key1')
# Output: 'value1'

# Update a value in the collection
collection.update('key1', 'new_value')

# Check if a key exists in the collection
collection.key_exists('key1')
# Output: True

# Delete a key-value pair from the collection
collection.delete('key1')

# Search for keys by value in the collection
collection.put('key2', 'common_value')
collection.put('key3', 'common_value')
collection.search('common_value')
# Output: ['key2', 'key3']

# Retrieve all keys in the collection
collection.keys()
# Output: ['key2', 'key3']

# Retrieve all values in the collection
collection.values()
# Output: ['common_value', 'common_value']

Collections provide a flexible way to manage different sets of data within the same database, making it easier to organize and access your data efficiently.

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

keyv-0.2.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keyv-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file keyv-0.2.0.tar.gz.

File metadata

  • Download URL: keyv-0.2.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Windows/10

File hashes

Hashes for keyv-0.2.0.tar.gz
Algorithm Hash digest
SHA256 db061b622db94b4a129e1e153cda5eca3b31348f97a788502d405a9491bcb9b2
MD5 7c9e7c4433dc9c00d339a7104b8f6103
BLAKE2b-256 a025d7cd8d1e03daedd6688d19af3fded272962f52f8b088e9cba3bdc4aa789a

See more details on using hashes here.

File details

Details for the file keyv-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: keyv-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Windows/10

File hashes

Hashes for keyv-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9899ef71c4e58f84a5f4bc8970c3cec866c3ec1cd3647d4b319907f94d167f5f
MD5 f65f591ca7b3bebc32c8fb5c9a3d84ad
BLAKE2b-256 958485807537dc4554dcb0b81b152a9f7d1b2090d3bb69da8535cbf26675c8a4

See more details on using hashes here.

Supported by

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