Skip to main content

My package description

Project description

Sqwool

Sqwool Logo

Sqwool is a robust and cross-platform extension manager for SQLite, designed to simplify the integration and management of SQLite extensions in your Python projects. It seamlessly handles platform-specific extension loading, ensuring compatibility across macOS, Windows, and Linux.

Table of Contents

Features

  • Cross-Platform Support: Automatically detects and handles platform-specific SQLite extensions for macOS, Windows, and Linux.
  • Seamless Extension Management: Automatically loads and manages SQLite extensions, reducing boilerplate code.
  • Enhanced Connection Handling: Extends the native sqlite3.Connection to support advanced features and extension loading.
  • Easy Setup: Simple functions to initialize and manage extension directories.
  • Comprehensive Platform Information: Provides detailed information about the SQLite build and platform specifics.

Installation

You can install Sqwool via pip:

pip install sqwool

Or clone the repository and install manually:

git clone https://github.com/yourusername/sqwool.git
cd sqwool
pip install .

Quick Start

Here’s a simple example to get you started with Sqwool:

import sqwool

# Connect to the SQLite database
conn = sqwool.connect('example.db')

# Create a cursor
cursor = conn.cursor()

# Execute a simple query
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')

# Insert a record
cursor.execute('INSERT INTO users (name) VALUES (?)', ('Alice',))

# Commit the transaction
conn.commit()

# Fetch records
cursor.execute('SELECT * FROM users')
users = cursor.fetchall()
print(users)

# Close the connection
conn.close()

Detailed Usage

Managing Extensions

Sqwool automatically manages and loads SQLite extensions based on your platform. To customize the extensions directory or manage extensions manually, follow these steps:

import sqwool
from pathlib import Path

# Set up custom extensions directory
extensions_dir = sqwool.setup_extension_directories(base_dir='path/to/extensions')

# Connect to the database with custom extensions directory
conn = sqwool.connect('example.db', extensions_dir=extensions_dir)

# Verify if extensions are supported
if conn.extensions_supported:
    print("Extensions loaded successfully.")
else:
    print("Extensions are not supported on this platform.")

conn.close()

Retrieving Platform and SQLite Information

You can retrieve detailed information about your platform and SQLite build:

import sqwool

platform_info = sqwool.get_platform_info()
print(platform_info)

sqlite_build_info = sqwool.get_sqlite_build_info()
print(sqlite_build_info)

Architecture

Sqwool is designed with modularity and extensibility in mind. Below is an overview of its architecture:

graph TD
    A[User Code] --> B[Sqwool Connect Function]
    B --> C[Enhanced Connection Class]
    C --> D[Extensions Manager]
    D --> E[Platform Info]
    D --> F[Extension Loader]
    C --> G[SQLite3 Connection]
    G --> H[SQLite3 Database]

Components

  • PlatformInfo: Detects the operating system and architecture to determine the appropriate extensions to load.
  • ExtensionsManager: Manages the loading and validation of SQLite extensions based on the detected platform.
  • Connection: An enhanced version of sqlite3.Connection that integrates with ExtensionsManager to load extensions automatically.
  • Connect Function: A wrapper around sqlite3.connect that initializes the enhanced Connection and manages extensions.

Example Use Cases

1. Data Encryption with SQLite Extensions

Enhance your SQLite database with encryption capabilities using extensions like SQLCipher.

import sqwool

# Initialize connection with encryption extension
conn = sqwool.connect('secure.db', extensions_dir='path/to/extensions')

# Enable encryption (assuming the extension provides such functionality)
conn.execute("PRAGMA key = 'your-encryption-key'")

# Proceed with normal database operations
cursor = conn.cursor()
cursor.execute('CREATE TABLE secrets (id INTEGER PRIMARY KEY, data TEXT)')
cursor.execute('INSERT INTO secrets (data) VALUES (?)', ('Top Secret',))
conn.commit()

conn.close()

2. Full-Text Search Integration

Integrate full-text search capabilities using the FTS5 extension.

import sqwool

# Connect to the database
conn = sqwool.connect('fts_example.db')

# Create a virtual table for full-text search
conn.execute('CREATE VIRTUAL TABLE documents USING fts5(content)')

# Insert documents
conn.execute("INSERT INTO documents (content) VALUES (?)", ("This is a sample document.",))
conn.execute("INSERT INTO documents (content) VALUES (?)", ("Another example of full-text search.",))
conn.commit()

# Perform a full-text search
cursor = conn.execute("SELECT rowid, content FROM documents WHERE content MATCH 'sample'")
results = cursor.fetchall()
print(results)

conn.close()

3. Geospatial Data Handling

Utilize geospatial extensions like SpatiaLite for advanced spatial data operations.

import sqwool

# Connect to the database
conn = sqwool.connect('spatial.db')

# Load SpatiaLite extension
conn.load_extension('mod_spatialite')

# Initialize spatial metadata
conn.execute('SELECT InitSpatialMetaData()')

# Create a spatial table
conn.execute('''
    CREATE TABLE places (
        id INTEGER PRIMARY KEY,
        name TEXT
    )
''')
conn.execute('''
    SELECT AddGeometryColumn('places', 'geom', 4326, 'POINT', 'XY')
''')

# Insert a spatial record
conn.execute('''
    INSERT INTO places (name, geom) VALUES (?, GeomFromText('POINT(-122.4194 37.7749)', 4326))
''', ('San Francisco',))
conn.commit()

# Query spatial data
cursor = conn.execute('''
    SELECT name, AsText(geom) FROM places WHERE Within(geom, BuildMbr(-123, 37, -121, 38))
''')
results = cursor.fetchall()
print(results)

conn.close()

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/YourFeature.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature/YourFeature.
  5. Open a pull request.

Please ensure your code adheres to the project's coding standards and includes appropriate tests.

License

This project is licensed under the MIT License.


For more information, visit the Sqwool GitHub Repository.

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

sqwool-0.1.0.tar.gz (3.8 MB view details)

Uploaded Source

Built Distribution

sqwool-0.1.0-py3-none-any.whl (3.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqwool-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for sqwool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 163b62f2be6e2a8174ba297246dc710e0b7f0fe5ca6dc034cdb9b9c5b8dcd214
MD5 2fb65f6cec9bbd9fdca93347af486ab9
BLAKE2b-256 e7d52eb958a0323fafc3ed9ea2e34b7568e67babc53a38c36cc6fd94a44cdf64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqwool-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for sqwool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13e9a2930058dbb3c9b31dd07752909da78384681b82411bb6d7b0337e20e202
MD5 a747150a0cfcc8c7076611ec090ef7a3
BLAKE2b-256 18bf5e5c1b9d04b1f3ceeeea1d98099192a91dc64e29cd91c9d9bf341c4a2669

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page