Read-only Cloud Firestore REST client library for kiarina namespace
Project description
kiarina-lib-firebase-firestore
English | 日本語
[!NOTE] What is this? An asynchronous read-only package for retrieving documents from Cloud Firestore with a Firebase ID token.
Dependencies
| Package | Version | License |
|---|---|---|
| HTTPX | >=0.28.1 |
BSD-3-Clause |
| Pydantic | >=2.10.6 |
MIT |
| Pydantic Settings | >=2.10.1 |
MIT |
| pydantic-settings-manager | >=3.2.0 |
MIT |
Installation
pip install kiarina-lib-firebase-firestore
Features
- Retrieving a Document Retrieves the document at a path through the Firestore REST API.
- Listing Documents Lists documents in a collection with pagination.
- Decoding Firestore Values
Converts Firestore typed values (such as
integerValue) into Python values. - Read Only by Design Provides no write APIs. Writes are expected to go through the server side (such as an API server).
- Configuring the Client Configures the endpoint and timeout through environment variables or pydantic-settings-manager.
Retrieving a Document
Pass a Firebase ID token obtained through TokenManager (kiarina-lib-firebase) or similar, and the document path.
from kiarina.lib.firebase import TokenManager
from kiarina.lib.firebase_firestore import get_document
token_manager = TokenManager(
api_key="firebase-web-api-key",
refresh_token="firebase-refresh-token",
)
snapshot = await get_document(
"your-project-id",
"users/user_1/posts/post_1",
await token_manager.get_id_token(),
)
if snapshot is not None:
print(snapshot.id, snapshot.fields)
Returns None when the document does not exist. Raises httpx.HTTPStatusError (403) when denied by security rules.
Listing Documents
list_documents lists documents in a collection. By default, documents are returned in document-name order.
from kiarina.lib.firebase_firestore import list_documents
result = await list_documents(
"your-project-id",
"users/user_1/posts",
id_token,
page_size=100,
)
for snapshot in result.documents:
print(snapshot.id, snapshot.fields)
if result.next_page_token is not None:
next_page = await list_documents(
"your-project-id",
"users/user_1/posts",
id_token,
page_size=100,
page_token=result.next_page_token,
)
Configuring the Client
Settings are managed by the single-configuration settings_manager.
kiarina.lib.firebase_firestore:
base_url: https://firestore.googleapis.com
timeout: 30.0
Load the settings at application startup.
import yaml
from pydantic_settings_manager import load_user_configs
from kiarina.lib.firebase_firestore import settings_manager
with open("config.yaml", encoding="utf-8") as file:
load_user_configs(yaml.safe_load(file) or {})
settings = settings_manager.get_settings()
To configure only this package directly, assign values to settings_manager.user_config.
from kiarina.lib.firebase_firestore import settings_manager
settings_manager.user_config = {
"base_url": "http://localhost:8080",
"timeout": 30.0,
}
Environment variables are also supported. Point base_url at a Firestore emulator for local testing.
export KIARINA_LIB_FIREBASE_FIRESTORE_BASE_URL=http://localhost:8080
export KIARINA_LIB_FIREBASE_FIRESTORE_TIMEOUT=30.0
API Reference
kiarina.lib.firebase_firestore
from kiarina.lib.firebase_firestore import (
DocumentList,
DocumentSnapshot,
FirestoreSettings,
get_document,
list_documents,
settings_manager,
)
get_document
async def get_document(
project_id: str,
path: str,
id_token: str,
*,
database_id: str = "(default)",
) -> DocumentSnapshot | None: ...
Retrieves the document at the specified path.
Parameters
project_id(str): Google Cloud project IDpath(str): Document path (e.g."users/user_1/posts/post_1")id_token(str): Firebase ID tokendatabase_id(str): Database ID. Defaults to"(default)"
Returns
DocumentSnapshot | None: The document, orNonewhen it does not exist
Raises
httpx.HTTPStatusError: When the HTTP response indicates an error (except 404)httpx.HTTPError: When communication fails
list_documents
async def list_documents(
project_id: str,
collection_path: str,
id_token: str,
*,
database_id: str = "(default)",
page_size: int | None = None,
page_token: str | None = None,
order_by: str | None = None,
) -> DocumentList: ...
Lists documents in a collection.
Parameters
project_id(str): Google Cloud project IDcollection_path(str): Collection path (e.g."users/user_1/posts")id_token(str): Firebase ID tokendatabase_id(str): Database ID. Defaults to"(default)"page_size(int | None): Maximum number of documents per pagepage_token(str | None): Thenext_page_tokenfrom the previous pageorder_by(str | None): Sort order (e.g."createTime desc")
Returns
DocumentList: A page of documents
Raises
httpx.HTTPStatusError: When the HTTP response indicates an errorhttpx.HTTPError: When communication fails
DocumentSnapshot
@dataclass
class DocumentSnapshot:
name: str
fields: dict[str, Any]
create_time: datetime
update_time: datetime
@property
def path(self) -> str: ...
@property
def id(self) -> str: ...
A document retrieved from Cloud Firestore.
Fields
name(str): Full resource name of the documentfields(dict[str, Any]): Fields converted into Python valuescreate_time(datetime): Creation timeupdate_time(datetime): Update time
Properties
path(str): Path relative to the database root (e.g."users/user_1/posts/post_1")id(str): Document ID (the last segment of the path)
Field values are converted as follows.
| Firestore | Python |
|---|---|
nullValue |
None |
booleanValue |
bool |
integerValue |
int |
doubleValue |
float |
timestampValue |
datetime |
stringValue |
str |
bytesValue |
bytes |
referenceValue |
str (resource name) |
geoPointValue |
dict (latitude / longitude) |
arrayValue |
list |
mapValue |
dict |
DocumentList
@dataclass
class DocumentList:
documents: list[DocumentSnapshot]
next_page_token: str | None
A page of documents listed from a collection.
Fields
documents(list[DocumentSnapshot]): Documents in this pagenext_page_token(str | None): Token for retrieving the next page.Noneon the last page
FirestoreSettings
class FirestoreSettings(BaseSettings):
base_url: str = "https://firestore.googleapis.com"
timeout: float = 30.0
Settings for the Firestore REST client.
Fields
base_url(str): Base URL of the Firestore REST API. Point this at a Firestore emulator for local testingtimeout(float): HTTP request timeout in seconds
settings_manager
settings_manager = SettingsManager(FirestoreSettings)
The SettingsManager for FirestoreSettings.
License
MIT License - See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kiarina_lib_firebase_firestore-2.20.0.tar.gz.
File metadata
- Download URL: kiarina_lib_firebase_firestore-2.20.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce2fe3034a2d6c06f7dbf21e9a8655abd846dc670abada1627f8a82131fb4f6d
|
|
| MD5 |
b0799b91ba288277176fd4718f7200d2
|
|
| BLAKE2b-256 |
627a13081582da1d1a5f6a4cc1eca9dd371ca5d9fd1dcbb9f5d970e427fa7d56
|
Provenance
The following attestation bundles were made for kiarina_lib_firebase_firestore-2.20.0.tar.gz:
Publisher:
release-pypi.yml on kiarina/kiarina-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kiarina_lib_firebase_firestore-2.20.0.tar.gz -
Subject digest:
ce2fe3034a2d6c06f7dbf21e9a8655abd846dc670abada1627f8a82131fb4f6d - Sigstore transparency entry: 2261450690
- Sigstore integration time:
-
Permalink:
kiarina/kiarina-python@4d86c74170de753f408ab309a0c879cc455c35ca -
Branch / Tag:
refs/tags/v2.20.0 - Owner: https://github.com/kiarina
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@4d86c74170de753f408ab309a0c879cc455c35ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file kiarina_lib_firebase_firestore-2.20.0-py3-none-any.whl.
File metadata
- Download URL: kiarina_lib_firebase_firestore-2.20.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84806780784d18815dc56587aafe809e8ce9cc33791a80962e4aa2f9995edff5
|
|
| MD5 |
a0d6a3ccc7e6f5d6bd02103ba7d4dd1d
|
|
| BLAKE2b-256 |
289edd1980826e18663ca776cb8f7dfa973b0828befe99f3e400dcc7d6dd005a
|
Provenance
The following attestation bundles were made for kiarina_lib_firebase_firestore-2.20.0-py3-none-any.whl:
Publisher:
release-pypi.yml on kiarina/kiarina-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kiarina_lib_firebase_firestore-2.20.0-py3-none-any.whl -
Subject digest:
84806780784d18815dc56587aafe809e8ce9cc33791a80962e4aa2f9995edff5 - Sigstore transparency entry: 2261450759
- Sigstore integration time:
-
Permalink:
kiarina/kiarina-python@4d86c74170de753f408ab309a0c879cc455c35ca -
Branch / Tag:
refs/tags/v2.20.0 - Owner: https://github.com/kiarina
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yml@4d86c74170de753f408ab309a0c879cc455c35ca -
Trigger Event:
push
-
Statement type: