Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomasvotava/frantic
Firestore with Pydantic models integration
https://github.com/tomasvotava/frantic
async firestore orm pydantic python
Last synced: 14 days ago
JSON representation
Firestore with Pydantic models integration
- Host: GitHub
- URL: https://github.com/tomasvotava/frantic
- Owner: tomasvotava
- License: mit
- Created: 2022-08-02T14:29:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-28T00:21:14.000Z (almost 2 years ago)
- Last Synced: 2024-10-17T03:44:13.458Z (30 days ago)
- Topics: async, firestore, orm, pydantic, python
- Language: Python
- Homepage: https://tomasvotava.github.io/frantic
- Size: 63.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Frantic
Firestore with Pydantic models integration.
Please note that this module is a work in progress. API may change over time. Also, the code is not tested yet
and there are no security checks run periodically.## Installation
### Using `pip`
```console
pip install frantic
```### Using `poetry`
```console
poetry add frantic
```## Basic usage
If you have your service account key path set in `GOOGLE_APPLICATION_CREDENTIALS`, it's fairly easy:
```python
import asyncio
from typing import ClassVar
from frantic import Frantic, BaseModel# Create a model the same way you would do it with Pydantic
class User(BaseModel):
# optionally, you may specify name of collection instances will be stored within:
collection: ClassVar = "my_users_collection"
# field 'id' is added automatically
name: strasync def main():
frantic = Frantic()user = User(name="ijustfarted")
# Save user in the Firestore db
await frantic.add(user)# user's id gets automatically populated and can be used to retrieve the user
retrieved = await frantic.get(User, user.id)
assert retrieved.name == user.name# list all users
users = await frantic.list(User)# delete user
await frantic.delete(user)
# or
await frantic.delete(User, user.id)if __name__ == "__main__":
asyncio.run(main)
```