Library needs access to postgress

I want to use a library rdflib-sqlalchemy that needs access to the Postgress instance. Is this possible?

Alternatively, the library also works with sqlite, would that be able to write to the anvil disk?

Here is a snippet of how it accesses sqlite:

from rdflib import plugin, ConjunctiveGraph, Literal, URIRef
from rdflib.store import Store

from rdflib_sqlalchemy import registerplugins

registerplugins()


ident = URIRef("http://example.com/rdflib_test")
uri = Literal("sqlite:///db2")

store = plugin.get("SQLAlchemy", Store)(identifier=ident)
graph = ConjunctiveGraph(store, identifier=ident)
graph.open(uri)
# do stuff with graph
graph.close()

The snippet works with a sqlite file db2 in the current directory.

Hi Simon,

I see three options, any of which will work for you:

  1. You can get direct access to your own dedicated Anvil Postgres database if you’re on a Dedicated Plan or higher.

  2. You could spin up a Postgres database in Amazon RDS or ElephantSQL or similar, and access it from your Anvil app with the usual libraries (psycopg2)

  3. You can run a sqlite database locally on the server, as a speed optimisation – although files in your Anvil server environment are ephemeral, so don’t rely on it sticking around.

1 Like

Adding to @meredydd’s comment:

  1. If you need libraries that aren’t available in the Anvil runtime, you can use an Uplink to run an external server module that accesses your database directly (which could be any of RDS, ElephantSQL, etc).
1 Like