Skip to main content

An activipy environment to use PostgreSQL as the data store for ActivityStream objects.


The activipy module enables the use of ActivityStreams in your applications and includes the support of different “environments” to extend functionality.

This package provides a “pgsql” environment that maps storage methods to PostgreSQL queries using psycopg2. Object data is stored using the jsonb data type to simplify the schema and provide maximum performance.

Example Code

Open a database:

>>> from activipy import core, vocab
>>> from activipy.pgsql import pgsql
>>> db = pgsql.JsonPgSQL.open(
... host="<db_server>", dbname="<db_name>",
... user="<db_user>", password="<db_user_pass>")
>>> env = pgsql.PgSQLNormalizedEnv

Create a new record and save to database:

>>> post_this = core.ASObj({
...     "@type": "Create",
...     "@id": "http://tsyesika.co.uk/act/foo-id-here/",
...     "actor": {
...         "@type": "Person",
...         "@id": "https://tsyesika.co.uk/",
...         "displayName": "Jessica Tallon"},
...     "to": ["acct:cwebber@identi.ca",
...            "acct:justaguy@rhiaro.co.uk",
...            "acct:ladyaeva@hedgehog.example"],
...     "object": {
...         "@type": "Note",
...         "@id": "https://tsyesika.co.uk/chat/sup-yo/",
...         "content": "Up for some root beer floats?"}},
... pgsql.PgSQLNormalizedEnv)
>>> post_this.m.save(db)
{'@type': 'Create',
 '@id': 'http://tsyesika.co.uk/act/foo-id-here/',
 'actor': 'https://tsyesika.co.uk/',
 'to': ['acct:cwebber@identi.ca',
        'acct:justaguy@rhiaro.co.uk',
        'acct:ladyaeva@hedgehog.example'],
 'object': 'https://tsyesika.co.uk/chat/sup-yo/'}

Note how in this example the record has been normalized. In this environment the actor and object are created in separate records and made into references in the parent record. To retrieve the original denormalized form:

>>> normalized_post = pgsql.pgsql_fetch(
... "http://tsyesika.co.uk/act/foo-id-here/", db, env)
>>> normalized_post.m.denormalize(db)
<ASObj Create "http://tsyesika.co.uk/act/foo-id-here/">
>>> normalized_post.m.denormalize(db).json()
{'to': ['acct:cwebber@identi.ca',
        'acct:justaguy@rhiaro.co.uk',
        'acct:ladyaeva@hedgehog.example'],
 '@id': 'http://tsyesika.co.uk/act/foo-id-here/',
 '@type': 'Create',
 'actor': {'@id': 'https://tsyesika.co.uk/',
           '@type': 'Person',
           'displayName': 'Jessica Tallon'},
 'object': {'@id':
            'https://tsyesika.co.uk/chat/sup-yo/',
            '@type': 'Note',
            'content': 'Up for some root beer floats?}}

Metadata

Release files for activipy-pgsql 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for activipy-pgsql 0.1.0
File Size Uploaded
activipy-pgsql-0.1.0.tar.gz 22.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for activipy-pgsql 0.1.0
File Interpreter ABI Platform
activipy_pgsql-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 30.2 kB

Release files / activipy-pgsql-0.1.0.tar.gz

Download URL activipy-pgsql-0.1.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
66ae6a68cb40aa07a7903291481de8c8a7fac37e88b3f9c8f072857ba0d8d9c5
BLAKE2b-256 checksum
How to use checksums
7464b20b983aff690556c0e87d6f06c2faa2eb1ea5de234110a7412f13775eb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / activipy_pgsql-0.1.0-py2.py3-none-any.whl

Download URL activipy_pgsql-0.1.0-py2.py3-none-any.whl
Size 7.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fa9bd4f214fb69a36c310fc87ed503ffdc7db2a31406ffc6a4024fc5314741ce
BLAKE2b-256 checksum
How to use checksums
4d323c0e354087ce60ab671a173e1980e25304a4fb63989f6ada48c7ac0e9cc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page