Skip to main content

A wrapper for sqlite3 to have schemaless, document-store features

Project description

neosqlite

neosqlite (new + nosqlite) is a pure Python library that provides a schemaless, pymongo-like wrapper for interacting with SQLite databases. The API is designed to be familiar to those who have worked with pymongo, providing a simple and intuitive way to work with document-based data in a relational database.

Features

  • pymongo-like API: A familiar interface for developers experienced with MongoDB.
  • Schemaless Documents: Store flexible JSON-like documents.
  • Lazy Cursor: find() returns a memory-efficient cursor for iterating over results.
  • Advanced Indexing: Supports single-key, compound-key, and nested-key indexes.
  • Modern API: Aligned with modern pymongo practices (using methods like insert_one, update_one, delete_many, etc.).

Quickstart

Here is a quick example of how to use neosqlite:

import neosqlite

# Connect to an in-memory database
with neosqlite.Connection(':memory:') as conn:
    # Get a collection
    users = conn.users

    # Insert a single document
    users.insert_one({'name': 'Alice', 'age': 30})

    # Insert multiple documents
    users.insert_many([
        {'name': 'Bob', 'age': 25},
        {'name': 'Charlie', 'age': 35}
    ])

    # Find a single document
    alice = users.find_one({'name': 'Alice'})
    print(f"Found user: {alice}")

    # Find multiple documents and iterate using the cursor
    print("\nAll users:")
    for user in users.find():
        print(user)

    # Update a document
    users.update_one({'name': 'Alice'}, {'$set': {'age': 31}})
    print(f"\nUpdated Alice's age: {users.find_one({'name': 'Alice'})}")

    # Delete documents
    result = users.delete_many({'age': {'$gt': 30}})
    print(f"\nDeleted {result.deleted_count} users older than 30.")

    # Count remaining documents
    print(f"There are now {users.count_documents({})} users.")

Indexes

Indexes can significantly speed up query performance. neosqlite supports single-key, compound-key, and nested-key indexes.

# Create a single-key index
users.create_index('age')

# Create a compound index
users.create_index([('name', neosqlite.ASCENDING), ('age', neosqlite.DESCENDING)])

# Create an index on a nested key
users.insert_one({'name': 'David', 'profile': {'followers': 100}})
users.create_index('profile.followers')

Indexes are automatically used by find() operations where possible. You can also provide a hint to force the use of a specific index.

Sorting

You can sort the results of a find() query by chaining the sort() method.

# Sort users by age in descending order
for user in users.find().sort('age', neosqlite.DESCENDING):
    print(user)

Contribution and License

This project was originally developed by Shaun Duncan and is now maintained by Chaiwat Suttipongsakul. It is licensed under the MIT license.

Contributions are highly encouraged. If you find a bug, have an enhancement in mind, or want to suggest a new feature, please feel free to open an issue or submit a pull request.

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

neosqlite-0.1.3.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

neosqlite-0.1.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file neosqlite-0.1.3.tar.gz.

File metadata

  • Download URL: neosqlite-0.1.3.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.6.30-android15-8-g94c1a24cabd5-ab12293704-4k

File hashes

Hashes for neosqlite-0.1.3.tar.gz
Algorithm Hash digest
SHA256 265bf8796b777296bf2226ad9be1c6178dce9f76ddcfdf35f2d0998e89cd3fb6
MD5 fc161c76bf068e6142064191d37d0a53
BLAKE2b-256 d1f8dd6c71ba19acae9d9279c9b7f5dfc6c4c3086bfd877d575b452b951c0cc8

See more details on using hashes here.

File details

Details for the file neosqlite-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: neosqlite-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.11 Linux/6.6.30-android15-8-g94c1a24cabd5-ab12293704-4k

File hashes

Hashes for neosqlite-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fead1b1a0bf5d30bced57a9e2b3fde3049db34edf3e27128acc91c0dd4627700
MD5 f864f07f3e9c6e241cf66c170d847957
BLAKE2b-256 44124385a0523d057a349aac8abb8a17839dd490d52594b94667f4ed3a506553

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