django-firebase-orm


Namedjango-firebase-orm JSON
Version 0.4 PyPI version JSON
download
home_pagehttps://github.com/TralahM/firebase_orm
SummaryNoSQL object model database for django ORM integration
upload_time2020-10-18 06:43:38
maintainer
docs_urlNone
authorTralah M Brian
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[![Build Status](https://travis-ci.com/TralahM/django-firebase-orm.svg?branch=master)](https://travis-ci.com/TralahM/django-firebase-orm)
[![Build status](https://ci.appveyor.com/api/projects/status/yvvmq5hyf7hj743a/branch/master?svg=true)](https://ci.appveyor.com/project/TralahM/django-firebase-orm/branch/master)
[![Documentation Status](https://readthedocs.org/projects/django-firebase-orm/badge/?version=latest)](https://django-firebase-orm.readthedocs.io/en/latest/?badge=latest)
[![License: GPLv3](https://img.shields.io/badge/License-GPLV2-green.svg)](https://opensource.org/licenses/GPLV2)
[![Organization](https://img.shields.io/badge/Org-TralahTek-blue.svg)](https://github.com/TralahTek)
[![Views](http://hits.dwyl.io/TralahM/django-firebase-orm.svg)](http://dwyl.io/TralahM/django-firebase-orm)
[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](https://github.com/TralahM/django-firebase-orm/pull/)
[![GitHub pull-requests](https://img.shields.io/badge/Issues-pr-red.svg?style=flat-square)](https://github.com/TralahM/django-firebase-orm/pull/)
[![Language](https://img.shields.io/badge/Language-python-3572A5.svg)](https://github.com/TralahM)
<img title="Watching" src="https://img.shields.io/github/watchers/TralahM/django-firebase-orm?label=Watchers&color=blue&style=flat-square">
<img title="Stars" src="https://img.shields.io/github/stars/TralahM/django-firebase-orm?color=red&style=flat-square">
<img title="Forks" src="https://img.shields.io/github/forks/TralahM/django-firebase-orm?color=green&style=flat-square">

# django-firebase-orm.

Django like models for NoSQL database Firestore Integrating with
django\'s ORM. This is a fork and improvement of
[firebase_orm](https://github.com/joewalk102/firebase-orm) project which
was initially forked from [xavx0z](https://github.com/xavx0z) and
stopped maintaining it.

I made a few changes and improvements to suit my liking:

1.  Changed the need of creating a second settings.py file in the root
    of your django project to now only require that you define the
    neccessary configurations in your project\'s settings module. *Note
    that django is now an explicit dependency*
2.  Created a new package for this app on pypi under
    **django-firebase-orm**

It is my desire to continue the development of this project and thus
welcome all developers wishing to contribute via improving
documentation, bug fixes, test coverage, new features, etc.

Installation
------------

```shell
$ pip install django-firebase-orm
```

Initialize
----------

In your project settings add the following configuration variables

> settings.py
>
```python
FIREBASE_ORM_CERTIFICATE = 'path/to/serviceAccountKey.json'
FIREBASE_ORM_BUCKET_NAME = '<BUCKET_NAME>.appspot.com'
```

FIREBASE_ORM_CERTIFICATE

:   Once you have created a [Firebase
    console](https://console.firebase.google.com/?authuser=0) project
    and downloaded a JSON file with your service account credentials.

FIREBASE_ORM_BUCKET_NAME

:   The bucket name must not contain gs:// or any other protocol
    prefixes. For example, if the bucket URL displayed in the [Firebase
    console](https://console.firebase.google.com/?authuser=0) is
    gs://bucket-name.appspot.com, pass the string
    bucket-name.appspot.com

Usage
-----

### Create model:

```python
from firebase_orm import models


class Article(models.Model):
    headline = models.TextField()
    type_article = models.TextField(db_column='type')

    class Meta:
        db_table = 'medications'

    def __str__(self):
        return self.headline
```

### Using The API:

**Creating objects**

To represent cloud firestore data in Python objects, FirebaseORM uses an
intuitive system: A *model* *class* represents a *collection*, and an
*instance* of that class represents a *document* in collection.

To create an object, instantiate it using keyword arguments to the model
class, then call save() to save it to the database.

```pycon
# Import the models we created
>>> from models import Article
# Create a new Article.
>>> a = Article(headline='Django is cool')
# Save the object into the database. You have to call save() explicitly.
>>> a.save()
```

**Retrieving all objects**

The simplest way to retrieve documents from a collections is to get all
of them. To do this, use the all() method on a Manager as you would in
normal django:

```pycon
>>> all_Article = Article.objects.all()
```

The all() method returns a list instance Article of all the collection
in the database.

```pycon
# Now it has an ID.
>>> a.id
1
# Fields are represented as attributes on the Python object.
>>> a.headline
'Django is cool'
```

**Saving changes to objects**

To save changes to an object that's already in the database, use save().

Given a Article instance a that has already been saved to the database,
this example changes its name and updates its record in the database:

```pycon
>>> a.headline = 'Django-Firebase-ORM is awesome'
>>> a.save()
```

This performs an document.update() method behind the scenes. FirebaseORM
doesn't hit the database until you explicitly call save().

```pycon
# Firebase ORM provides a rich database lookup API.
>>> Article.objects.get(id=1)
<Article: Django-Firebase-ORM is awesome>
>>> Article.objects.get(id=2)
Traceback (most recent call last):
    ...
DoesNotExist: Article matching query does not exist.
```

Field options:
--------------

The following arguments are available to all field types. All are
optional.

**Field.db_column**

> If contains characters that aren't allowed in Python variable names --
> use db_column. The name of the firestore key in document to use for
> this field. If this isn't given, FirebaseORM will use the field's
> name.

Field types:
------------

### AutoField

**class AutoField()**

> By default, FirebaseORM gives each model the following field:
>

```python
id = models.AutoField(primary_key=True)
```

### TextField

**class TextField(**options)\*\*

> Text string Up to 1,048,487 bytes (1 MiB - 89 bytes). Only the first
> 1,500 bytes of the UTF-8 representation are considered by queries.
>
> TextField has not extra required argument.

Dependencies
------------

1.  *firebase-admin*
2.  *grpcio*
3.  *django*

## Building from Source for Developers

```console
$ git clone https://github.com/TralahM/django-firebase-orm.git
$ cd django-firebase-orm
```

# Contributing
[See the Contributing File](CONTRIBUTING.rst)


[See the Pull Request File](PULL_REQUEST_TEMPLATE.md)

# LICENCE

[Read the license here](LICENSE)

CREDITS
-------

Thanks to [joewalk102](https://github.com/joewalk102) for forking the
original project without whom this project would not be possible.

[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-black.svg?style=for-the-badge&logo=github)](https://github.com/TralahTek)
[![TralahM](https://img.shields.io/badge/Engineer-TralahM-blue.svg?style=for-the-badge&logo=github)](https://github.com/TralahM)
[![TralahM](https://img.shields.io/badge/Maintainer-TralahM-green.svg?style=for-the-badge&logo=github)](https://github.com/TralahM)


# Self-Promotion

[![](https://img.shields.io/badge/Github-TralahM-green?style=for-the-badge&logo=github)](https://github.com/TralahM)
[![](https://img.shields.io/badge/Twitter-%40tralahtek-red?style=for-the-badge&logo=twitter)](https://twitter.com/TralahM)
[![TralahM](https://img.shields.io/badge/Kaggle-TralahM-purple.svg?style=for-the-badge&logo=kaggle)](https://kaggle.com/TralahM)
[![TralahM](https://img.shields.io/badge/LinkedIn-TralahM-red.svg?style=for-the-badge&logo=linkedin)](https://linkedin.com/in/TralahM)


[![Blog](https://img.shields.io/badge/Blog-tralahm.tralahtek.com-blue.svg?style=for-the-badge&logo=rss)](https://tralahm.tralahtek.com)

[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-cyan.svg?style=for-the-badge)](https://org.tralahtek.com)





            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TralahM/firebase_orm",
    "name": "django-firebase-orm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tralah M Brian",
    "author_email": "musyoki.brian@tralahtek.com",
    "download_url": "https://files.pythonhosted.org/packages/cc/61/cc669e859cc087d1a66bcd91a6fd0d61354030e2e7377f96ce72db7862f8/django-firebase-orm-0.4.tar.gz",
    "platform": "",
    "description": "\n[![Build Status](https://travis-ci.com/TralahM/django-firebase-orm.svg?branch=master)](https://travis-ci.com/TralahM/django-firebase-orm)\n[![Build status](https://ci.appveyor.com/api/projects/status/yvvmq5hyf7hj743a/branch/master?svg=true)](https://ci.appveyor.com/project/TralahM/django-firebase-orm/branch/master)\n[![Documentation Status](https://readthedocs.org/projects/django-firebase-orm/badge/?version=latest)](https://django-firebase-orm.readthedocs.io/en/latest/?badge=latest)\n[![License: GPLv3](https://img.shields.io/badge/License-GPLV2-green.svg)](https://opensource.org/licenses/GPLV2)\n[![Organization](https://img.shields.io/badge/Org-TralahTek-blue.svg)](https://github.com/TralahTek)\n[![Views](http://hits.dwyl.io/TralahM/django-firebase-orm.svg)](http://dwyl.io/TralahM/django-firebase-orm)\n[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](https://github.com/TralahM/django-firebase-orm/pull/)\n[![GitHub pull-requests](https://img.shields.io/badge/Issues-pr-red.svg?style=flat-square)](https://github.com/TralahM/django-firebase-orm/pull/)\n[![Language](https://img.shields.io/badge/Language-python-3572A5.svg)](https://github.com/TralahM)\n<img title=\"Watching\" src=\"https://img.shields.io/github/watchers/TralahM/django-firebase-orm?label=Watchers&color=blue&style=flat-square\">\n<img title=\"Stars\" src=\"https://img.shields.io/github/stars/TralahM/django-firebase-orm?color=red&style=flat-square\">\n<img title=\"Forks\" src=\"https://img.shields.io/github/forks/TralahM/django-firebase-orm?color=green&style=flat-square\">\n\n# django-firebase-orm.\n\nDjango like models for NoSQL database Firestore Integrating with\ndjango\\'s ORM. This is a fork and improvement of\n[firebase_orm](https://github.com/joewalk102/firebase-orm) project which\nwas initially forked from [xavx0z](https://github.com/xavx0z) and\nstopped maintaining it.\n\nI made a few changes and improvements to suit my liking:\n\n1.  Changed the need of creating a second settings.py file in the root\n    of your django project to now only require that you define the\n    neccessary configurations in your project\\'s settings module. *Note\n    that django is now an explicit dependency*\n2.  Created a new package for this app on pypi under\n    **django-firebase-orm**\n\nIt is my desire to continue the development of this project and thus\nwelcome all developers wishing to contribute via improving\ndocumentation, bug fixes, test coverage, new features, etc.\n\nInstallation\n------------\n\n```shell\n$ pip install django-firebase-orm\n```\n\nInitialize\n----------\n\nIn your project settings add the following configuration variables\n\n> settings.py\n>\n```python\nFIREBASE_ORM_CERTIFICATE = 'path/to/serviceAccountKey.json'\nFIREBASE_ORM_BUCKET_NAME = '<BUCKET_NAME>.appspot.com'\n```\n\nFIREBASE_ORM_CERTIFICATE\n\n:   Once you have created a [Firebase\n    console](https://console.firebase.google.com/?authuser=0) project\n    and downloaded a JSON file with your service account credentials.\n\nFIREBASE_ORM_BUCKET_NAME\n\n:   The bucket name must not contain gs:// or any other protocol\n    prefixes. For example, if the bucket URL displayed in the [Firebase\n    console](https://console.firebase.google.com/?authuser=0) is\n    gs://bucket-name.appspot.com, pass the string\n    bucket-name.appspot.com\n\nUsage\n-----\n\n### Create model:\n\n```python\nfrom firebase_orm import models\n\n\nclass Article(models.Model):\n    headline = models.TextField()\n    type_article = models.TextField(db_column='type')\n\n    class Meta:\n        db_table = 'medications'\n\n    def __str__(self):\n        return self.headline\n```\n\n### Using The API:\n\n**Creating objects**\n\nTo represent cloud firestore data in Python objects, FirebaseORM uses an\nintuitive system: A *model* *class* represents a *collection*, and an\n*instance* of that class represents a *document* in collection.\n\nTo create an object, instantiate it using keyword arguments to the model\nclass, then call save() to save it to the database.\n\n```pycon\n# Import the models we created\n>>> from models import Article\n# Create a new Article.\n>>> a = Article(headline='Django is cool')\n# Save the object into the database. You have to call save() explicitly.\n>>> a.save()\n```\n\n**Retrieving all objects**\n\nThe simplest way to retrieve documents from a collections is to get all\nof them. To do this, use the all() method on a Manager as you would in\nnormal django:\n\n```pycon\n>>> all_Article = Article.objects.all()\n```\n\nThe all() method returns a list instance Article of all the collection\nin the database.\n\n```pycon\n# Now it has an ID.\n>>> a.id\n1\n# Fields are represented as attributes on the Python object.\n>>> a.headline\n'Django is cool'\n```\n\n**Saving changes to objects**\n\nTo save changes to an object that's already in the database, use save().\n\nGiven a Article instance a that has already been saved to the database,\nthis example changes its name and updates its record in the database:\n\n```pycon\n>>> a.headline = 'Django-Firebase-ORM is awesome'\n>>> a.save()\n```\n\nThis performs an document.update() method behind the scenes. FirebaseORM\ndoesn't hit the database until you explicitly call save().\n\n```pycon\n# Firebase ORM provides a rich database lookup API.\n>>> Article.objects.get(id=1)\n<Article: Django-Firebase-ORM is awesome>\n>>> Article.objects.get(id=2)\nTraceback (most recent call last):\n    ...\nDoesNotExist: Article matching query does not exist.\n```\n\nField options:\n--------------\n\nThe following arguments are available to all field types. All are\noptional.\n\n**Field.db_column**\n\n> If contains characters that aren't allowed in Python variable names --\n> use db_column. The name of the firestore key in document to use for\n> this field. If this isn't given, FirebaseORM will use the field's\n> name.\n\nField types:\n------------\n\n### AutoField\n\n**class AutoField()**\n\n> By default, FirebaseORM gives each model the following field:\n>\n\n```python\nid = models.AutoField(primary_key=True)\n```\n\n### TextField\n\n**class TextField(**options)\\*\\*\n\n> Text string Up to 1,048,487 bytes (1 MiB - 89 bytes). Only the first\n> 1,500 bytes of the UTF-8 representation are considered by queries.\n>\n> TextField has not extra required argument.\n\nDependencies\n------------\n\n1.  *firebase-admin*\n2.  *grpcio*\n3.  *django*\n\n## Building from Source for Developers\n\n```console\n$ git clone https://github.com/TralahM/django-firebase-orm.git\n$ cd django-firebase-orm\n```\n\n# Contributing\n[See the Contributing File](CONTRIBUTING.rst)\n\n\n[See the Pull Request File](PULL_REQUEST_TEMPLATE.md)\n\n# LICENCE\n\n[Read the license here](LICENSE)\n\nCREDITS\n-------\n\nThanks to [joewalk102](https://github.com/joewalk102) for forking the\noriginal project without whom this project would not be possible.\n\n[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-black.svg?style=for-the-badge&logo=github)](https://github.com/TralahTek)\n[![TralahM](https://img.shields.io/badge/Engineer-TralahM-blue.svg?style=for-the-badge&logo=github)](https://github.com/TralahM)\n[![TralahM](https://img.shields.io/badge/Maintainer-TralahM-green.svg?style=for-the-badge&logo=github)](https://github.com/TralahM)\n\n\n# Self-Promotion\n\n[![](https://img.shields.io/badge/Github-TralahM-green?style=for-the-badge&logo=github)](https://github.com/TralahM)\n[![](https://img.shields.io/badge/Twitter-%40tralahtek-red?style=for-the-badge&logo=twitter)](https://twitter.com/TralahM)\n[![TralahM](https://img.shields.io/badge/Kaggle-TralahM-purple.svg?style=for-the-badge&logo=kaggle)](https://kaggle.com/TralahM)\n[![TralahM](https://img.shields.io/badge/LinkedIn-TralahM-red.svg?style=for-the-badge&logo=linkedin)](https://linkedin.com/in/TralahM)\n\n\n[![Blog](https://img.shields.io/badge/Blog-tralahm.tralahtek.com-blue.svg?style=for-the-badge&logo=rss)](https://tralahm.tralahtek.com)\n\n[![TralahTek](https://img.shields.io/badge/Organization-TralahTek-cyan.svg?style=for-the-badge)](https://org.tralahtek.com)\n\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "NoSQL object model database for django ORM integration",
    "version": "0.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9474c5c02f730365dc04351b674aa25f",
                "sha256": "41ffb072466abc0e57a5b3a1f0565a0a99368feff512e814dfdb73eddbddaf18"
            },
            "downloads": -1,
            "filename": "django_firebase_orm-0.4-py36-none-any.whl",
            "has_sig": false,
            "md5_digest": "9474c5c02f730365dc04351b674aa25f",
            "packagetype": "bdist_wheel",
            "python_version": "py36",
            "requires_python": null,
            "size": 20765,
            "upload_time": "2020-10-18T06:43:36",
            "upload_time_iso_8601": "2020-10-18T06:43:36.418784Z",
            "url": "https://files.pythonhosted.org/packages/e2/5e/47b6a1738fab482e3059c6b9e359df0865a0b0edaec79936ba1c72bfcd6b/django_firebase_orm-0.4-py36-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "3d30fc63c651668680cfd4f00164f081",
                "sha256": "7c02445af263f9832bd880b755f277254d4a490cd57dc116c980ddbd103e38dc"
            },
            "downloads": -1,
            "filename": "django-firebase-orm-0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "3d30fc63c651668680cfd4f00164f081",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8074,
            "upload_time": "2020-10-18T06:43:38",
            "upload_time_iso_8601": "2020-10-18T06:43:38.155442Z",
            "url": "https://files.pythonhosted.org/packages/cc/61/cc669e859cc087d1a66bcd91a6fd0d61354030e2e7377f96ce72db7862f8/django-firebase-orm-0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-10-18 06:43:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "TralahM",
    "error": "Could not fetch GitHub repository",
    "lcname": "django-firebase-orm"
}
        
Elapsed time: 0.15235s