Skip to main content

A GitHub based database system ('GitBase') which offers offline backups and optional encryption.

Project description

GitBase

GitBase is a Python package for custom databases powered by GitHub ("Gitbases"/"GitBase"), with encryption using cryptography. It provides Python developers with a quick and easy-to-use database solution without requiring knowledge of a new programming language. Additionally, GitBase offers offline backups, allowing users to save, load, and delete their data even without an internet connection. The online database will automatically sync with the latest file, whether offline or online.


Latest Update

  • Made it possible to import is_online function from gitbase

Example Code

# Example for GitBase 0.5.4

from gitbase import MultiBase, PlayerDataSystem, DataSystem, NotificationManager, is_online
from cryptography.fernet import Fernet
import sys

# Check if they're online
print(f"Is Online: {is_online()}") # `is_online` returns a bool value

# Initialize GitHub database and encryption key
GITHUB_TOKEN = "YOUR_TOKEN"
REPO_OWNER = "YOUR_GITHUB_USERNAME"
REPO_NAME = "YOUR_REPO_NAME"
encryption_key = Fernet.generate_key()

# Setup MultiBase with one or more GitBase configurations.
# You can add multiple configurations to handle repository fallback.
database = MultiBase([
    {
        "token": GITHUB_TOKEN,
        "repo_owner": REPO_OWNER,
        "repo_name": REPO_NAME,
        "branch": "main"
    },
    # Additional GitBase configurations can be added here.
    # {"token": "YOUR_SECOND_TOKEN", "repo_owner": "YOUR_GITHUB_USERNAME", "repo_name": "YOUR_SECOND_REPO", "branch": "main"}
])
# In legacy use case do
# from gitbase import GitBase, PlayerDataSystem, DataSystem, NotificationManager
# database = GitBase(token=GITHUB_TOKEN, repo_owner=REPO_OWNER, repo_name=REPO_NAME, branch='main')

# Instantiate systems
player_data_system = PlayerDataSystem(db=database, encryption_key=encryption_key)
data_system = DataSystem(db=database, encryption_key=encryption_key)

# File upload and download examples
database.upload_file(file_path="my_file.txt", remote_path="saved_files/my_file.txt")
database.download_file(remote_path="saved_files/my_file.txt", local_path="files/my_file.txt")

# Define the Player class to manage individual player instances
class Player:
    def __init__(self, username, score, password):
        self.username = username
        self.score = score
        self.password = password

# Create a sample player instance
player = Player(username="john_doe", score=100, password="123")

# Save specific attributes of the player instance with encryption using MultiBase
player_data_system.save_account(
    username="john_doe",
    player_instance=player,
    encryption=True,
    attributes=["username", "score", "password"],
    path="players"
)

# Load player data
player_data_system.load_account(username="john_doe", player_instance=player, encryption=True)

# Placeholder functions for game flow
def load_game():
    print("Game starting...")

def main_menu():
    sys.exit("Exiting game...")

# Check if an account exists and validate user password
if player_data_system.get_all(path="players"):
    if player.password == input("Enter your password: "):
        print("Login successful!")
        load_game()
    else:
        print("Incorrect password!")
        main_menu()

# Save key-value data with encryption using MultiBase
data_system.save_data(key="key_name", value=69, path="data", encryption=True)

# Load and display a specific key-value pair
loaded_key_value = data_system.load_data(key="key_name", path="data", encryption=True)
print(f"Key: {loaded_key_value.key}, Value: {loaded_key_value.value}")

# Retrieve and display all key-value pairs in the data path
print("All stored data:", data_system.get_all(path="data"))

# Delete specific key-value data
data_system.delete_data(key="key_name", path="data")

# Retrieve and display all player accounts
print("All player accounts:", player_data_system.get_all(path="players"))

# Delete a specific player account and use NotificationManager to silence output
NotificationManager.hide()
player_data_system.delete_account(username="john_doe")
NotificationManager.show()

Consider Using GitBase Web

GitBase Web

GitBase Web is an extension of the Python project developed by Taireru LLC called GitBase. This extension allows developers to view all their saved data via the web.

Note: To use GitBase Web, you must:

  1. Use a private GitHub repository.
  2. Host the website using a service such as Vercel.

Links


Contact

For any inquiries, please email us at tairerullc@gmail.com. We’ll get back to you as soon as possible.
Thank you for using GitBase, and happy coding!

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

gitbase-0.5.4.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

gitbase-0.5.4-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file gitbase-0.5.4.tar.gz.

File metadata

  • Download URL: gitbase-0.5.4.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gitbase-0.5.4.tar.gz
Algorithm Hash digest
SHA256 5090d83f4af0cfde732c5c73df70fcc54b1547068d435a01d20d8574522fe3c5
MD5 39f169103e058b3ba95bb9d208acf2c7
BLAKE2b-256 7734ee6f69b731614d613c0a83de6fc620b3013531d4478299714b4c0b95168f

See more details on using hashes here.

File details

Details for the file gitbase-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: gitbase-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for gitbase-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4c575aeb50c8b3568aa2d9c8748001b777d25b8ee7906211c8cd227b5d53f27f
MD5 ccc2e26fa233c287c320bfdc50629ae7
BLAKE2b-256 90592f145cb59821298c75a16f0e8b546c409060ff9a5fd2c4e0034360cfe198

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