Skip to main content

GitBase is a custom database system built with Python and powered by GitHub, treating GitHub repositories as databases. It features encryption using the cryptography library, ensuring data security.

Project description

GitBase

GitBase is a custom database system built with Python and powered by GitHub, treating GitHub repositories as databases ("GitBases" or "GitBase"). It features encryption using the cryptography library, ensuring data security. Designed for Python developers, GitBase provides a seamless and intuitive database solution without requiring knowledge of a separate database language. Additionally, it supports offline backups, enabling users to save, load, and delete data without an internet connection. Once online, the database automatically syncs with the latest stored file, ensuring consistency across offline and online environments.


Latest Update (05/15/2025; 09:08 AM)

  • Adjusted offline saving path for __config__ (now default saves to Documents instead of /AppData/Roaming/, /Library/Application Support/, /.local/share/)
  • Fix issue where first item for get_all in DataSystem was malformed

Example Code

# GitBase v0.7.2 Showcase Example

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

# -------------------------
# Online Status Check
# -------------------------
print(f"Is Online: {is_online()}")  # Check if the system is online

# -------------------------
# GitHub Database Setup
# -------------------------
encryption_key = Fernet.generate_key()  # Generate encryption key for secure storage

# MultiBase setup with fallback repository configurations (if needed)
database = MultiBase([
    {
        "token": "YOUR_TOKEN",
        "repo_owner": "YOUR_GITHUB_USERNAME",
        "repo_name": "YOUR_REPO_NAME",
        "branch": "main"
    },
    # Additional GitBase configurations can be added here
    # {"token": "SECOND_TOKEN", "repo_owner": "SECOND_USERNAME", "repo_name": "SECOND_REPO", "branch": "main"}
])
# When using Legacy GitBase do the below instead (will be a single repository)
# from gitbase import GitBase
# database = GitBase(token=GITHUB_TOKEN, repo_owner=REPO_OWNER, repo_name=REPO_NAME)

# -------------------------
# Configure GitBase
# -------------------------

__config__.app_name = "Cool RPG Game"
__config__.publisher = "Taireru LLC"
__config__.version = "1.0.0"
__config__.use_offline = True # defaults to `True`, no need to type out unless you want to set it to `False`
__config__.show_logs = True # defaults to `True`, no need to type out unless you want to set it to `False`
__config__.use_version_path = False # defaults to `True`, this variable will decide if your app path will use a version subdirectory (meaning different versions will have different data)
__config__.setdatpath() # Update `datpath` variable of `__config__` for offline data saving (you can also set it manually via `__config__.datpath = 'path/to/data'`)
# the path setup with `__config__.cleanpath` property can be used for other application needs besides GitBase, it will return a clean path based on your os (ex. Windows -> C:/Users/YourUsername/Documents/Taireru LLC/Cool RPG Game/)

# -------------------------
# System Instantiation
# -------------------------
player_data_system = PlayerDataSystem(db=database, encryption_key=encryption_key)
data_system = DataSystem(db=database, encryption_key=encryption_key)

# -------------------------
# File Upload & Download
# -------------------------
# Upload file to GitHub repository
database.upload_file(file_path="my_file.txt", remote_path="saved_files/my_file.txt")

# Download file from GitHub repository
database.download_file(remote_path="saved_files/my_file.txt", local_path="files/my_file.txt")

# -------------------------
# File Streaming with ProxyFile
# -------------------------
proxy_file = ProxyFile(repo_owner="REPO_OWNER", repo_name="REPO_NAME", token="GITHUB_TOKEN", branch="main")

# Stream an audio file
audio_file = proxy_file.play_audio(remote_path="audio_files/sample_audio.wav")

# Stream a video file
video_file = proxy_file.play_video(remote_path="video_files/sample_video.mp4")

# -------------------------
# Player Class Definition
# -------------------------
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 & Load Player Data with Encryption
# -------------------------
# Save player data to the repository (with encryption)
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)

# -------------------------
# Game Flow Functions
# -------------------------
def load_game():
    print("Game starting...")

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

# -------------------------
# Account Validation & Login
# -------------------------
# Validate player credentials
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 & Load General Data with Encryption
# -------------------------
# Save data (key-value) to the repository (with encryption)
data_system.save_data(key="key_name", value=69, path="data", encryption=True)

# Load and display 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}")

# Display all stored data
print("All stored data:", data_system.get_all(path="data"))

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

# -------------------------
# Player Account Management
# -------------------------
# Display all player accounts
print("All player accounts:", player_data_system.get_all(path="players"))

# Delete a specific player account
NotificationManager.hide()  # Hide notifications temporarily
player_data_system.delete_account(username="john_doe")
NotificationManager.show()  # Show notifications again

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.7.2.tar.gz (22.9 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.7.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gitbase-0.7.2.tar.gz
Algorithm Hash digest
SHA256 8e64e748f82c0825ae2d5da6c8f5737390c57294d5366720bba3b5dd7551de81
MD5 af0a646f8ece8d6bae8096ea95516400
BLAKE2b-256 692cead4fc0700a1238d812c0786da960705bfe538a753f54f66ee32377f2631

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gitbase-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fed70bfd8730b65f23595d60a1ab780fe9a08ea205a273691fa4a352944c3fde
MD5 e887779056b781373a7ea269a3c07079
BLAKE2b-256 7b8fa343316a0b57bac0b5f96411e903df4f099c8cacb88cbd79b62cdbd159b0

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