Skip to content

NeuralGen/PyDataman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android or Windows     Made with Python


Are you having problem keeping variables outside of your python program or writting and managing codes for your cloud database? 🥵

Don't destroy your pc or damage your head ❌.

Try PyDataman 👷‍♂️, he will do all the hard works on your behalf!!





What is PyDataman?

Basically this module is for saving data specially variables including other data like images or text files outside your code so that you never ever lose them.
Let's say you've created a game with pygame. There is a high score system and you want to save the highest score in an online database so that users all over the world can see the highest score. Here comes the usage of PyDataman. Yes you can also do it without PyDataman, but you've to write more to do so.
Again, let's say you don't want a variable to be reset everytime you run your code, here you must use PyVariable. Using PyDataman, you can save a variable in your drive (offline) or in an online database. It's really simple enough.

One more feature, you can save any of your files in an online databse and download from any device whenever and wherever you need them.

Note: You can save and read variables of any data type even lists, tuples, sets and dictionaries. All of them is supported.





Installation

Installing the module is quite easy ;)
Simple open your terminal and enter pip install pydataman.

Note: If you are having any problem with the installation, feel free to contact me in Gmail and in facebook





Variable in Folder


Save your variables outside your code so that whenever you restart your code, you won't lose them. Here's how to do it -

Simply import the module. Call the save(var_name, value) method with the name and the value of a variable as argument to store your data locally and call read(var_name) to read the value. The value will already be in your desired data type, no need to covert again.

Also, call exists() method with name of a variable as argument to check if the variable exists.
Note: It will return True or False.



Here is a sample code -

import pydataman

pydataman.save("Name", "John")  # This will store the variable Name with the value John
LocalName = pydataman.read("Name")  # This will read the value of Name from files and store in LocalName
print(LocalName)  # This will print John

Another example of checking if a variable exists -

import pydataman

if pydataman.exists("X"):  # The method returns true if the variable exists in your folder
      print("The variable X exists")
else:
      print("The variable X doesn't exist")





Variable in online database


Store your variables online so that everytime you restart your code, you don't lose the values. Even you can create a variable from a device and access it's value from another. Here's how to do these -

Setting up your database:

Step 1:   Go to https://console.firebase.google.com/
Step 2:   Login with your google account.
Step 3:   Click on Add Project
Step 4:   Enter any name (The name doesn't matter at all).
Step 5:   Disable Google Analytics and click on continue.
Step 6:   After the the database creation is finished, click on continue.
Step 7:   Click on Realtime Database on the left.
Step 8:   Click on Create Database and select your nearest location.
Step 9:   After clicking Next, Select Start in test mode and click on Enable
Step 10:   Go to Rules tab and replace the code by this -
{
  "rules": {
    ".read": "true",
    ".write": "true",
  }
}
Step 11:   Finally, come back to Data tab and just copy this url shown in the image.

Step 10

Step 12:   Now go to your code and import the module pydataman.
Step 13:   After that create an object of the class CloudVariable with the url you copied as argument.

Everything is now ready. Simply call the save() method with the name and the value of a variable as argument to store your data online and call the read() method with the name of your variable as argument to read the value of it.
Note: The returned value will automatically be in your desired data type.
Also, call exists() method with name of a variable as argument to check if the variable exists.It will return True or False.


Here is a sample code -

import pydataman

data = pydataman.CloudVariable(The_Url_You_Copied)

data.save("Name", "John")  # This will store the variable Name with the value John
LocalName = data.read("Name")  # This will read the value of Name from your database and store in LocalName
print(LocalName)  # This will print John

Another example of checking if a variable exists -

import pydataman

data = pydataman.CloudVariable(The_Url_You_Copied)

if data.exists("X"):  # The method returns true if the variable exists in your database
      print("The variable X exists")
else:
      print("The variable X doesn't exist")

Note: You have to use multiple firebase database (Not account) for multiple projects.





Store files online


Store your files online like variables, and here is how to do it -

Setting up your online storage:

Step 1:   Go to https://console.firebase.google.com/
Step 2:   Login with your google account.
Step 3:   Click on Add Project
Step 4:   Enter any name (The name doesn't matter at all).
Step 5:   Disable Google Analytics and click on continue.
Step 6:   The project creation is now finished.
Step 7:   Click on Storage on the left.
Step 8:   Click on Get Started and click next.
Step 9:   Select your nearest location and click done.
Step 10:   Now go to Rules tab and replace the line allow read, write: if request.auth != null; by allow read, write
Step 11:   Then click the settings icon beside Project Overview on the left and select Project settings.
Step 12:   Click on the </> icon under Your apps.
Step 13:   Enter any name and press register.
Step 14:   Copy the items of the dictionary firebaseConfig, it's important.
Step 15:   Click Continue to console.
Step 16:   Now go to Service accounts tab and select Python.
Step 17:   Click on Generate new private key and save the key in any easy-to-remember name.
Step 18:   Finally click on Storage on the left and you are ready for the code.
Step 19:   Now go to your code and import the module pydataman.
Step 20:   After that create call the function InitializeDatabase with these 2 arguments -

  • The dictionary you recently copied.
  • The directory of you private key file


Note 1: You can find the dictionary in the general tab in project settings.
Note 2: You have to convert the dictionary to Python as it is written in JavaScript. (Don't worry, you don't have to know javascript)
Note 3: Only "apiKey", "authDomain", "databaseURL" and "storageBucket" is needed. Others are optional.


Everything is now ready. Create an object of the class NewFile() with the directory of your file (in your local device) as argument. To upload your file, call the upload method of NewFile() instance, and call the download() method to download the file.

One thing to remember, you can only upload and download files that is in the directory where your code is




Here is a sample code -

import pydataman

#You must change the values of config as your own info, otherwise the code won't work
config = {
    "apiKey": "AIzaSyBy37khExSIw-XZK2kT17_P1jPSxDt2rj",
    "authDomain": "variables-2da3.firebaseapp.com",
    "databaseURL": "https://variables-2da3-default-rtdb.asia-southeast1.firebasedatabase.app",
    "storageBucket": "variables-2da3.appspot.com",
}
serviceAccount = "Creds.json"

pydataman.InitializeDatabase(config, serviceAccount)
MyImage = pydataman.NewFile("Cat.png")
MyImage.upload()  #The file "Cat.png" is now uploaded to your database
MyImage.download()  #This will download the file and save as "Cat.png"



Twist: You can save the firebaseConfig dictionary using CloudVariable() and use in InitializeDatabase() whenever you want so that you don't have any chance to lose them.





Some example usage

Example 1.1 (Count how many times a code is run) - Saving in your drive:

import pydataman  # Importing the module

count = 0
if not pydataman.exists("count"):  # Create a variable if it doesn't exist
    pydataman.save("count", 0)
        
count = pydataman.read("count")  # This will read the value of count and store in count variable
count = count + 1
    
pydataman.save("count", count)  # This will store the variable count with the value of count
print("This program ran " + str(count) + " times")



Example 2 (Storing my accounts in online database):

import pydataman  # Importing the module
    
data = pydataman.CloudVariable(the_url_you_copied)  # Create the object
    
Accounts = {"myemail@gmail.com" : "mypassword",
              "mysecondemail@gmail.com" : "hardpassword",
              "blahblahemail@gmail.com" : "blahblahpassword"}
                  
data.save("MyAccounts", Accounts)  # This will store the dictionary with name MyAccounts

After running the code above, you can run this code from anywhere in the world and any device you want to get the value of MyAccounts -

import pydataman  # Importing the module
    
data = pydataman.CloudVariable(the_url_you_copied)  # Create the object
Accounts = {}
                  
Accounts = data.read("MyAccounts")  # This will load the dictionary MyAccounts from your database



Example 3 (Save an excel file in online storage):

import pydataman

#You must change the values of config as your own info, otherwise the code won't work
config = {
    "apiKey": "AIzaSyBy37khExSIw-XZK2kT17_P1jPSxDt2rj",
    "authDomain": "variables-2da3.firebaseapp.com",
    "databaseURL": "https://variables-2da3-default-rtdb.asia-southeast1.firebasedatabase.app",
    "storageBucket": "variables-2da3.appspot.com",
}
serviceAccount = "Creds.json"
    
pydataman.InitializeDatabase(config, serviceAccount)
MyExcelFile = pydataman.NewFile("Data.xlsx")
MyExcelFile.upload()  # This will upload the file in your storage






Troubleshooting - Some common problems you might face

  

Problem 1 - ModuleNotFoundError: No module named 'Crypto'

   If you get any error like this while running your code, try following these steps -
   Step 1:   Open your terminal.
   Step 2:   Enter pip uninstall crypto.
   Step 3:   Enter pip uninstall pycryptodome.
   Step 4:   Enter pip install pycryptodome.

  

Problem 2 - ... has no attribute ...

   If you get this type of error after the module is updated, try upgrading the module -
   Step 1:   Open your terminal.
   Step 2:   Enter pip install pydataman -U.

  

Problem 3 - ModuleNotFoundError: No module named 'sseclient'

   If you get any error like this while running your code, try opening up terminal and enter - pip install sseclient.





Lisence

This module is completely free and open source. You can freely use and modify the module if you want. Any suggestion will be highly appreciated ;)
Created by Sajedur Rahman Fiad and Jonayed Mohiuddin Shanto.
Email : scientistfiad@gmail.com

Let me know your valuable feedback.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages