Skip to main content

Add your description here

Project description

fxdb - Fast Execute in Database

fxdb - A lightweight, single-file library for easy and efficient database interactions.

Features

  • Single file, no external dependencies.
  • Streamlined operations for inserting, updating, and querying data.
  • Simple integration with dictionaries and dataframes.
  • Built-in backup functionality for data security.
  • Focused on core database operations (CRUD).

Installation

Install fxdb via pip:

pip install fxdb

Quick Start

1. Initialize a Database Instance

You can initialize the database by specifying the file path. If the file does not exist, it will be automatically created:

from fxdb import fxdb

# Example 1: Default database file
db = fxdb('data')

# Example 2: Custom database file
db = fxdb('data.sqlite3')

# Example 3: Database in a specific directory
db = fxdb('path/to/data/demo.db')

2. Backup Functionality

Ensure your data is secure with automatic backups:

db.backup(backup_dir="database_backup", keep_num=5)
  • backup_dir: Directory to store backups.
  • keep_num: Maximum number of backups to retain.

3. Table Operations

Interact with tables seamlessly. Use db['table_name'] to access or create a table:

table = db['test_table']
Automatic Table Creation
  • When inserting data, fxdb automatically creates the table based on the full set of keys provided in your data.
  • All keys across your dataset are analyzed to define the table structure, ensuring consistency and avoiding key mismatches.

4.Insert Data

Insert records into the table:

# Insert a single record
table.insert(name="Jack", age=25)

# Insert multiple records from a dictionary
table.insert_from_dict([
    {"name": "Bob", "age": 25, "city": "Los Angeles"},
    {"name": "Charlie", "age": 35, "city": "Chicago"}
])

# Insert data from a DataFrame
table.insert_from_df(data)

5.Upsert Data

Update or insert records if they already exist:

# Upsert from a dictionary
table.upsert_from_dict(data, keys=["name"])

# Upsert from a DataFrame
table.upsert_from_df(data, keys=["name","gender"])

6.Query Data

Retrieve data with minimal effort:

# Fetch all records
records = table.all()

# Select records matching specific criteria
jack = table.select(name="Jack")

7.Delete Data

Remove data from the table:

# Delete records matching specific criteria
table.delete(name="Jack")

# Truncate all data in the table
table.truncate()

# Drop the entire table
table.drop()

License

This project is licensed under the MIT License.

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

fxdb-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

fxdb-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file fxdb-0.1.0.tar.gz.

File metadata

  • Download URL: fxdb-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for fxdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e616f253479df2a6017c0bb7aa4da3c0b6f152f29acdbe9905f29be9874a2b9
MD5 ce3d01364ac83aa1ed97167a19d085ff
BLAKE2b-256 6e7c3193e58c415f176fca082eab6214173d0b79ee3b1231f273948763860683

See more details on using hashes here.

File details

Details for the file fxdb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fxdb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for fxdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7cab675ae67cd1839416dbc888e9e3b8f208c360c691d5b8d64d365610c8e4de
MD5 d1623f942acc1d86c38513d26207e3d2
BLAKE2b-256 b2be339d58ea2b5dc116344ef1c0b276b4c49191830b50d8bf826fd39da624ec

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