Skip to main content

A Firestore-like wrapper for SQL databases.

Project description

FireWrap

FireWrap is a Python library that provides a Firebase Firestore-like interface for SQLite databases. It allows you to perform CRUD operations on collections and documents, making it easier to work with SQLite in a way that resembles Firebase Firestore.

Features

  • Encode and decode column names for SQLite compatibility.
  • Migrate data from Firebase to SQLite.
  • Perform CRUD operations on collections and documents.
  • Support for JSON data storage and retrieval.
  • FireWrapClient: A client class that simplifies database operations with methods for adding, updating, deleting, and querying documents.

Installation

To install FireWrap, install the module:

pip install FireWrap

Usage

Initialize FireWrap

To use FireWrap, you need to create an instance of the FireWrap class, specifying the database path:

from firewrap import FireWrap

db = FireWrap('path/to/your/database.db')

Working with Collections

You can get a reference to a collection and perform operations like adding documents, retrieving documents, and counting documents.

Add a Document

data = {"name": "John Doe", "age": 30}
doc = db.collection("users").addDoc(data)

Get All Documents

docs = db.collection("users").getDocs()

Get a Document by ID

doc = db.collection("users").doc("document_id").getDoc()

Update a Document

update_data = {"age": 31}
db.collection("users").doc("document_id").updateDoc(update_data)

Delete a Document

db.collection("users").doc("document_id").deleteDoc()

FireWrapClient

The FireWrapClient class provides a convenient interface for interacting with the FireWrap database. Here are some of the key methods:

  • get_docs(collection_name, limit=10, offset=0, sortingField=None, order="asc", searchKeywords=[]): Retrieve documents from a specified collection with optional pagination and sorting.
  • add_doc(collection_name, data, id=None): Add a new document to a collection.
  • update_doc(collection_name, doc_id, data): Update an existing document in a collection.
  • delete_doc(collection_name, doc_id): Delete a document from a collection.
  • append_to_array(collection_name, doc_id, array_name, values): Append values to an array field in a document.
  • remove_from_array(collection_name, doc_id, array_name, values): Remove values from an array field in a document.
  • create_collection(collection_name): Create a new collection if it doesn't already exist.
  • get_collection_names(): Retrieve the names of all collections in the database.

API Endpoints

FireWrap also provides a Flask-based API for interacting with the database over HTTP.

  • GET /collections/: Retrieve all documents in a collection.
  • POST /collections/: Add a new document to a collection.
  • GET /collections//<doc_id>: Retrieve a specific document by ID.
  • POST /collections//<doc_id>: Create a new document with a specific ID.
  • PATCH /collections//<doc_id>: Update a specific document.
  • DELETE /collections//<doc_id>: Delete a specific document.
  • GET /collections//count: Get the total number of documents in a collection.
  • GET /collections: Retrieve the names of all collections.
  • POST /collections: Create a new collection.
  • POST /collections//<doc_id>/array: Append values to an array field in a document.
  • DELETE /collections//<doc_id>/array: Remove values from an array field in a document.

Migration from Firebase

To migrate data from Firebase to FireWrap, use the migrate_firebase_to_local_sql function:

from port import migrate_firebase_to_local_sql

migrate_firebase_to_local_sql('path/to/firebase/credentials.json', 'firesql.db')

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Changelog

[0.1.7.3] - 2025-03-05

Fixed

  • try catch added to apply sqlite settings.

[0.1.7.2] - 2025-03-05

Fixed

  • Fixed issue with db not saving isntantly to file.

[0.1.7.1] - 2025-03-05

Fixed

  • Fixed issue with addDoc not working correctly with auto generated IDs.

[0.1.7] - 2025-03-04

Added

  • Initial version of the FireWrapClient class with methods for database operations.

[0.1.6.3] - 2025-03-04

Added

  • Fixed array not initalizing on first doc POST or PATCH

[0.1.6.2] - 2025-03-03

Added

  • Added array method to append or delete an entry from an array field

[0.1.6] - 2025-03-03

Added

  • Added order, limit, offset,sortBy parameters to getDocs method.
  • Added search parameter to getDocs method. (You can search for multiple keywords by separating them with a comma)
  • Pagination added & sorting added while fetching docs

[0.1.5] - 2025-02-24

Added

  • Created endpoints for managing collections:
    • /collection GET: Retrieve collections.
    • /collection POST: Create a new collection.

[0.1.4] - 2025-02-17

Fixed

  • Fixed issue with updateDoc not preserving other fields.
  • Improved JSON encoding/decoding for nested objects.
  • Enhanced performance of database queries.

[0.1.3] - 2025-02-16

Created

  • Initally released on pypi

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

firewrap-0.1.7.3.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

firewrap-0.1.7.3-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file firewrap-0.1.7.3.tar.gz.

File metadata

  • Download URL: firewrap-0.1.7.3.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for firewrap-0.1.7.3.tar.gz
Algorithm Hash digest
SHA256 66e8fe4a31d6002cd5d376ee0dfa9355481a7b632fa3b9164549f4411833814b
MD5 ff06ef2ebc1fc5239d58503ed44c2921
BLAKE2b-256 54ccc15196767db5555fc59bc8600f5c95b8f92b0625e97297752c2ab61e1e54

See more details on using hashes here.

File details

Details for the file firewrap-0.1.7.3-py3-none-any.whl.

File metadata

  • Download URL: firewrap-0.1.7.3-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for firewrap-0.1.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 74dee4e8e569a2b9b7350ed3404493f1ffcdb5e9fc7ee4eb0fc715e15eac1345
MD5 f0e88fc0371b4a8569ebdd84e58ed05e
BLAKE2b-256 8eeb53b1f2dcecad97c5283dc8070928652ac91a5ffbd15b30b9b129fdd01221

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