Skip to content

saeedraaza/px-kvstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Developer

Muhammad Saeed Raza (saeedraza.work@gmail.com)

PX Key-Value Store

A simple HTTP key-value store using only Python standard library. Thread-safe and ready for production use.

Features

  • In-memory key-value storage
  • HTTP API with JSON responses
  • Thread-safe operations
  • Docker support
  • No external dependencies
  • Complete test coverage

Quick Start

Local Development

# Start the server
python3 -m app.main

# Test the API
curl -X PUT http://localhost:8080/kv/hello \
  -H "Content-Type: application/json" \
  -d '{"value": "world"}'

curl http://localhost:8080/kv/hello
# Response: {"key": "hello", "value": "world"}

Docker Deployment

# Build the Docker image
docker build -t px-kvstore .

# Run the container
docker run -p 8080:8080 px-kvstore

# Test the containerized service
curl http://localhost:8080/healthz

API

Endpoints

PUT /kv/{key} - Create or update

curl -X PUT http://localhost:8080/kv/username \
  -H "Content-Type: application/json" \
  -d '{"value": "alice"}'

Returns: 201 (created) or 200 (updated)

GET /kv/{key} - Get value

curl http://localhost:8080/kv/username

Returns: {"key": "username", "value": "alice"} or 404

DELETE /kv/{key} - Remove key

curl -X DELETE http://localhost:8080/kv/username

Returns: 204 (deleted) or 404

GET /healthz - Health check

curl http://localhost:8080/healthz

Returns: {"ok": true}

Testing

# Run tests
python3 -m unittest discover tests/

# Or use make
make test

Configuration

Set these environment variables:

# Change port (default: 8080)
PORT=9000 python3 -m app.main

# Change host (default: 0.0.0.0)  
HOST=127.0.0.1 PORT=9000 python3 -m app.main

Docker

# Build and run
make docker-build
make docker-run

# Or manually
docker build -t px-kvstore .
docker run -p 8080:8080 px-kvstore

Future Enhancements

Things we could add later:

  • Persistence: Save data to disk or database
  • Authentication: API keys or user login
  • Caching: LRU cache for better performance
  • Logging: Better logs and monitoring
  • Prefix search: GET /kv?prefix=user: to find keys
  • TTL: Auto-delete keys after timeout
  • Swagger docs: Interactive API documentation
  • Rate limiting: Prevent too many requests
  • Clustering: Multiple servers working together
  • Backup: Save and restore data

""" Design an undo operation for your key-value store and server.

  • The undo operation should be able to revert the latest change to the key-value store.
  • There are no input parameters to this API.
  • The only outputs should be a boolean/status

Example:

Initial State of KVStore

my_kvstore = {}

Create a key-value pair

my_kvstore = { 'my_key': 100 }

Alter a key-value pair

my_kvstore = { 'my_key': 25 }

Delete a key-value pair

my_kvstore = {}

Undo - Revert to the previous state

my_kvstore = { 'my_key': 25 }

Undo - Revert to the previous state

my_kvstore = { 'my_key': 100 }

Undo - Revert to the previous state

my_kvstore = {}

Undo again -

do nothing """

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published