A project to integrate Google Ads API with MongoDB session management
Project description
ADK MongoDB Session
A session management library for the Google ADK framework that uses MongoDB as a backend.
This package provides a MongodbSessionService that implements the google.adk.sessions.base_session_service.BaseSessionService abstract base class, allowing you to store and manage session state in a MongoDB database.
Installation
To install the package, you can use pip to install it directly from the source:
pip install .
For development, you can install it in editable mode with the testing dependencies:
pip install -e ".[test]"
Usage
First, you need to instantiate the MongodbSessionService with your MongoDB connection details.
from adk-mongodb-session.adk.mongodb.sessions.mongodb_session_service import MongodbSessionService
# Initialize the service
session_service = MongodbSessionService(
db_url="mongodb://localhost:27017/",
database="my_adk_app",
collection_prefix="sessions"
)
Now you can use the service to create, retrieve, list, and delete sessions.
Creating a Session
import asyncio
async def main():
# Create a new session
new_session = await session_service.create_session(
app_name="my_app",
user_id="user_123",
state={"initial_key": "initial_value"}
)
print(f"Created session with ID: {new_session.id}")
if __name__ == "__main__":
asyncio.run(main())
Retrieving a Session
import asyncio
async def main():
# Get a session by ID
session = await session_service.get_session(
app_name="my_app",
user_id="user_123",
session_id="<your_session_id>"
)
if session:
print(f"Retrieved session state: {session.state}")
if __name__ == "__main__":
asyncio.run(main())
Tiered State Management
The service automatically handles the three-tiered state (app, user, and session). When you create or update a session, you can provide state keys with the prefixes app: and user: to store data at the corresponding level.
import asyncio
from google.adk.sessions.state import State
async def main():
# Create a session with tiered state
session = await session_service.create_session(
app_name="my_app",
user_id="user_123",
state={
f"{State.APP_PREFIX}theme": "dark",
f"{State.USER_PREFIX}language": "en",
"session_specific_data": "foo"
}
)
# The session object will have a merged view of the state
print(session.state)
# {
# 'app:theme': 'dark',
# 'user:language': 'en',
# 'session_specific_data': 'foo'
# }
if __name__ == "__main__":
asyncio.run(main())
Running Tests
To run the tests, first install the testing dependencies:
pip install -e ".[test]"
Then, run the tests using unittest:
python -m unittest discover tests
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 adk_mongodb_session-0.1.0.tar.gz.
File metadata
- Download URL: adk_mongodb_session-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a992357fdf2249341f7cebb0060349bfca87573dac2da2d374634831457ba6e9
|
|
| MD5 |
2e421493cdea4c6cf9db8de0c01e701b
|
|
| BLAKE2b-256 |
49bcbd79ce98c09645fd84f81f7d0fba23fe79017e4ce50dcfa12921ca751ee3
|
Provenance
The following attestation bundles were made for adk_mongodb_session-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on SergeySetti/adk-mongodb-session
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adk_mongodb_session-0.1.0.tar.gz -
Subject digest:
a992357fdf2249341f7cebb0060349bfca87573dac2da2d374634831457ba6e9 - Sigstore transparency entry: 597859994
- Sigstore integration time:
-
Permalink:
SergeySetti/adk-mongodb-session@ada3970d6e742d23f48c5301a7421e2793c70d73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/SergeySetti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ada3970d6e742d23f48c5301a7421e2793c70d73 -
Trigger Event:
release
-
Statement type:
File details
Details for the file adk_mongodb_session-0.1.0-py3-none-any.whl.
File metadata
- Download URL: adk_mongodb_session-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e207b2ede7cc1d833e43b606638a0aa0c8be21fc8785407f35a0c59954a05bc
|
|
| MD5 |
6fc3888e60e64faf96dbf971fef5f78a
|
|
| BLAKE2b-256 |
768aa06f59714127ecf69cc379c75917fd6714a23a7d2983419da0c36bf8f9cf
|
Provenance
The following attestation bundles were made for adk_mongodb_session-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on SergeySetti/adk-mongodb-session
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adk_mongodb_session-0.1.0-py3-none-any.whl -
Subject digest:
0e207b2ede7cc1d833e43b606638a0aa0c8be21fc8785407f35a0c59954a05bc - Sigstore transparency entry: 597859995
- Sigstore integration time:
-
Permalink:
SergeySetti/adk-mongodb-session@ada3970d6e742d23f48c5301a7421e2793c70d73 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/SergeySetti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ada3970d6e742d23f48c5301a7421e2793c70d73 -
Trigger Event:
release
-
Statement type: