bosc


Namebosc JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryA file-based document store with python interface
upload_time2024-03-22 17:33:16
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.8
licenseNone
keywords document store file-based python pydantic sqlite
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Bosc](https://raw.githubusercontent.com/roman-right/bosc/main/logo/logo.svg)](https://github.com/roman-right/bosc)

# Bosc

[![pypi](https://img.shields.io/pypi/v/bosc.svg)](https://pypi.python.org/pypi/bosc)

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:

```shell
pip install bosc
```

## Quickstart

### Defining a Document Model

```python
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
```python
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
```python
# 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
```python
# 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
```python
# 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.

```python
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.

```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bosc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "document store, file-based, python, pydantic, sqlite",
    "author": null,
    "author_email": "Roman Right <roman-right@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/79/d8/d30bfc58d6612f61ed6359a12317fb2f726fcd37e6ff630b9ff495b4683e/bosc-0.0.6.tar.gz",
    "platform": null,
    "description": "[![Bosc](https://raw.githubusercontent.com/roman-right/bosc/main/logo/logo.svg)](https://github.com/roman-right/bosc)\n\n# Bosc\n\n[![pypi](https://img.shields.io/pypi/v/bosc.svg)](https://pypi.python.org/pypi/bosc)\n\nBosc 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.\n\n\n> \u26a0\ufe0f 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.\n\n## Installation\nBefore you begin, ensure you have Python installed on your system. This document store requires Python 3.8 or newer.\n\nYou can install Bosc using pip:\n\n```shell\npip install bosc\n```\n\n## Quickstart\n\n### Defining a Document Model\n\n```python\nfrom bosc import Document\n\n\nclass User(Document):\n    name: str\n    age: int\n\n    # Specify the database path for this document\n    bosc_database_path = \"my_database.db\"\n    \n    # Specify the collection name for this document (Optional)\n    bosc_collection_name = \"users\"\n```\n\n### Inserting Documents\n```python\nuser = User(name=\"John Doe\", age=30)\nuser.insert()  # Insert the document into the database\n\n# Inserting multiple documents\nUser.insert_many([\n    User(name=\"Jane Doe\", age=25),\n    User(name=\"Alice\", age=35),\n])\n```\n\n### Querying Documents\n```python\n# Find all users\nusers = User.find()\n\n# Find users with specific criteria\njohns = User.find(User.name == \"John Doe\")\nyoung_users = User.find(User.age < 30)\n\n# Find users with multiple criteria\nusers = User.find(User.name == \"John Doe\", User.age > 30)\n\n# Find having order by\nusers = User.find(\n    User.name == \"John Doe\", \n    order_by=\"age\", \n    order_direction=OrderDirection.ASC\n)\n\n# Find with limit\nusers = User.find(User.name == \"John Doe\", limit=1)\n\n# Find with offset\nusers = User.find(User.name == \"John Doe\", offset=1)\n\n# Find a single user\njane = User.find_one(User.name == \"Jane Doe\")\n```\n\n### Updating Documents\n```python\n# Update all users named John Doe to have age 31\nUser.update(User.name == \"John Doe\", Set(\"age\", 31))\n\n# Update a single document\njohn = User.find_one(User.name == \"John Doe\")\njohn.age = 32\njohn.save()  # This uses the OnConflict.REPLACE strategy\n```\n\n### Deleting Documents\n```python\n# Delete a specific user\njane.delete()\n\n# Delete all users named Alice\nUser.delete_many(User.name == \"Alice\")\n```\n\n## Advanced Usage\n\n### Working with Indexes\nTo improve query performance, you can define indexes on your document fields.\n\n```python\nfrom bosc import Document, Index, IndexType\n\nclass User(Document):\n    name: str\n    age: int\n\n    bosc_indexes = [\n        Index(\"name\", IndexType.UNIQUE),\n        Index(\"age\", IndexType.PATH),\n    ]\n    bosc_database_path = \"my_database.db\"\n\n# Sync indexes with the database\nUser.sync_indexes()\n```\n\nThis 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.\n\n### Complex Queries\nLeverage the full power of queries with complex conditions and ordering.\n\n```python\nfrom bosc import And, Or\nfrom bosc import OrderDirection\n\n# Find users named John Doe over 30 years old\nusers = User.find(And(User.name == \"John Doe\", User.age > 30))\n\n# Find users either named Alice or younger than 25\nusers = User.find(Or(User.name == \"Alice\", User.age < 25))\n\n# Order users by age\nusers = User.find(order_by=\"age\", order_direction=OrderDirection.ASC)\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A file-based document store with python interface",
    "version": "0.0.6",
    "project_urls": {
        "repository": "https://github.com/roman-right/bosc"
    },
    "split_keywords": [
        "document store",
        " file-based",
        " python",
        " pydantic",
        " sqlite"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f83abe1cc5546cd1f086f9edea97a98a8e1d56984c5e3034fa60330ceed9992b",
                "md5": "358b3021ac09620f663f71c1aad98031",
                "sha256": "b844d9831b9b1d0bb9d039dffa8efd2af62c869ee97d78ba0aa756bc8e64b44c"
            },
            "downloads": -1,
            "filename": "bosc-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "358b3021ac09620f663f71c1aad98031",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 16564,
            "upload_time": "2024-03-22T17:33:15",
            "upload_time_iso_8601": "2024-03-22T17:33:15.134480Z",
            "url": "https://files.pythonhosted.org/packages/f8/3a/be1cc5546cd1f086f9edea97a98a8e1d56984c5e3034fa60330ceed9992b/bosc-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "79d8d30bfc58d6612f61ed6359a12317fb2f726fcd37e6ff630b9ff495b4683e",
                "md5": "b14a241bb92ee8617f9e06b7dc7f7e2d",
                "sha256": "bca6cd928382f213a56b2843f1a9ab8a4e529c701b15a8b16d8e61d8cdc234f3"
            },
            "downloads": -1,
            "filename": "bosc-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "b14a241bb92ee8617f9e06b7dc7f7e2d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 32566,
            "upload_time": "2024-03-22T17:33:16",
            "upload_time_iso_8601": "2024-03-22T17:33:16.402005Z",
            "url": "https://files.pythonhosted.org/packages/79/d8/d30bfc58d6612f61ed6359a12317fb2f726fcd37e6ff630b9ff495b4683e/bosc-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-22 17:33:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "roman-right",
    "github_project": "bosc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bosc"
}
        
Elapsed time: 0.23035s