Skip to main content

A file-based document store with python interface

Project description

Bosc

Bosc

pypi

Bosc is a document store that provides an easy, Pythonic interface for handling documents stored on the local file system. It utilizes the full power of SQLite for storing and querying documents and employs Pydantic as the parsing and validation engine, ensuring it works seamlessly within the modern Python ecosystem, including FastAPI.

⚠️ Bosc is not an ORM for SQLite. It is a document-oriented store that uses SQLite as a backend. It is not designed to replace traditional SQL databases, but rather to provide a simple, Pythonic interface for working with flexible documents.

Installation

Before you begin, ensure you have Python installed on your system. This document store requires Python 3.8 or newer.

You can install Bosc using pip:

pip install bosc

Quickstart

Defining a Document Model

from bosc import Document


class User(Document):
    name: str
    age: int

    # Specify the database path for this document
    bosc_database_path = "my_database.db"
    
    # Specify the collection name for this document (Optional)
    bosc_collection_name = "users"

Inserting Documents

user = User(name="John Doe", age=30)
user.insert()  # Insert the document into the database

# Inserting multiple documents
User.insert_many([
    User(name="Jane Doe", age=25),
    User(name="Alice", age=35),
])

Querying Documents

# Find all users
users = User.find()

# Find users with specific criteria
johns = User.find(User.name == "John Doe")
young_users = User.find(User.age < 30)

# Find users with multiple criteria
users = User.find(User.name == "John Doe", User.age > 30)

# Find having order by
users = User.find(
    User.name == "John Doe", 
    order_by="age", 
    order_direction=OrderDirection.ASC
)

# Find with limit
users = User.find(User.name == "John Doe", limit=1)

# Find with offset
users = User.find(User.name == "John Doe", offset=1)

# Find a single user
jane = User.find_one(User.name == "Jane Doe")

Updating Documents

# Update all users named John Doe to have age 31
User.update(User.name == "John Doe", Set("age", 31))

# Update a single document
john = User.find_one(User.name == "John Doe")
john.age = 32
john.save()  # This uses the OnConflict.REPLACE strategy

Deleting Documents

# Delete a specific user
jane.delete()

# Delete all users named Alice
User.delete_many(User.name == "Alice")

Advanced Usage

Working with Indexes

To improve query performance, you can define indexes on your document fields.

from bosc import Document, Index, IndexType

class User(Document):
    name: str
    age: int

    bosc_indexes = [
        Index("name", IndexType.UNIQUE),
        Index("age", IndexType.PATH),
    ]
    bosc_database_path = "my_database.db"

# Sync indexes with the database
User.sync_indexes()

This will create indexes on the name and age fields of the User documents, assuming Index and IndexType are properly defined and imported from the bosc package.

Complex Queries

Leverage the full power of queries with complex conditions and ordering.

from bosc import And, Or
from bosc import OrderDirection

# Find users named John Doe over 30 years old
users = User.find(And(User.name == "John Doe", User.age > 30))

# Find users either named Alice or younger than 25
users = User.find(Or(User.name == "Alice", User.age < 25))

# Order users by age
users = User.find(order_by="age", order_direction=OrderDirection.ASC)

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

bosc-0.0.7.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

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

bosc-0.0.7-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file bosc-0.0.7.tar.gz.

File metadata

  • Download URL: bosc-0.0.7.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for bosc-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c224fdf2bf6322cd36c7b4f56fdcee20d8f181269a9d5f21d8a48937123998a9
MD5 c40611e105a1a4dea95f79ea1ede4b20
BLAKE2b-256 b334fe9a483d31b59807cf9674bc36627ce304e156e046e31a46fd2ceedc7412

See more details on using hashes here.

File details

Details for the file bosc-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: bosc-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for bosc-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 28a9b625ce6edc4f3fcabf90742a5fa3a2dec0cf1e233953f20014a248f1e655
MD5 2e47101b80fbbdb1c8e37fc6990c787a
BLAKE2b-256 e324990ccfcbf79d9bdd5284df6c1d4c44f64dafb050860c0a150ef966bbc2d6

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