日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 嵌入键值数据库_PupDB 一个用Python编写基于文件的简单键值数据库

發(fā)布時間:2025/4/5 python 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 嵌入键值数据库_PupDB 一个用Python编写基于文件的简单键值数据库 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

What is it?

PupDB is an ernest attempt to create a simple file-based key-value database written in Python.

Why PupDB?

The objective behind the creation of PupDB is to create a database system which performs simple persistence operations well and data can be accessed with a minimalist, easy-to-use API with least configuration.

PupDB is the best choice when:

You need a simple NoSQL data store with an interface as simple as a Python dict, and want to start storing and retrieving data within a few minutes.

You want to create an application without bothering much about configuration and setup for storing data.

Your database is not very huge i.e. not greater than a few megabytes of data.

When not to use PupDB:

You want to perform advanced queries on your data.

Your database is larger than a few megabytes of data.

You want a database software that supports advanced capabilities like indexing, partitioning etc.

Salient Features

Multi-processing support: Same database file can be used across multiple processes concurrently.

Mult-threading support: Same database file (with separate PupDB instance per thread) can be used concurrently.

REST-based HTTP Interface: Apart from using it as a python package, you can also use PupDB via a flask-based HTTP interface. This way you can use PupDB with programming languages other than Python.

Installation

PupDB can be installed using pip:

pip install pupdb

Basic API Documentation and Usage

PupDB can be instantiated as follows:

from pupdb.core import PupDB

# Specify database file path as an argument to the PupDB constructor. That's it.

db = PupDB('db.json')

set(key, value): Stores the value mapped to key in the database file.

db.set('test_key', 'test_value')

get(key): Returns the value mapped to key in the database file. Returns None if key is not found.

db.get('test_key')

remove(key): Removes the key from the database file. Raises a KeyError if key is not found in the database file.

# Remove the key `test_key` from the db.

db.remove('test_key')

# Try doing the same again and it'll raise a `KeyError`,

# as the key has already been deleted from the db in the above step.

db.remove('test_key')

keys(): Returns the keys present in the database file. Return type is list in Python 2 and Dictionary view object (similar to dict.keys()) in Python 3.

# Python 2

print db.keys() # This will print ['key1', ...]

# Python 3

print(list(db.keys())) # This will print ['key1', ...]

values(): Returns the values of all keys present in the database file. Return type is list for Python 2 and Dictionary view object (similar to dict.values()) in Python 3.

# Python 2

print db.values() # This will print ['value1', ...]

# Python 3

print(list(db.values())) # This will print ['value1', ...]

items(): Returns the values of all keys present in the database file. Return type is list for Python 2 and Dictionary view object (similar to dict.items()) in Python 3.

# Python 2

print db.items() # This will print [('key1', 'value1'), ...]

# Python 3

print(list(db.items())) # This will print [('key1', 'value1'), ...]

dumps(): Returns a json dump of the entire database file sorted by key.

db.dumps() # This will print the database json string.

truncate_db(): Removes all data from the database file i.e. truncates the database file.

db.truncate_db()

print(db) # Will print an empty database dict '{}', as the database has been truncated.

Using the PupDB HTTP/REST Interface

Using the HTTP/REST Interface, all PupDB-related operations can be performed without using PupDB as a Python package. As a result, PupDB can be used in any programming language that can make HTTP requests.

To start PupDB's gunicorn-based flask server:

from pupdb.server import start_http_server

# Start the gunicorn server (with 4 worker threads).

start_http_server()

The server will listen to local port 4000. The server will be available at http://localhost:4000.

HTTP API Endpoints

/get?key= (Method: GET): This API endpoint is an interface to PupDB's get() method. e.g.:

curl -XGET http://localhost:4000/get?key=test

The above curl request will fetch the result for key test.

/set (Method: POST): This API endpoint is an interface to PupDB's set() method. e.g.:

curl -XPOST http://localhost:4000/set -H 'Content-Type: application/json' -d '{"key": "test", "value": "1234"}'

The above curl request will set the value 1234 to key test in the database.

/remove/ (Method: DELETE): This API endpoint is an interface to PupDB's remove() method. e.g.:

curl -XDELETE http://localhost:4000/remove/test

The above curl request will remove the key test in the database. It returns a 404 Not Found if the key does not exist in the database.

/keys (Method: GET): This API endpoint is an interface to PupDB's keys() method. e.g.:

curl -XGET http://localhost:4000/keys

The above curl request will return a payload containing the list of keys in the database.

/values (Method: GET): This API endpoint is an interface to PupDB's values() method. e.g.:

curl -XGET http://localhost:4000/values

The above curl request will return a payload containing the list of values of all keys in the database.

/items (Method: GET): This API endpoint is an interface to PupDB's items() method. e.g.:

curl -XGET http://localhost:4000/items

The above curl request will return a payload containing the list of [key, value] pairs in the database.

/dumps (Method: GET): This API endpoint is an interface to PupDB's dumps() method. e.g.:

curl -XGET http://localhost:4000/dumps

The above curl request will return a payload containing the string dump of the entire database.

/truncate-db (Method: POST): This API endpoint is an interface to PupDB's truncate_db() method. e.g.:

curl -XPOST http://localhost:4000/truncate-db

The above curl request will truncate i.e. remove all key-value pairs from the database.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.txt file for more details.

總結(jié)

以上是生活随笔為你收集整理的python 嵌入键值数据库_PupDB 一个用Python编写基于文件的简单键值数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 岛国伊人 | 精品久久五月天 | 成人免费观看网站 | 精品一区三区 | 长篇高h肉爽文丝袜 | 少妇免费看 | 国产稀缺真实呦乱在线 | 欧美精品免费在线 | 天天操夜夜操 | 久久日本精品字幕区二区 | 日韩中文第一页 | 天天干天天操天天舔 | 三上悠亚久久 | 99热这里只有精品5 国产精品伦子伦免费视频 精品一二三 | 日韩激情电影在线 | 91国产免费观看 | 久草中文在线观看 | 91在线精品一区二区 | 第一福利视频 | 黄色一级视频在线观看 | 91久久中文字幕 | 日本一区二区三区免费在线观看 | 40到50岁中老年妇女毛片 | 国产永久免费无遮挡 | 日本成人免费视频 | 青娱乐91 | 国产传媒av| 黄a网站 | 国产精品一区二区6 | 激情五月俺也去 | 美女黄色大片 | www.天天射| 国产一级片中文字幕 | av十大美巨乳 | 中国一区二区三区 | 毛片在线网站 | 视频免费1区二区三区 | 国产三级大片 | 欧美 日韩 国产 亚洲 色 | ,一级淫片a看免费 | 免费一二区| 国产一区二区三区四区在线观看 | 三级黄色片免费观看 | 欧美视频在线观看一区二区三区 | 亚洲17p| 国产亚洲综合av | 精品视频在线观看一区 | 久久精品男人的天堂 | 91福利一区 | 最近最新最好看的2019 | 日韩电影在线观看一区二区 | 国产成人亚洲精品无码h在线 | 私密视频在线观看 | 漂亮人妻被黑人久久精品 | 成人欧美在线 | 涩涩av| 亚洲av无码乱码在线观看富二代 | 天天视频污| 欧美精品黑人猛交高潮 | 日本黄视频网站 | 91精品国产乱码久久久张津瑜 | a级一级片 | 国产欧美久久一区二区三区 | 在线观看aa | 可以直接看av的网址 | 国产又大又硬又粗 | 黑人欧美一区二区三区 | 在线观看免费av网址 | 欧美成人综合网站 | 美女网站在线 | 亚洲最大福利视频 | 男女av在线| 五月天婷婷综合 | 国产亚洲精品久久久久久 | 重口味av| 男女激情视频网站 | 欧美a级大片 | 姐姐你真棒插曲快来救救我电影 | 国产精品免费入口 | 成人123区 | 五十路熟母 | 一区二区三区四区久久 | 男人天堂网址 | 久草电影网站 | 精品国产乱码久久久久久蜜柚 | 亚洲成人v | 日韩极品在线 | 欧美性受xxxx狂喷水 | 成人a免费 | 国产无套精品 | 国产午夜激情 | 国产一区二区播放 | 一直草| 美女涩涩视频 | 欧美乱妇15p | 神马影院午夜伦理 | 免费的毛片视频 | 91国产丝袜播放在线 | 国产精品入口日韩视频大尺度 |