Skip to main content

A SDK for Menous DB

Project description

<title>Document</title> <style> .container{ align-items: center; } .image{ max-height:200px; } </style>

Introduction

Menous DB is a simple and elegant key value database. It uses a structured file system to store key values. The database is written in python and can be used directly in python using the menousdb pip package.

Installation

You can install the menousdb module by using the pip package manager. You can install the package manager on all platforms by using the following commands:

For Linux use the following commands

$ sudo apt update
$ sudo apt upgrade
$ sudo apt-get install python3-pip
For Mac OS use homebrew to install pip

$ brew install python3-pip

Next we will use the pip package manager to install the library. Make sure you have pip set up properly and you can access it through your terminal window.

(Windows)

$ pip install menousdb 

(Mac OS and Linux)

$ pip3 install menousdb

Documentation

Importing the module

To import the menousdb import simply use

from menousdb import *

Initializing the database

To create a database from scratch use:

# Using the imported class from the import statement

db = MenousDB(
    url="http://localhost:5555/",
    key="YOUR API KEY",
    database="DATABASE"
)

# Checking if the database exists
if not db.checkDbExists():
    # If not create the database
    db.createDb()

Checking if the database exists

# isCreated is either True or False
isCreated = db.checkDbExists()

Reading the entire database

To read the entire database we will use the readDb method. The readDb method returns a dictionary that can be converted to a dataframe.

data = db.readDb()

Deleting the entire database

To delete the entire database we will use the deleteDb method.

if db.checkDbExists():
    db.deleteDb()
else:
    print("Database not found")

Creating a new table

To create a new table, the parameters are the name of the table and the attributes of the new table. The attributes parameter must be a list of strings.

# Defining the table name and attributes
table_name = "test"
attributes = ["name", "age", "gender"]

# Creating a new table using the defined variable
db.createTable(table_name, attributes)

Checking if a table exists

To check if a table exists you can use the following which will return a boolean value of True or False.

# Defining the table name
table_name = "test"
# Cheking the table exists
isCreate = db.checkTableExists(table_name)

Inserting values into the database

To insert new values into the table you can use the following code. The parameter values must be a dictionary whose order of keys must exactly match the order of the attributes passed in the creation of the table.

# Defining table name and values
table_name = test
values = {
    "name":"John Doe",
    "age":"15",
    "gender":"male"
}

db.insertIntoTable(
    table=table_name,
    values=values
)

Selecting the entire table

To get the complete data of a table use the following code:

table_name = "test"
# Getting all the data in the table
data = db.getTable(table_name)

Selecting Values with conditions

To search for values with conditions you can use the following code. The parameters required are the table name and the conditions which will be a dictionary.

table_name = "test"
conditions = {
    "name":"John Doe"
}

# Contains all the values where the name is John Doe
data = db.selectWhere(
    table= table_name,
    conditions=conditions
)

Selecting columns

To select only specefic columns from the table you can use the following code. The parameters include the table name and a list of names of columns you want to select.

table_name = "test"
columns=["name","age"]

# contains all the column values
selectedData = db.selectColumns(table_name, columns)

Selecting columns with conditions

To select columns with conditions you can use the following code. The parameters include the table name, the target columns and the conditions. conditions will be a dictionary and columns will be an array.

table_name="test"
columns=["name","age"]
conditions={"name":"John Doe"}

data = db.selectColumnsWhere(
    table_name,
    columns,
    conditions
)

Updating values

To update the values in the table we need the conditions and the replacement values. The parameters are the table name, the conditions and the replacement values.

table_name = "test"
conditions = {
    "name":"John Doe"
}
values = {
    "name":"William Smith"
}

# This will replace the value of every row where the 
# name is John Doe to William Smith
db.updateWhere(
    table=table_name,
    conditions=conditions,
    values=values
)

Deleting values

To delete values from a table with conditions use the following code. The parameters are the table name and the conditions.

table_name = "test"
conditions = {
    "name":"John Doe",
}
db.deleteWhere(
    table=table_name,
    conditions=conditions
)

Deleting the entire table

To delete the entire table just use the deleteTable functions. Its only parameter is the table name.

table_name="test"
db.deleteTable(table_name)

Getting all the databases

To get a list of all the databases use the following code.

databases = db.getDatabases()

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

menousdb-0.1.3.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

menousdb-0.1.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file menousdb-0.1.3.tar.gz.

File metadata

  • Download URL: menousdb-0.1.3.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for menousdb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f3f8dfeff1426f3ec07906b42a12dfe853c8041cb73f3c12e1a5326c09166f74
MD5 bf1b44386d74d64f7fbaa6ac6e1ff758
BLAKE2b-256 96204434b8c00b6ff266f976d7ce91b49352a5e4dda81829a5fb54c3bedeba40

See more details on using hashes here.

File details

Details for the file menousdb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: menousdb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for menousdb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2a0ca233e429ae13b5aec9e61fa0829eb28542682d2f407d9f360a82aeac91a4
MD5 7bdab7ae0d226e2ae2b397581de64135
BLAKE2b-256 7b750cbee35ae550a5bd25efcf4313d6d9d25b87c64d6425fe103eeb542365a8

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