PyliteDB


NamePyliteDB JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryPyliteDB is a lightweight, fast and simple database management system
upload_time2024-11-06 08:29:27
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pylite Database

Pylite is a lightweight database system built in Python. It provides a simple and intuitive interface for creating, managing, and querying data with support for table relationships, type validation, and event handling.

## Features

- 🔒 **Built-in Encryption**: Secure your data with AES-GCM encryption
- 📊 **Pandas Integration**: Powered by pandas DataFrame for efficient data manipulation
- 🔗 **Table Relationships**: Support for primary and foreign key relationships
- 🎯 **Type Validation**: Built-in type checking and custom type validators
- 🎭 **Event System**: Comprehensive event hooks for database operations
- 💾 **Auto-save Capability**: Optional automatic saving after modifications
- 🔄 **SQL Import**: Import existing SQLite databases
- 📝 **Custom Types**: Includes email and password validators with fake data generation

## Installation

```bash
pip install PyliteDB
```

## Quick Start

```python
from pylite import Database, email, password

# Create a new database
db = Database(AutoSave=True)

# Create a users table with typed columns
db.CreateTable("Users").AddColumn(
    ID=int,
    Email=email,
    Password=password,
    Username=str
)

# Insert data
db.Users.Insert(
    ID=1,
    Email="user@example.com",
    Password="SecurePass123!",
    Username="john_doe"
)

# Save database with encryption
db.Save("my_database.pylite", "your_secure_password")

# Load existing database
db = Database("my_database.pylite", "your_secure_password")
```

## Working with Tables

### Creating Tables

```python
# Create table with columns
db.CreateTable("Products").AddColumn(
    ID=int,
    Name=str,
    Price=float,
    Stock=int
)
```

### CRUD Operations

```python
# Insert
db.Products.Insert(ID=1, Name="Widget", Price=9.99, Stock=100)

# Select
product = db.Products.Get(ID=1)
filtered = db.Products.Select(db.Products.Price > 5.00)

# Update
db.Products.Update(db.Products.ID == 1, Price=10.99)
db.Products.UpdateAt(0, Stock=95)

# Delete
db.Products.Delete(db.Products.Stock == 0)
db.Products.DeleteAt(0)
```

### Table Relationships

```python
# Create related tables
db.CreateTable("Orders").AddColumn(
    OrderID=int,
    ProductID=int,
    Quantity=int
)

# Link tables
db.Link(db.Orders.ProductID, db.Products.ID)
```

## Event Handling

```python
# Add event handlers
db.Users.afterInsert = lambda table, added: print(f"New user added: {added['Username']}")
db.Users.beforeDelete = lambda table: print("About to delete user(s)")
```

## Custom Types

Pylite includes built-in custom types with validation:

### Email Type

```python
# Validates email format
db.CreateTable("Contacts").AddColumn(
    Email=email  # Ensures valid email format
)
```

### Password Type

```python
# Enforces password requirements
db.CreateTable("Accounts").AddColumn(
    Password=password  # Requires length, upper/lower case, numbers, special chars
)
```

## Data Security

Pylite uses AES-GCM encryption with:

- PBKDF2 key derivation
- Random salt generation
- Secure IV handling
- Authentication tags

```python
# Save with encryption
db.Save("secure_database.pylite", "your_strong_password")

# Load encrypted database
db = Database("secure_database.pylite", "your_strong_password")
```

## Method Reference

### Database Class Methods

#### Core Database Operations

```python
Database(Path="", Password="", AutoSave=False)  # Constructor
Database.Save(Path="", Password="", asJson=False)  # Save database to file
Database.Load()  # Load database from file
Database.LoadFromSQL(SQLFilePath)  # Load from SQLite database
Database.ChangePassword(Password)  # Change database encryption password
```

#### Table Management

```python
Database.CreateTable(TableName)  # Create new table
Database.DeleteTable(TableName)  # Delete existing table
Database.RenameTable(OldName, NewName)  # Rename table
Database.GetTables()  # Get list of all tables
Database.ClearEmptyTables()  # Remove all empty tables
Database.Link(source, target)  # Create relationship between tables
```

### Table Class Methods

#### Column Operations

```python
Table.AddColumn(**columns)  # Add new columns with types
Table.RemoveColumn(ColumnName)  # Remove column
Table.RenameColumn(OldName, NewName)  # Rename column
Table.ReorderColumns(NewOrder)  # Reorder columns
```

#### CRUD Operations

```python
# Create
Table.Insert(**columns)  # Insert new row

# Read
Table.Select(condition=None)  # Select rows matching condition
Table.Get(**columns)  # Get first row matching conditions
Table[column_name]  # Access column data
Table[row_index]  # Access row data

# Update
Table.Update(selector=None, **columns)  # Update rows matching selector
Table.UpdateAt(index, **columns)  # Update row at specific index

# Delete
Table.Delete(condition=None, index=None, all=False)  # Delete rows
Table.DeleteAt(index)  # Delete row at specific index
```

#### Query Operations

```python
Table.Sort(Column, ascending=True)  # Sort table by column
Table.Limit(n)  # Limit to first n rows
Table.RemoveDuplicates()  # Remove duplicate rows
Table.Exists(**columns)  # Check if rows matching conditions exist
```

#### Data Analysis

```python
Table.ColumnStats(column)  # Get column statistics
Table.Difference(OtherTable)  # Compare with another table
Table.Intersection(OtherTable, onColumn=None)  # Get common rows
Table.Union(OtherTable)  # Combine tables
Table.Distinct(Column)  # Get unique values in column
Table.Map(Column, Mapping)  # Apply mapping to column
```

#### Properties and Attributes

```python
Table.Columns  # List of column names
Table.Rows  # List of all rows
Table.Length  # Number of rows
Table.df  # Access underlying pandas DataFrame
len(table)  # Get number of rows
```

#### Storage Operations

```python
Table.SaveToDisk(path)  # Save single table to file
Table.LoadFromDisk(path)  # Load single table from file
Table.toDict()  # Convert table to dictionary
Table.loadFromDict(data)  # Load table from dictionary
```

#### Event Handlers

Tables support the following event hooks:

- `beforeInsert`, `afterInsert`
- `beforeUpdate`, `afterUpdate`
- `beforeDelete`, `afterDelete`
- `beforeRenameColumn`, `afterRenameColumn`
- `beforeRemoveColumn`, `afterRemoveColumn`
- `beforeSelect`, `afterSelect`
- `beforeAddColumn`, `afterAddColumn`
- `beforeCopy`, `afterCopy`

```python
# Example of event handler usage
table.afterInsert = lambda table, added: print(f"Added new row: {added}")
```

## Additional Features

- **Auto-save**: Enable automatic saving after modifications
- **SQL Import**: Import existing SQLite databases
- **Table Operations**: Sort, filter, limit, and manipulate data
- **Data Statistics**: Get column statistics and table information
- **Data Export**: Convert tables to dictionaries or save individually

## Best Practices

1. **Always use strong passwords** for database encryption
2. **Enable AutoSave** for important data
3. **Implement event handlers** for critical operations
4. **Use appropriate column types** for data validation
5. **Regular backups** of database files

## Contributing

Contributions are welcome! Please feel free to submit pull requests, create issues, or suggest improvements.

## License

[MIT License](LICENSE)

## Support

For support, please open an issue on the GitHub repository or contact the maintainers.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PyliteDB",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Ilify <iliesmraihia@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/63/ac/2e3aced29f3c2a67eb109f3ef6809793216063263e5b0e31e841af3bd46f/pylitedb-0.4.1.tar.gz",
    "platform": null,
    "description": "# Pylite Database\r\n\r\nPylite is a lightweight database system built in Python. It provides a simple and intuitive interface for creating, managing, and querying data with support for table relationships, type validation, and event handling.\r\n\r\n## Features\r\n\r\n- \ud83d\udd12 **Built-in Encryption**: Secure your data with AES-GCM encryption\r\n- \ud83d\udcca **Pandas Integration**: Powered by pandas DataFrame for efficient data manipulation\r\n- \ud83d\udd17 **Table Relationships**: Support for primary and foreign key relationships\r\n- \ud83c\udfaf **Type Validation**: Built-in type checking and custom type validators\r\n- \ud83c\udfad **Event System**: Comprehensive event hooks for database operations\r\n- \ud83d\udcbe **Auto-save Capability**: Optional automatic saving after modifications\r\n- \ud83d\udd04 **SQL Import**: Import existing SQLite databases\r\n- \ud83d\udcdd **Custom Types**: Includes email and password validators with fake data generation\r\n\r\n## Installation\r\n\r\n```bash\r\npip install PyliteDB\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom pylite import Database, email, password\r\n\r\n# Create a new database\r\ndb = Database(AutoSave=True)\r\n\r\n# Create a users table with typed columns\r\ndb.CreateTable(\"Users\").AddColumn(\r\n    ID=int,\r\n    Email=email,\r\n    Password=password,\r\n    Username=str\r\n)\r\n\r\n# Insert data\r\ndb.Users.Insert(\r\n    ID=1,\r\n    Email=\"user@example.com\",\r\n    Password=\"SecurePass123!\",\r\n    Username=\"john_doe\"\r\n)\r\n\r\n# Save database with encryption\r\ndb.Save(\"my_database.pylite\", \"your_secure_password\")\r\n\r\n# Load existing database\r\ndb = Database(\"my_database.pylite\", \"your_secure_password\")\r\n```\r\n\r\n## Working with Tables\r\n\r\n### Creating Tables\r\n\r\n```python\r\n# Create table with columns\r\ndb.CreateTable(\"Products\").AddColumn(\r\n    ID=int,\r\n    Name=str,\r\n    Price=float,\r\n    Stock=int\r\n)\r\n```\r\n\r\n### CRUD Operations\r\n\r\n```python\r\n# Insert\r\ndb.Products.Insert(ID=1, Name=\"Widget\", Price=9.99, Stock=100)\r\n\r\n# Select\r\nproduct = db.Products.Get(ID=1)\r\nfiltered = db.Products.Select(db.Products.Price > 5.00)\r\n\r\n# Update\r\ndb.Products.Update(db.Products.ID == 1, Price=10.99)\r\ndb.Products.UpdateAt(0, Stock=95)\r\n\r\n# Delete\r\ndb.Products.Delete(db.Products.Stock == 0)\r\ndb.Products.DeleteAt(0)\r\n```\r\n\r\n### Table Relationships\r\n\r\n```python\r\n# Create related tables\r\ndb.CreateTable(\"Orders\").AddColumn(\r\n    OrderID=int,\r\n    ProductID=int,\r\n    Quantity=int\r\n)\r\n\r\n# Link tables\r\ndb.Link(db.Orders.ProductID, db.Products.ID)\r\n```\r\n\r\n## Event Handling\r\n\r\n```python\r\n# Add event handlers\r\ndb.Users.afterInsert = lambda table, added: print(f\"New user added: {added['Username']}\")\r\ndb.Users.beforeDelete = lambda table: print(\"About to delete user(s)\")\r\n```\r\n\r\n## Custom Types\r\n\r\nPylite includes built-in custom types with validation:\r\n\r\n### Email Type\r\n\r\n```python\r\n# Validates email format\r\ndb.CreateTable(\"Contacts\").AddColumn(\r\n    Email=email  # Ensures valid email format\r\n)\r\n```\r\n\r\n### Password Type\r\n\r\n```python\r\n# Enforces password requirements\r\ndb.CreateTable(\"Accounts\").AddColumn(\r\n    Password=password  # Requires length, upper/lower case, numbers, special chars\r\n)\r\n```\r\n\r\n## Data Security\r\n\r\nPylite uses AES-GCM encryption with:\r\n\r\n- PBKDF2 key derivation\r\n- Random salt generation\r\n- Secure IV handling\r\n- Authentication tags\r\n\r\n```python\r\n# Save with encryption\r\ndb.Save(\"secure_database.pylite\", \"your_strong_password\")\r\n\r\n# Load encrypted database\r\ndb = Database(\"secure_database.pylite\", \"your_strong_password\")\r\n```\r\n\r\n## Method Reference\r\n\r\n### Database Class Methods\r\n\r\n#### Core Database Operations\r\n\r\n```python\r\nDatabase(Path=\"\", Password=\"\", AutoSave=False)  # Constructor\r\nDatabase.Save(Path=\"\", Password=\"\", asJson=False)  # Save database to file\r\nDatabase.Load()  # Load database from file\r\nDatabase.LoadFromSQL(SQLFilePath)  # Load from SQLite database\r\nDatabase.ChangePassword(Password)  # Change database encryption password\r\n```\r\n\r\n#### Table Management\r\n\r\n```python\r\nDatabase.CreateTable(TableName)  # Create new table\r\nDatabase.DeleteTable(TableName)  # Delete existing table\r\nDatabase.RenameTable(OldName, NewName)  # Rename table\r\nDatabase.GetTables()  # Get list of all tables\r\nDatabase.ClearEmptyTables()  # Remove all empty tables\r\nDatabase.Link(source, target)  # Create relationship between tables\r\n```\r\n\r\n### Table Class Methods\r\n\r\n#### Column Operations\r\n\r\n```python\r\nTable.AddColumn(**columns)  # Add new columns with types\r\nTable.RemoveColumn(ColumnName)  # Remove column\r\nTable.RenameColumn(OldName, NewName)  # Rename column\r\nTable.ReorderColumns(NewOrder)  # Reorder columns\r\n```\r\n\r\n#### CRUD Operations\r\n\r\n```python\r\n# Create\r\nTable.Insert(**columns)  # Insert new row\r\n\r\n# Read\r\nTable.Select(condition=None)  # Select rows matching condition\r\nTable.Get(**columns)  # Get first row matching conditions\r\nTable[column_name]  # Access column data\r\nTable[row_index]  # Access row data\r\n\r\n# Update\r\nTable.Update(selector=None, **columns)  # Update rows matching selector\r\nTable.UpdateAt(index, **columns)  # Update row at specific index\r\n\r\n# Delete\r\nTable.Delete(condition=None, index=None, all=False)  # Delete rows\r\nTable.DeleteAt(index)  # Delete row at specific index\r\n```\r\n\r\n#### Query Operations\r\n\r\n```python\r\nTable.Sort(Column, ascending=True)  # Sort table by column\r\nTable.Limit(n)  # Limit to first n rows\r\nTable.RemoveDuplicates()  # Remove duplicate rows\r\nTable.Exists(**columns)  # Check if rows matching conditions exist\r\n```\r\n\r\n#### Data Analysis\r\n\r\n```python\r\nTable.ColumnStats(column)  # Get column statistics\r\nTable.Difference(OtherTable)  # Compare with another table\r\nTable.Intersection(OtherTable, onColumn=None)  # Get common rows\r\nTable.Union(OtherTable)  # Combine tables\r\nTable.Distinct(Column)  # Get unique values in column\r\nTable.Map(Column, Mapping)  # Apply mapping to column\r\n```\r\n\r\n#### Properties and Attributes\r\n\r\n```python\r\nTable.Columns  # List of column names\r\nTable.Rows  # List of all rows\r\nTable.Length  # Number of rows\r\nTable.df  # Access underlying pandas DataFrame\r\nlen(table)  # Get number of rows\r\n```\r\n\r\n#### Storage Operations\r\n\r\n```python\r\nTable.SaveToDisk(path)  # Save single table to file\r\nTable.LoadFromDisk(path)  # Load single table from file\r\nTable.toDict()  # Convert table to dictionary\r\nTable.loadFromDict(data)  # Load table from dictionary\r\n```\r\n\r\n#### Event Handlers\r\n\r\nTables support the following event hooks:\r\n\r\n- `beforeInsert`, `afterInsert`\r\n- `beforeUpdate`, `afterUpdate`\r\n- `beforeDelete`, `afterDelete`\r\n- `beforeRenameColumn`, `afterRenameColumn`\r\n- `beforeRemoveColumn`, `afterRemoveColumn`\r\n- `beforeSelect`, `afterSelect`\r\n- `beforeAddColumn`, `afterAddColumn`\r\n- `beforeCopy`, `afterCopy`\r\n\r\n```python\r\n# Example of event handler usage\r\ntable.afterInsert = lambda table, added: print(f\"Added new row: {added}\")\r\n```\r\n\r\n## Additional Features\r\n\r\n- **Auto-save**: Enable automatic saving after modifications\r\n- **SQL Import**: Import existing SQLite databases\r\n- **Table Operations**: Sort, filter, limit, and manipulate data\r\n- **Data Statistics**: Get column statistics and table information\r\n- **Data Export**: Convert tables to dictionaries or save individually\r\n\r\n## Best Practices\r\n\r\n1. **Always use strong passwords** for database encryption\r\n2. **Enable AutoSave** for important data\r\n3. **Implement event handlers** for critical operations\r\n4. **Use appropriate column types** for data validation\r\n5. **Regular backups** of database files\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit pull requests, create issues, or suggest improvements.\r\n\r\n## License\r\n\r\n[MIT License](LICENSE)\r\n\r\n## Support\r\n\r\nFor support, please open an issue on the GitHub repository or contact the maintainers.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "PyliteDB is a lightweight, fast and simple database management system",
    "version": "0.4.1",
    "project_urls": {
        "Homepage": "https://github.com/ilify/Pylite",
        "Issues": "https://github.com/ilify/Pylite/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a532af4dea702652215c7ed3bc6cefc172d2e493235d2c38d6c75ac4ffc77964",
                "md5": "891eb7539b2d38ef81746b3ecb1ae97d",
                "sha256": "676ca383c4c7a9e01162149eca9c9ddc433d48ca46cf7e5af931cc9bcbce5390"
            },
            "downloads": -1,
            "filename": "PyliteDB-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "891eb7539b2d38ef81746b3ecb1ae97d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16024,
            "upload_time": "2024-11-06T08:29:23",
            "upload_time_iso_8601": "2024-11-06T08:29:23.261863Z",
            "url": "https://files.pythonhosted.org/packages/a5/32/af4dea702652215c7ed3bc6cefc172d2e493235d2c38d6c75ac4ffc77964/PyliteDB-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "63ac2e3aced29f3c2a67eb109f3ef6809793216063263e5b0e31e841af3bd46f",
                "md5": "959672e4d88ca0c5b5433e32ac3c3343",
                "sha256": "b6580bfd0c80f146d062dea42e66aa5ecb51bfde1e1038731985a24e309ad8cc"
            },
            "downloads": -1,
            "filename": "pylitedb-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "959672e4d88ca0c5b5433e32ac3c3343",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18162,
            "upload_time": "2024-11-06T08:29:27",
            "upload_time_iso_8601": "2024-11-06T08:29:27.545623Z",
            "url": "https://files.pythonhosted.org/packages/63/ac/2e3aced29f3c2a67eb109f3ef6809793216063263e5b0e31e841af3bd46f/pylitedb-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-06 08:29:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ilify",
    "github_project": "Pylite",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pylitedb"
}
        
Elapsed time: 0.67452s