pi7db


Namepi7db JSON
Version 2.1 PyPI version JSON
download
home_pagehttps://github.com/shivjeetbhullar/pi7db
Summarypi7db Is A Fast And Powerfull Directory Based Database Built In Python3.
upload_time2023-06-07 05:22:51
maintainer
docs_urlNone
authorShivjeet Singh Bhullar
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pi7db.
Pi7db is a open-source powerful python package to manage directory based database in JSON format with number of features like Filter, sort, update etc.

# WHY I USE Pi7db ?
There are some reasons may you like.
- NOSQL
- Flexible Data
- No Need To Make Connection To Database. (Most Hated Stuff)
- Simple And Super Fast.
- Directory Based Databse (Place Where You Want).
- Advance Filter Options Like (Less Than, Greater Than, String Filter, List Filter etc).
- Read, Write, Sort, Update, Trash, Filter Data With Advance Features.
- Encrypt Data With Password.

# DATABASE STRUCTURE
Data is stored in binary files inside collections. Database structure is similar to mongodb.
![image](https://drive.google.com/uc?export=view&id=1BXxi6mfcQ11mnBpSot96TvczC5LpgYa3 "Pi7db Structure")

## File Structure
```json
{
   "un_id": 20202171823558180,
   "title": "This Is File", 
   "description": "This file strore information.",
   "tags": ["pi7db", "database", "NoSQL"],
   "views": 10,
   "cr_dc_path":"Blog_Database/Collection_name/FileName.bin",
   "comments": [	
      {
         "user":"john",
         "message": "My Name is Jonh"
      }
   ]
}
```
There is un_id and cr_dc_path is avalible in every file by default represent a uniqe key for file and file path in system 

# INSTALLATION
Installation with pip
```sh
 $ pip3 install pi7db 
 ```
# Getting Started
First import pi7db package in python file and create a object by passing argument Database name. It will automatically create a directory in current folder with that name where all datafiles will be stored.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")
```
### Manual Database path
if you want to store database in a specific directory then pass second argument of path. 
```python
from pi7db import pi7db
db = pi7db("Blog_Database","path/to/dir")
```
# Write Data
Write function is used for write Json data.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

data = {
       "Name":"John",
       "Surname":"Diamond",
       "Tel-Number":9876543210,
       "Age":30,
       "Subject":["Python","Ruby","Perl"],
       "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                   ]
       }
       
db.write('Users',data)
# This Will Write Data In Users Collection.
```
### Write Data In Specific File Manually. 
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

data = {
       "Name":"John",
       "Surname":"Diamond",
       "Tel-Number":9876543210,
       "Age":30,
       "Subject":["Python","Ruby","Perl"],
       "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                   ]
       }
       
data2 = {
       "Name":"Richard",
       "Surname":"Stallman",
       "Tel-Number":9876543000,
       "Age":40,
       "Subject":["UNIX","C","Perl"],
       "comments": [
                   { "user":"Marshal",
                     "message": "I Love C Language."},
                   { "user":"Della",
                    "message": "C Is A Fast Language"}
                   ]
       }
       
db.write('Users' , 'John' , data)

db.write('Users' , 'Richard' , data2)
# This Will Write Data In john (filename john) file inside Users Collection.
```
Following Directory Tree Will Be Created In Your PC.
![image](https://drive.google.com/uc?export=view&id=1xoXs59TFbm-9cDZPlrupMEmzQkqJy-TM "Pi7db Structure")
You can directly call file during read time this will increase speed of your program.
For Example: You Can Call Specific Blog Post By Its Name. 

# Read Data
Data read is pretty easy and fast in pi7db. With the help of read function.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.read()

# This Will Read Entire Data In Database And Return Output In Dict.
# But Read Entire Data Is Not Recomended When Your Database Size Is Large For Example 500mb.
```

# Read Data From Collection
Data read is pretty easy and fast in pi7db. With the help of read function.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.read('Users')

# This Will Read Entire Data In Users Collection And Return Output In Dict.
```
#### Output:
```json
 {"data": 
   [
   { 
    "un_id": "20202660459428127",
    "Name": "John",
    "Surname": "Diamond",
    "Tel-Number": 9876543210,
    "Age":30,
    "Subject":["Python","Ruby","Perl"],
    "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                ],
    "cr_dc_path": "Blog_Database/Users/John.bin"
   },
   { 
    "un_id": "20202590449478829",
    "Name": "Richard",
    "Surname": "Stallman",
    "Tel-Number": 9876543000,
    "Age":40,
    "Subject":["UNIX","C","Perl"],
    "comments": [
                   { "user":"Marshal",
                     "message": "I Love C Language."},
                   { "user":"Della",
                    "message": "C Is A Fast Language"}
                   ],
    "cr_dc_path": "Blog_Database/Users/Richard.bin"
   }
   ], 
  "status": 1
 }
```
In output status:
 - 1 = Sucess
 - 0 = Error

# Read Data From File
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.read('Users','John')

# This Will Read Entire Data In Users Collection And Return Output In Dict.
```
#### Output:
```json
 {"data": 
   [{ 
    "unid": "20202660459428127",
    "Name": "John",
    "Surname": "Diamond",
    "Tel-Number": 9876543210,
    "Age":30,
    "Subject":["Python","Ruby","Perl"],
    "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                   ],
    "cr_dc_path": "Blog_Database/Users/John.bin"
   }], 
  "status": 1
 }
```
# Read Data From File By KeyName
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.read('Users','John','Surname')

# This Will Read Entire Data In Users Collection And Return Output In Dict.
```
#### Output:
```
 Diamond
```

# FILTER DATA
 Filter Is Most Powerfull Funtion Of This Package. You Can Filter Data According To Your Choice There Are Many Number Of Features Avalible In Filter Function. In Filter Function It Is Possible To Filter Data From Nested Dict Or List Of Dicts As The Way You Want. Filter Makes This Database More Flexible And Powefull.
 Some Features Are Shown Below:
 - Operators (Used For Filter Data)
   - OR
   - AND 
   - LT (Less Than)
   - GT (Greater Than)
   - GET (Greater And Equal Than)
   - LET (Less And Equal Than)
 - String Filter (User To Filter Data According To String)
   - Forward String Filter
   - Backward String Filter
   - Center String Filter
 - List Filter (Filter Data From List)
 - Nested Filter (Filter Data From Nested Dict)
 
 ### Simple Filter
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({"Name":"John"})
#This will filter all data where name is John and return output.
```
### Output
```json
{"data": [{
       "unid": "20203953408762519", 
       "Name": "John", 
       "Surname": "Diamond", 
       "Tel-Number": 9876543210, 
       "Age":30,
       "Subject":["Python","Ruby","Perl"],
       "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                   ],
       "cr_dc_path": "Blog_Database/Users/John.bin"
        }],
 "status": 1
}
```
 ### AND Filter
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({"Name":"John","Surname":"Diamond","Tel-Number":9876543210})
```
This Will Check In Database:
- if Name is John
- and Surname is Diamond
- and Tel-Number is 9876543210

If All These Conditions are True Then Return Output Otherwise Return Nothing.

### OR Filter
> **Note:** Before Using "OR" Operator You Have To Import It.
```python
from pi7db import pi7db, OR
db = pi7db("Blog_Database")

db.filter({"Name":"John"}, OR ,{"Surname":"Diamond","Tel-Number":9876543210})
```
This Will Check In Database:
- if Name is John
- OR Surname is Diamond and Tel-Number is 9876543210

If All These Conditions are True Then Return Output Otherwise Return Nothing.

### GT (GREATER THAN) Filter
> **Note:** Befor Using "GT" Operator You Have To Import It.
```python
from pi7db import pi7db, GT
db = pi7db("Blog_Database")

db.filter({ "Age": (GT,19) })
```
This Will Check In Database:
- if Age Greater Than 19

If This Condition is True Then Return Output Otherwise Return Nothing.

### LT (LESS THAN) Filter
> **Note:** Before Using "LT" Operator You Have To Import It.
```python
from pi7db import pi7db, LT
db = pi7db("Blog_Database")

db.filter({ "Age": (LT,39) })
```
This Will Check In Database:
- if Age Less Than 39

### LET (Less and Equal THAN) And GET (Greater and Equal Than) Filter
Use Of These Filters Are Similarly To **GT** And **LT** Operators. For Example
> **Note:** Before Using Operator You Have To Import It.
```python
from pi7db import pi7db, GET,LET
db = pi7db("Blog_Database")

#LET FILTER (Less and Equal THAN) 
db.filter({ "Age": (LET,40) })

#GET FILTER (Greater and Equal Than)
db.filter({ "Age": (GET,40) })
```
If This Condition is True Then Return Output Otherwise Return Nothing.
## STRING Filters
There Are Number Of String Filters are Avalible In pi7db.
- Forward String Filter
- Backward String Filter
- Center String Filter

### FORWARD STRING Filter
 `**` Is Used In Front Of String You Want To Filter. For Example `**String`. This Will Check If String After `**` Mathches With Any Value In DataBase. And It Will Ignore Front Portion Of String AS Shown In Code Below.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "Name": "**ard" })
#This Will Check If Name Ends With "ard" For Example: "Richard".
```
This Will Check In Database:
- if Name Ends With **"ard"**

### BACKWARD STRING Filter
 `**` Is Used In End Of String You Want To Filter. For Example `String**`. This Will Check If String Before `**` Mathches With Any Value In DataBase. And It Will Ignore Back Portion Of String AS Shown In Code Below.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "Name": "Ric**" })
#This Will Check If Name Starts With "Ric" For Example: "Richard".
```
This Will Check In Database:
- if Name Starts With **"Ric"**

### Output
```json
{"data": [{
       "un_id": "20202590449478829",
       "Name": "Richard",
       "Surname": "Stallman",
       "Tel-Number": 9876543000,
       "Age":40,
       "Subject":["UNIX","C","Perl"],
       "comments": [
                   { "user":"Marshal",
                     "message": "I Love C Language."},
                   { "user":"Della",
                    "message": "C Is A Fast Language"}
                   ],
       "cr_dc_path": "Blog_Database/Users/Richard.bin"
        }],
 "status": 1
}
```

### CENTER STRING Filter
 `**` Is Used In Front And Back Of String You Want To Filter. For Example `**String**`. This Will Check If String Mathches in Center With Any Value In DataBase.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "Name": "**ich**" })
#This Will Check If "ich" is in Name. For Example: "Richard".
```
This Will Check In Database:
- if **"ich"** In Name

## LIST Filter
 It Is Also Possible To Filter Data From List. As Shown Below:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "Subject": ["UNIX","Perl"] })
#This Will Check If "UNIX" And "Perl" Exist In Subject.
```
This Will Check In Database:
- if **"UNIX"** Exist In List Of Subject
- if **"Perl"** Exist In List Of Subject

If Both The Conditions Are True Then It Will Return Output.

## NESTED Filter
 It Is Also Possible To Filter Data From List. As Shown Below:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "comments": [
                   { "user":"Marshal"}
                       ] 
         })
         
#This Will Check If user "Marshal" exist in "comments".
```
This Will Check In Database:
- if user **"Marshal"** Exist In List Of comments

### Another Example Of NESTED Filter
In Nested Filters You Can Use Any Filter Like **GT**,**GET**,**LET** etc. In This Example We Will Cover Nested Filter With String Filter.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.filter({ "comments": [
                   { "message":"**Love**"}
                       ] 
         })
         
#This Will Check If "Love" Word In message.
```
This Will Check In Database:
- if message Is About **"Love"**
If The Conditions Is True Then It Will Return Output.
## Example: Use Of Multiple Filters Together
In This Example We Will Use "OR", "And","GT" and String Filters.
First Import **GT** and **OR** From pi7db
```python
from pi7db import pi7db, OR, GT
db = pi7db("Blog_Database")

db.filter(
          "Subject":["C"],
          OR,
          { "Surname":"Stall**", "Tel-Number":9876543210 },
          OR,
          { "Age":(GT,18) }
        )
```
This Will Check Following Conditions:
- If **C** In Subject List.
- OR Surname Is "Diamond" AND TEl-Number Is 9876543210.
- OR Age Is Greater Than 18.

If Only One Condition True Then It Will Return Output. Because We Use **OR** Operator In Filter.

# DELETE DATA
Various Options Are Avalible For Delete Data.
- Delete A Key From File. For Example (delete Surname From John File In Users Collection)
- Delete A Specific File. For Example (Delete John File From Users Collection)
- Delete Entire Collection. For Example (Delete Users)

### Delete A Key From File
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.trash('Users','John','Surname')
```
This Will Delete Surname From John File In Users Collection.
### Output:
```
{'success': 'Deleted! Surname Deleted From John!', 'status': 1}
```
### Delete A File From Collection
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.trash('Users','John')
```
This Will Delete John File From Users Collection.
### Output:
```
{'success': 'Deleted! Johan!', 'status': 1}
```
### Delete A Collection
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.trash('Users')
```
This Will Delete Entire Collection.
### Output:
```
{'success': 'Deleted! Collection Users Deleted Successfully!', 'status': 1}
```
 
 # DELETE BY FILTER
 Pi7db provide number of features. It is also possible to delete data by filter.
 Two arguments **where** and **dropkey** is used for delete data.

### Delete Data With Where Argument
 ```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.trash(where={"Name":"John"})
#This will delete all The files where Name is John.

# For Delete Only From Users Collection Use db.trash("Users",where={"Name":"John"})
```
### Output:
```
True
```
This will delete all The files where Name is John. This is one from advance features of pi7db.
 
 ### Delete Data With Where Argument Using Multiple Filters
 It is Also Possible To Delete Data With Multiple Filters As Shown Below
 ```python
from pi7db import pi7db,OR,GT
db = pi7db("Blog_Database")

db.trash("Users", where = [
                   {"Name":"**jo**","Surname":"Diamond"},
                   OR,
                   {"Age":(GT,50)}
                  ] 
        )
```
This Will Check Following Conditions:
- If **jo** In Name AND Surname Is "Diamond"
- OR Age Is Greater Than 50.
If These Two Conditions Are True Then It Will Be Removed From Database.

 ### Delete Data With "Where" And "Dropkey" Argument
 Delete a key with filter
 ```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.trash('Users', where={"Name":"John"}, dropkey='Tel-Number')
#This will delete all Tel-Number Keys From All files where Name is John.
```
### Output:
```
True
```
 This will delete all Tel-Number Keys From All files where Name is John.
 You Can Use Number Of Filters To Delete Data As Shown In Filter Data Funtion Below.
 > **NOTE:** NESTED KEY DELETE IS NOT SUPPORTED IN CURRENT VERSION OF pi7db. (comming soon).
 # UPDATE Data
 If You Want To Update Data Then Use Update Function. In Update Function If is Also Possible To Update By Filter.
 
### UPDATE Data In Specific File
It Takes Three Arguments Collection_Name , File_Name And Dict Data
For Example: ` db.update("Collection_name","File_Name",{"Data":"Data"}) `
As Shown Below:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.update('Users','John', {'Name': "Johnson",
                           "Surname":"Retchie",
                           "Father_name":"Sam"
                         })
```
### Output:
```
{'success': 'Success! Value Update in John!', 'status': 1}
```
 ### UPDATE Using Where Argument
It Takes Two Or Three Arguments Dict Data
For Example:
 - ` db.update("Collection_name",{"Data":"Data"}, where="Name":"John") ` #With Collection Name
 - ` db.update({"Data":"Data"}, where="Name":"John") `#Without Collection Name

Collection Name Is Recomended. It Will Increase Speed Of Update.

As Shown Below:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.update({"Father_name":"Sam Diamond"}, where={"Name":"John"})
#For Pass Multiple Argument In Where Use list
#for Example where = [ {"Name":"John"} ,OR, {"Surname":"**mnd"}]
```
It Will Update Father_name Key Where Name Is John. If Father_name Key Not Exist Then It Will Add Automatically where Name Is John.
### Output:
```
True
```

### UPDATE Data In All File
Sometime We Want To Update Data In All Files Present In Database.Then We Can Use `String Filter`.
As Shown Below:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

db.update({'Added_Date': "2020-05-21"},where={"Name":"**"})
```
This Will Update Data In All Files Where Name Key Is Present.
### Output:
```
{'success': 'Success! Value Update in John!', 'status': 1}
```

 ### UPDATE Data With INCREMENT Function
 **INCREMENT** Function Provide Help In Update Data With Less Efforts For Example If You Want To Update Age of John then `{"Age":increment(2)}`. This Will Increment John's Age By 2 For example 40 + 2 = 42.
 Increment Function Take Single Int Argement For example 9. or any other Integer.
 Example:
 > Note : You Have To Import increment Function From pi7db
 ```python
from pi7db import pi7db,increment
db = pi7db("Blog_Database")

#Using Where Argument
db.update({"Age":increment(5)}, where={"Name":"John"})
#For Pass Multiple Argument In Where Use list
#for Example (Using OR operator):- where = [ {"Name":"John"} ,OR, {"Surname":"**mnd"}]

#OR IN A SPECIFIC FILE
db.update("Users","John", {"Age":increment(5)})
```
 It Will Increment John's Age By 5
 ### Output
```
True
```
 ### UPDATE Data With decrement Function
 **DECREMENT** Function Is Opposite To Increment Function It Help In Decrement In Value. For Example:- `{"Age":decrement(3)}`. This Will Decrement John's Age By 3 For example 40 - 3 = 39.
 Decrement Function Take Single Int Argement For example 5. or any other Integer.
 Example:
 > Note : You Have To Import decrement Function From pi7db
 ```python
from pi7db import pi7db,decrement
db = pi7db("Blog_Database")

# UPDATE IN A SPECIFIC FILE
db.update("Users","John", {"Age":decrement(2)})

#OR USING WHERE ARGUMENT
db.update({"Age":decrement(2)}, where={"Name":"John"})
#For Pass Multiple Argument In Where Use list
#for Example (Using OR operator):- where = [ {"Name":"John"} ,OR, {"Surname":"**mnd"}]
```
 It Will Decrement John's Age By 2
 ### Output
```
True
```
 > **NOTE:** NESTED UPDATE IS NOT SUPPORTED IN CURRENT VERSION OF pi7db. (comming soon).
 
 # SORT Data
 For Get Sorted Data Use **sort** Function. Sort Function Take one Argument Of Data Type **set**. For Example: `db.sort({"Name"})`
 By Default Data Is In Ascending Order For Set Manually:
 - For Sort Data In Ascending Order Use `db.sort({"Name"}, order=asc)`
 - For Sort Data In Descending Order Use `db.sort({"Name"}, order=dsc)`
> **NOTE:** Import **asc** and **dsc** For Use Order.
 ```python
from pi7db import pi7db, asc, dsc
db = pi7db("Blog_Database")

# By Default Order Is Ascending
db.update({"Name"})

#For Descending Order Use
db.update({"Name"},order=dsc)
```

 
 ### SORT Data In Nested Dict
 > **Note:** Data Sortion Work Only With Nested Dict Not With list. 
 For Example We Have Data In Database In This Order:
 ```json
   {
    "User":{
            "Name":"Richard",
            "Subject":{"Science":"Chemistry","Computer":"CSE"},
            "Teacher":{"Science":"Fury","Computer":"James"},
            }
   }
 ```
 ##### How To Sort This Nested Data ?
 - For Sort By Name In This Data We Will Pass Argument Like `db.sort({"User","Name"})`
 - For Sort By Specific Subject In This Data We Will Pass Argument Like `db.sort({"User","Subject","Science"})`
 - For Sort By Specific Teacher Name We Will Pass Argument Like `db.sort({"User","Teacher","Science"})`
 
 You Can Also Pass Collection_Name Before Dict. Collection Name Is Recommended.
 For Sort In Specific Collection We Will Pass Argument Of Collection Name For Example: `db.sort("Users",{"User","Subject","Science"})`
 
 ### SORT Filtered Data
 There Is A Function `db.sortdict` In pi7db Which Is Used To Sort Filtered Data. In Other Hand `db.sort` Function Is Used To Sort All Data.for Example:
  ```python
from pi7db import pi7db,dsc
db = pi7db("Blog_Database")

filtered_data = db.filter({"Name":"**"})
db.sortdict(filtered_data,{"Surname"},order=dsc)
```
### output
```json
 {"data": 
   [{ 
    "un_id": "20202590449478829",
    "Name": "Richard",
    "Surname": "Stallman",
    "Tel-Number": 9876543000,
    "Age":40,
    "Subject":["UNIX","C","Perl"],
    "comments": [
                   { "user":"Marshal",
                     "message": "I Love C Language."},
                   { "user":"Della",
                    "message": "C Is A Fast Language"}
                   ],
    "cr_dc_path": "Blog_Database/Users/Richard.bin"
   },
   { 
    "un_id": "20202660459428127",
    "Name": "John",
    "Surname": "Diamond",
    "Tel-Number": 9876543210,
    "Age":30,
    "Subject":["Python","Ruby","Perl"],
    "comments": [
                   { "user":"Stephin",
                     "message": "John Is Best!"},
                   { "user":"Alex",
                    "message": "We Love You John!"}
                ],
    "cr_dc_path": "Blog_Database/Users/John.bin"
   }], 
  "status": 1
 }
```

# Some Other Advance Arguments:
There Are Some Other Arguments Help In Speed Of Data Read, Ignore Files, Read Data From Specific Part.
List Of Arguments:
- `FROM` (Starting Point File Number)
- `TO` (End Point Of File Number)
- `FIRST` (Read Number Of Files From Start)
- `LAST` (Read Number Of Files From Last)
- `IGNORE` (Ignore Specific File)

### `FROM` Argument
Suppose You Have 1000 Number Of Files In Database. But You Want To Ignore First 10 Files And Read Other 990 Files Then `FROM` Argument Can Help You.
For Example:
> **NOTE:** Write `FROM` In **Capital Words**
```python
from pi7db import pi7db
db = pi7db("Blog_Database")
db.read(FROM=10)
```

### `TO` Argument
Suppose You Have 1000 Files In Database. But You Want To Read From 10 To 50 Files. For Example:
> **NOTE:** Write `TO` In **Capital Words**.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")
db.read(FROM=10,TO=50)
```

### `FIRST` Argument
Suppose You Have 1000 Files In Database. But You Want To Read Only First 10 Files.For Example:
> **NOTE:** Write `FIRST` In **Capital Words**.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")
db.read(FIRST=10)
```
This Will Read And Return First 10 Files.

### `LAST` Argument
Suppose You Have 1000 Files In Database. But You Want To Read Only Last 10 Files.For Example:
> **NOTE:** Write `LAST` In **Capital Words**.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")
db.read(LAST=10)
```
This Will Read And Return LAST 10 Files.

### `IGNORE` Argument
Suppose You Want To Ignore A File During Read, Sort Or Filter Time Then Use Ignore Argumen.For Example:
> **NOTE:** Write `IGNORE` In **Capital Words**.
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

#IGNORE SINGLE FILE
db.read(IGNORE="John")

#IGNORE MULTIPLE FILES USING LIST
db.read( IGNORE= ["John","Richard"] )

```
`IGNORE = "John"` # This Will Ignore Only John File
`IGNORE = ["John","Richard"]` # This Will Ignore All Files In List

#### You Can Use These Arguments With `sort` , `filter` and `read` Functions
For Example:
```python
from pi7db import pi7db
db = pi7db("Blog_Database")

#With READ
db.read(IGNORE="John")

#With SORT
db.sort({"Name"},FROM=1,TO=10)

#With FILTER
db.filter({"Name":"J**"},FIRST=50)


```
`MORE FEATURES COMMING SOON, THANKYOU.`



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shivjeetbhullar/pi7db",
    "name": "pi7db",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Shivjeet Singh Bhullar",
    "author_email": "bhullarshivjeet@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# Pi7db.\nPi7db is a open-source powerful python package to manage directory based database in JSON format with number of features like Filter, sort, update etc.\n\n# WHY I USE Pi7db ?\nThere are some reasons may you like.\n- NOSQL\n- Flexible Data\n- No Need To Make Connection To Database. (Most Hated Stuff)\n- Simple And Super Fast.\n- Directory Based Databse (Place Where You Want).\n- Advance Filter Options Like (Less Than, Greater Than, String Filter, List Filter etc).\n- Read, Write, Sort, Update, Trash, Filter Data With Advance Features.\n- Encrypt Data With Password.\n\n# DATABASE STRUCTURE\nData is stored in binary files inside collections. Database structure is similar to mongodb.\n![image](https://drive.google.com/uc?export=view&id=1BXxi6mfcQ11mnBpSot96TvczC5LpgYa3 \"Pi7db Structure\")\n\n## File Structure\n```json\n{\n   \"un_id\": 20202171823558180,\n   \"title\": \"This Is File\", \n   \"description\": \"This file strore information.\",\n   \"tags\": [\"pi7db\", \"database\", \"NoSQL\"],\n   \"views\": 10,\n   \"cr_dc_path\":\"Blog_Database/Collection_name/FileName.bin\",\n   \"comments\": [\t\n      {\n         \"user\":\"john\",\n         \"message\": \"My Name is Jonh\"\n      }\n   ]\n}\n```\nThere is un_id and cr_dc_path is avalible in every file by default represent a uniqe key for file and file path in system \n\n# INSTALLATION\nInstallation with pip\n```sh\n $ pip3 install pi7db \n ```\n# Getting Started\nFirst import pi7db package in python file and create a object by passing argument Database name. It will automatically create a directory in current folder with that name where all datafiles will be stored.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n```\n### Manual Database path\nif you want to store database in a specific directory then pass second argument of path. \n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\",\"path/to/dir\")\n```\n# Write Data\nWrite function is used for write Json data.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndata = {\n       \"Name\":\"John\",\n       \"Surname\":\"Diamond\",\n       \"Tel-Number\":9876543210,\n       \"Age\":30,\n       \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n       \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                   ]\n       }\n       \ndb.write('Users',data)\n# This Will Write Data In Users Collection.\n```\n### Write Data In Specific File Manually. \n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndata = {\n       \"Name\":\"John\",\n       \"Surname\":\"Diamond\",\n       \"Tel-Number\":9876543210,\n       \"Age\":30,\n       \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n       \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                   ]\n       }\n       \ndata2 = {\n       \"Name\":\"Richard\",\n       \"Surname\":\"Stallman\",\n       \"Tel-Number\":9876543000,\n       \"Age\":40,\n       \"Subject\":[\"UNIX\",\"C\",\"Perl\"],\n       \"comments\": [\n                   { \"user\":\"Marshal\",\n                     \"message\": \"I Love C Language.\"},\n                   { \"user\":\"Della\",\n                    \"message\": \"C Is A Fast Language\"}\n                   ]\n       }\n       \ndb.write('Users' , 'John' , data)\n\ndb.write('Users' , 'Richard' , data2)\n# This Will Write Data In john (filename john) file inside Users Collection.\n```\nFollowing Directory Tree Will Be Created In Your PC.\n![image](https://drive.google.com/uc?export=view&id=1xoXs59TFbm-9cDZPlrupMEmzQkqJy-TM \"Pi7db Structure\")\nYou can directly call file during read time this will increase speed of your program.\nFor Example: You Can Call Specific Blog Post By Its Name. \n\n# Read Data\nData read is pretty easy and fast in pi7db. With the help of read function.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.read()\n\n# This Will Read Entire Data In Database And Return Output In Dict.\n# But Read Entire Data Is Not Recomended When Your Database Size Is Large For Example 500mb.\n```\n\n# Read Data From Collection\nData read is pretty easy and fast in pi7db. With the help of read function.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.read('Users')\n\n# This Will Read Entire Data In Users Collection And Return Output In Dict.\n```\n#### Output:\n```json\n {\"data\": \n   [\n   { \n    \"un_id\": \"20202660459428127\",\n    \"Name\": \"John\",\n    \"Surname\": \"Diamond\",\n    \"Tel-Number\": 9876543210,\n    \"Age\":30,\n    \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n    \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                ],\n    \"cr_dc_path\": \"Blog_Database/Users/John.bin\"\n   },\n   { \n    \"un_id\": \"20202590449478829\",\n    \"Name\": \"Richard\",\n    \"Surname\": \"Stallman\",\n    \"Tel-Number\": 9876543000,\n    \"Age\":40,\n    \"Subject\":[\"UNIX\",\"C\",\"Perl\"],\n    \"comments\": [\n                   { \"user\":\"Marshal\",\n                     \"message\": \"I Love C Language.\"},\n                   { \"user\":\"Della\",\n                    \"message\": \"C Is A Fast Language\"}\n                   ],\n    \"cr_dc_path\": \"Blog_Database/Users/Richard.bin\"\n   }\n   ], \n  \"status\": 1\n }\n```\nIn output status:\n - 1 = Sucess\n - 0 = Error\n\n# Read Data From File\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.read('Users','John')\n\n# This Will Read Entire Data In Users Collection And Return Output In Dict.\n```\n#### Output:\n```json\n {\"data\": \n   [{ \n    \"unid\": \"20202660459428127\",\n    \"Name\": \"John\",\n    \"Surname\": \"Diamond\",\n    \"Tel-Number\": 9876543210,\n    \"Age\":30,\n    \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n    \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                   ],\n    \"cr_dc_path\": \"Blog_Database/Users/John.bin\"\n   }], \n  \"status\": 1\n }\n```\n# Read Data From File By KeyName\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.read('Users','John','Surname')\n\n# This Will Read Entire Data In Users Collection And Return Output In Dict.\n```\n#### Output:\n```\n Diamond\n```\n\n# FILTER DATA\n Filter Is Most Powerfull Funtion Of This Package. You Can Filter Data According To Your Choice There Are Many Number Of Features Avalible In Filter Function. In Filter Function It Is Possible To Filter Data From Nested Dict Or List Of Dicts As The Way You Want. Filter Makes This Database More Flexible And Powefull.\n Some Features Are Shown Below:\n - Operators (Used For Filter Data)\n   - OR\n   - AND \n   - LT (Less Than)\n   - GT (Greater Than)\n   - GET (Greater And Equal Than)\n   - LET (Less And Equal Than)\n - String Filter (User To Filter Data According To String)\n   - Forward String Filter\n   - Backward String Filter\n   - Center String Filter\n - List Filter (Filter Data From List)\n - Nested Filter (Filter Data From Nested Dict)\n \n ### Simple Filter\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({\"Name\":\"John\"})\n#This will filter all data where name is John and return output.\n```\n### Output\n```json\n{\"data\": [{\n       \"unid\": \"20203953408762519\", \n       \"Name\": \"John\", \n       \"Surname\": \"Diamond\", \n       \"Tel-Number\": 9876543210, \n       \"Age\":30,\n       \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n       \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                   ],\n       \"cr_dc_path\": \"Blog_Database/Users/John.bin\"\n        }],\n \"status\": 1\n}\n```\n ### AND Filter\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({\"Name\":\"John\",\"Surname\":\"Diamond\",\"Tel-Number\":9876543210})\n```\nThis Will Check In Database:\n- if Name is John\n- and Surname is Diamond\n- and Tel-Number is 9876543210\n\nIf All These Conditions are True Then Return Output Otherwise Return Nothing.\n\n### OR Filter\n> **Note:** Before Using \"OR\" Operator You Have To Import It.\n```python\nfrom pi7db import pi7db, OR\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({\"Name\":\"John\"}, OR ,{\"Surname\":\"Diamond\",\"Tel-Number\":9876543210})\n```\nThis Will Check In Database:\n- if Name is John\n- OR Surname is Diamond and Tel-Number is 9876543210\n\nIf All These Conditions are True Then Return Output Otherwise Return Nothing.\n\n### GT (GREATER THAN) Filter\n> **Note:** Befor Using \"GT\" Operator You Have To Import It.\n```python\nfrom pi7db import pi7db, GT\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Age\": (GT,19) })\n```\nThis Will Check In Database:\n- if Age Greater Than 19\n\nIf This Condition is True Then Return Output Otherwise Return Nothing.\n\n### LT (LESS THAN) Filter\n> **Note:** Before Using \"LT\" Operator You Have To Import It.\n```python\nfrom pi7db import pi7db, LT\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Age\": (LT,39) })\n```\nThis Will Check In Database:\n- if Age Less Than 39\n\n### LET (Less and Equal THAN) And GET (Greater and Equal Than) Filter\nUse Of These Filters Are Similarly To **GT** And **LT** Operators. For Example\n> **Note:** Before Using Operator You Have To Import It.\n```python\nfrom pi7db import pi7db, GET,LET\ndb = pi7db(\"Blog_Database\")\n\n#LET FILTER (Less and Equal THAN) \ndb.filter({ \"Age\": (LET,40) })\n\n#GET FILTER (Greater and Equal Than)\ndb.filter({ \"Age\": (GET,40) })\n```\nIf This Condition is True Then Return Output Otherwise Return Nothing.\n## STRING Filters\nThere Are Number Of String Filters are Avalible In pi7db.\n- Forward String Filter\n- Backward String Filter\n- Center String Filter\n\n### FORWARD STRING Filter\n `**` Is Used In Front Of String You Want To Filter. For Example `**String`. This Will Check If String After `**` Mathches With Any Value In DataBase. And It Will Ignore Front Portion Of String AS Shown In Code Below.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Name\": \"**ard\" })\n#This Will Check If Name Ends With \"ard\" For Example: \"Richard\".\n```\nThis Will Check In Database:\n- if Name Ends With **\"ard\"**\n\n### BACKWARD STRING Filter\n `**` Is Used In End Of String You Want To Filter. For Example `String**`. This Will Check If String Before `**` Mathches With Any Value In DataBase. And It Will Ignore Back Portion Of String AS Shown In Code Below.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Name\": \"Ric**\" })\n#This Will Check If Name Starts With \"Ric\" For Example: \"Richard\".\n```\nThis Will Check In Database:\n- if Name Starts With **\"Ric\"**\n\n### Output\n```json\n{\"data\": [{\n       \"un_id\": \"20202590449478829\",\n       \"Name\": \"Richard\",\n       \"Surname\": \"Stallman\",\n       \"Tel-Number\": 9876543000,\n       \"Age\":40,\n       \"Subject\":[\"UNIX\",\"C\",\"Perl\"],\n       \"comments\": [\n                   { \"user\":\"Marshal\",\n                     \"message\": \"I Love C Language.\"},\n                   { \"user\":\"Della\",\n                    \"message\": \"C Is A Fast Language\"}\n                   ],\n       \"cr_dc_path\": \"Blog_Database/Users/Richard.bin\"\n        }],\n \"status\": 1\n}\n```\n\n### CENTER STRING Filter\n `**` Is Used In Front And Back Of String You Want To Filter. For Example `**String**`. This Will Check If String Mathches in Center With Any Value In DataBase.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Name\": \"**ich**\" })\n#This Will Check If \"ich\" is in Name. For Example: \"Richard\".\n```\nThis Will Check In Database:\n- if **\"ich\"** In Name\n\n## LIST Filter\n It Is Also Possible To Filter Data From List. As Shown Below:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"Subject\": [\"UNIX\",\"Perl\"] })\n#This Will Check If \"UNIX\" And \"Perl\" Exist In Subject.\n```\nThis Will Check In Database:\n- if **\"UNIX\"** Exist In List Of Subject\n- if **\"Perl\"** Exist In List Of Subject\n\nIf Both The Conditions Are True Then It Will Return Output.\n\n## NESTED Filter\n It Is Also Possible To Filter Data From List. As Shown Below:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"comments\": [\n                   { \"user\":\"Marshal\"}\n                       ] \n         })\n         \n#This Will Check If user \"Marshal\" exist in \"comments\".\n```\nThis Will Check In Database:\n- if user **\"Marshal\"** Exist In List Of comments\n\n### Another Example Of NESTED Filter\nIn Nested Filters You Can Use Any Filter Like **GT**,**GET**,**LET** etc. In This Example We Will Cover Nested Filter With String Filter.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.filter({ \"comments\": [\n                   { \"message\":\"**Love**\"}\n                       ] \n         })\n         \n#This Will Check If \"Love\" Word In message.\n```\nThis Will Check In Database:\n- if message Is About **\"Love\"**\nIf The Conditions Is True Then It Will Return Output.\n## Example: Use Of Multiple Filters Together\nIn This Example We Will Use \"OR\", \"And\",\"GT\" and String Filters.\nFirst Import **GT** and **OR** From pi7db\n```python\nfrom pi7db import pi7db, OR, GT\ndb = pi7db(\"Blog_Database\")\n\ndb.filter(\n          \"Subject\":[\"C\"],\n          OR,\n          { \"Surname\":\"Stall**\", \"Tel-Number\":9876543210 },\n          OR,\n          { \"Age\":(GT,18) }\n        )\n```\nThis Will Check Following Conditions:\n- If **C** In Subject List.\n- OR Surname Is \"Diamond\" AND TEl-Number Is 9876543210.\n- OR Age Is Greater Than 18.\n\nIf Only One Condition True Then It Will Return Output. Because We Use **OR** Operator In Filter.\n\n# DELETE DATA\nVarious Options Are Avalible For Delete Data.\n- Delete A Key From File. For Example (delete Surname From John File In Users Collection)\n- Delete A Specific File. For Example (Delete John File From Users Collection)\n- Delete Entire Collection. For Example (Delete Users)\n\n### Delete A Key From File\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.trash('Users','John','Surname')\n```\nThis Will Delete Surname From John File In Users Collection.\n### Output:\n```\n{'success': 'Deleted! Surname Deleted From John!', 'status': 1}\n```\n### Delete A File From Collection\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.trash('Users','John')\n```\nThis Will Delete John File From Users Collection.\n### Output:\n```\n{'success': 'Deleted! Johan!', 'status': 1}\n```\n### Delete A Collection\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.trash('Users')\n```\nThis Will Delete Entire Collection.\n### Output:\n```\n{'success': 'Deleted! Collection Users Deleted Successfully!', 'status': 1}\n```\n \n # DELETE BY FILTER\n Pi7db provide number of features. It is also possible to delete data by filter.\n Two arguments **where** and **dropkey** is used for delete data.\n\n### Delete Data With Where Argument\n ```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.trash(where={\"Name\":\"John\"})\n#This will delete all The files where Name is John.\n\n# For Delete Only From Users Collection Use db.trash(\"Users\",where={\"Name\":\"John\"})\n```\n### Output:\n```\nTrue\n```\nThis will delete all The files where Name is John. This is one from advance features of pi7db.\n \n ### Delete Data With Where Argument Using Multiple Filters\n It is Also Possible To Delete Data With Multiple Filters As Shown Below\n ```python\nfrom pi7db import pi7db,OR,GT\ndb = pi7db(\"Blog_Database\")\n\ndb.trash(\"Users\", where = [\n                   {\"Name\":\"**jo**\",\"Surname\":\"Diamond\"},\n                   OR,\n                   {\"Age\":(GT,50)}\n                  ] \n        )\n```\nThis Will Check Following Conditions:\n- If **jo** In Name AND Surname Is \"Diamond\"\n- OR Age Is Greater Than 50.\nIf These Two Conditions Are True Then It Will Be Removed From Database.\n\n ### Delete Data With \"Where\" And \"Dropkey\" Argument\n Delete a key with filter\n ```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.trash('Users', where={\"Name\":\"John\"}, dropkey='Tel-Number')\n#This will delete all Tel-Number Keys From All files where Name is John.\n```\n### Output:\n```\nTrue\n```\n This will delete all Tel-Number Keys From All files where Name is John.\n You Can Use Number Of Filters To Delete Data As Shown In Filter Data Funtion Below.\n > **NOTE:** NESTED KEY DELETE IS NOT SUPPORTED IN CURRENT VERSION OF pi7db. (comming soon).\n # UPDATE Data\n If You Want To Update Data Then Use Update Function. In Update Function If is Also Possible To Update By Filter.\n \n### UPDATE Data In Specific File\nIt Takes Three Arguments Collection_Name , File_Name And Dict Data\nFor Example: ` db.update(\"Collection_name\",\"File_Name\",{\"Data\":\"Data\"}) `\nAs Shown Below:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.update('Users','John', {'Name': \"Johnson\",\n                           \"Surname\":\"Retchie\",\n                           \"Father_name\":\"Sam\"\n                         })\n```\n### Output:\n```\n{'success': 'Success! Value Update in John!', 'status': 1}\n```\n ### UPDATE Using Where Argument\nIt Takes Two Or Three Arguments Dict Data\nFor Example:\n - ` db.update(\"Collection_name\",{\"Data\":\"Data\"}, where=\"Name\":\"John\") ` #With Collection Name\n - ` db.update({\"Data\":\"Data\"}, where=\"Name\":\"John\") `#Without Collection Name\n\nCollection Name Is Recomended. It Will Increase Speed Of Update.\n\nAs Shown Below:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.update({\"Father_name\":\"Sam Diamond\"}, where={\"Name\":\"John\"})\n#For Pass Multiple Argument In Where Use list\n#for Example where = [ {\"Name\":\"John\"} ,OR, {\"Surname\":\"**mnd\"}]\n```\nIt Will Update Father_name Key Where Name Is John. If Father_name Key Not Exist Then It Will Add Automatically where Name Is John.\n### Output:\n```\nTrue\n```\n\n### UPDATE Data In All File\nSometime We Want To Update Data In All Files Present In Database.Then We Can Use `String Filter`.\nAs Shown Below:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\ndb.update({'Added_Date': \"2020-05-21\"},where={\"Name\":\"**\"})\n```\nThis Will Update Data In All Files Where Name Key Is Present.\n### Output:\n```\n{'success': 'Success! Value Update in John!', 'status': 1}\n```\n\n ### UPDATE Data With INCREMENT Function\n **INCREMENT** Function Provide Help In Update Data With Less Efforts For Example If You Want To Update Age of John then `{\"Age\":increment(2)}`. This Will Increment John's Age By 2 For example 40 + 2 = 42.\n Increment Function Take Single Int Argement For example 9. or any other Integer.\n Example:\n > Note : You Have To Import increment Function From pi7db\n ```python\nfrom pi7db import pi7db,increment\ndb = pi7db(\"Blog_Database\")\n\n#Using Where Argument\ndb.update({\"Age\":increment(5)}, where={\"Name\":\"John\"})\n#For Pass Multiple Argument In Where Use list\n#for Example (Using OR operator):- where = [ {\"Name\":\"John\"} ,OR, {\"Surname\":\"**mnd\"}]\n\n#OR IN A SPECIFIC FILE\ndb.update(\"Users\",\"John\", {\"Age\":increment(5)})\n```\n It Will Increment John's Age By 5\n ### Output\n```\nTrue\n```\n ### UPDATE Data With decrement Function\n **DECREMENT** Function Is Opposite To Increment Function It Help In Decrement In Value. For Example:- `{\"Age\":decrement(3)}`. This Will Decrement John's Age By 3 For example 40 - 3 = 39.\n Decrement Function Take Single Int Argement For example 5. or any other Integer.\n Example:\n > Note : You Have To Import decrement Function From pi7db\n ```python\nfrom pi7db import pi7db,decrement\ndb = pi7db(\"Blog_Database\")\n\n# UPDATE IN A SPECIFIC FILE\ndb.update(\"Users\",\"John\", {\"Age\":decrement(2)})\n\n#OR USING WHERE ARGUMENT\ndb.update({\"Age\":decrement(2)}, where={\"Name\":\"John\"})\n#For Pass Multiple Argument In Where Use list\n#for Example (Using OR operator):- where = [ {\"Name\":\"John\"} ,OR, {\"Surname\":\"**mnd\"}]\n```\n It Will Decrement John's Age By 2\n ### Output\n```\nTrue\n```\n > **NOTE:** NESTED UPDATE IS NOT SUPPORTED IN CURRENT VERSION OF pi7db. (comming soon).\n \n # SORT Data\n For Get Sorted Data Use **sort** Function. Sort Function Take one Argument Of Data Type **set**. For Example: `db.sort({\"Name\"})`\n By Default Data Is In Ascending Order For Set Manually:\n - For Sort Data In Ascending Order Use `db.sort({\"Name\"}, order=asc)`\n - For Sort Data In Descending Order Use `db.sort({\"Name\"}, order=dsc)`\n> **NOTE:** Import **asc** and **dsc** For Use Order.\n ```python\nfrom pi7db import pi7db, asc, dsc\ndb = pi7db(\"Blog_Database\")\n\n# By Default Order Is Ascending\ndb.update({\"Name\"})\n\n#For Descending Order Use\ndb.update({\"Name\"},order=dsc)\n```\n\n \n ### SORT Data In Nested Dict\n > **Note:** Data Sortion Work Only With Nested Dict Not With list. \n For Example We Have Data In Database In This Order:\n ```json\n   {\n    \"User\":{\n            \"Name\":\"Richard\",\n            \"Subject\":{\"Science\":\"Chemistry\",\"Computer\":\"CSE\"},\n            \"Teacher\":{\"Science\":\"Fury\",\"Computer\":\"James\"},\n            }\n   }\n ```\n ##### How To Sort This Nested Data ?\n - For Sort By Name In This Data We Will Pass Argument Like `db.sort({\"User\",\"Name\"})`\n - For Sort By Specific Subject In This Data We Will Pass Argument Like `db.sort({\"User\",\"Subject\",\"Science\"})`\n - For Sort By Specific Teacher Name We Will Pass Argument Like `db.sort({\"User\",\"Teacher\",\"Science\"})`\n \n You Can Also Pass Collection_Name Before Dict. Collection Name Is Recommended.\n For Sort In Specific Collection We Will Pass Argument Of Collection Name For Example: `db.sort(\"Users\",{\"User\",\"Subject\",\"Science\"})`\n \n ### SORT Filtered Data\n There Is A Function `db.sortdict` In pi7db Which Is Used To Sort Filtered Data. In Other Hand `db.sort` Function Is Used To Sort All Data.for Example:\n  ```python\nfrom pi7db import pi7db,dsc\ndb = pi7db(\"Blog_Database\")\n\nfiltered_data = db.filter({\"Name\":\"**\"})\ndb.sortdict(filtered_data,{\"Surname\"},order=dsc)\n```\n### output\n```json\n {\"data\": \n   [{ \n    \"un_id\": \"20202590449478829\",\n    \"Name\": \"Richard\",\n    \"Surname\": \"Stallman\",\n    \"Tel-Number\": 9876543000,\n    \"Age\":40,\n    \"Subject\":[\"UNIX\",\"C\",\"Perl\"],\n    \"comments\": [\n                   { \"user\":\"Marshal\",\n                     \"message\": \"I Love C Language.\"},\n                   { \"user\":\"Della\",\n                    \"message\": \"C Is A Fast Language\"}\n                   ],\n    \"cr_dc_path\": \"Blog_Database/Users/Richard.bin\"\n   },\n   { \n    \"un_id\": \"20202660459428127\",\n    \"Name\": \"John\",\n    \"Surname\": \"Diamond\",\n    \"Tel-Number\": 9876543210,\n    \"Age\":30,\n    \"Subject\":[\"Python\",\"Ruby\",\"Perl\"],\n    \"comments\": [\n                   { \"user\":\"Stephin\",\n                     \"message\": \"John Is Best!\"},\n                   { \"user\":\"Alex\",\n                    \"message\": \"We Love You John!\"}\n                ],\n    \"cr_dc_path\": \"Blog_Database/Users/John.bin\"\n   }], \n  \"status\": 1\n }\n```\n\n# Some Other Advance Arguments:\nThere Are Some Other Arguments Help In Speed Of Data Read, Ignore Files, Read Data From Specific Part.\nList Of Arguments:\n- `FROM` (Starting Point File Number)\n- `TO` (End Point Of File Number)\n- `FIRST` (Read Number Of Files From Start)\n- `LAST` (Read Number Of Files From Last)\n- `IGNORE` (Ignore Specific File)\n\n### `FROM` Argument\nSuppose You Have 1000 Number Of Files In Database. But You Want To Ignore First 10 Files And Read Other 990 Files Then `FROM` Argument Can Help You.\nFor Example:\n> **NOTE:** Write `FROM` In **Capital Words**\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\ndb.read(FROM=10)\n```\n\n### `TO` Argument\nSuppose You Have 1000 Files In Database. But You Want To Read From 10 To 50 Files. For Example:\n> **NOTE:** Write `TO` In **Capital Words**.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\ndb.read(FROM=10,TO=50)\n```\n\n### `FIRST` Argument\nSuppose You Have 1000 Files In Database. But You Want To Read Only First 10 Files.For Example:\n> **NOTE:** Write `FIRST` In **Capital Words**.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\ndb.read(FIRST=10)\n```\nThis Will Read And Return First 10 Files.\n\n### `LAST` Argument\nSuppose You Have 1000 Files In Database. But You Want To Read Only Last 10 Files.For Example:\n> **NOTE:** Write `LAST` In **Capital Words**.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\ndb.read(LAST=10)\n```\nThis Will Read And Return LAST 10 Files.\n\n### `IGNORE` Argument\nSuppose You Want To Ignore A File During Read, Sort Or Filter Time Then Use Ignore Argumen.For Example:\n> **NOTE:** Write `IGNORE` In **Capital Words**.\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\n#IGNORE SINGLE FILE\ndb.read(IGNORE=\"John\")\n\n#IGNORE MULTIPLE FILES USING LIST\ndb.read( IGNORE= [\"John\",\"Richard\"] )\n\n```\n`IGNORE = \"John\"` # This Will Ignore Only John File\n`IGNORE = [\"John\",\"Richard\"]` # This Will Ignore All Files In List\n\n#### You Can Use These Arguments With `sort` , `filter` and `read` Functions\nFor Example:\n```python\nfrom pi7db import pi7db\ndb = pi7db(\"Blog_Database\")\n\n#With READ\ndb.read(IGNORE=\"John\")\n\n#With SORT\ndb.sort({\"Name\"},FROM=1,TO=10)\n\n#With FILTER\ndb.filter({\"Name\":\"J**\"},FIRST=50)\n\n\n```\n`MORE FEATURES COMMING SOON, THANKYOU.`\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "pi7db Is A Fast And Powerfull Directory Based Database Built In Python3.",
    "version": "2.1",
    "project_urls": {
        "Homepage": "https://github.com/shivjeetbhullar/pi7db"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47922dd90397d8e8252ebd9d0af242b2506ef7cc7b2c8c5548cae4037246bbbc",
                "md5": "ccb5400793e0d99efabe8f9b31b3f52b",
                "sha256": "df97d3c098d30fe54ec1ee82384d0c8aee2cba5dad707d92f406fba45c4b25ba"
            },
            "downloads": -1,
            "filename": "pi7db-2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ccb5400793e0d99efabe8f9b31b3f52b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 28386,
            "upload_time": "2023-06-07T05:22:51",
            "upload_time_iso_8601": "2023-06-07T05:22:51.613562Z",
            "url": "https://files.pythonhosted.org/packages/47/92/2dd90397d8e8252ebd9d0af242b2506ef7cc7b2c8c5548cae4037246bbbc/pi7db-2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-07 05:22:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "shivjeetbhullar",
    "github_project": "pi7db",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pi7db"
}
        
Elapsed time: 0.07214s