Databases#

Q: How do I list all databases?

sorted(bd.databases)

Q: How do I test if a given database is installed?

'<my database label>' in bd.databases

Q: How do I instantiate a Database object?

my_db = bd.Database('<database_name>')

Q: How do I copy a Database?

copied_database = bd.Database('<database_name>').copy('<new_name>')

Q: How do I rename a Database?

new_database = bd.Database('<database_name>').rename('<new_name>')

Q: How do I delete a Database?

del bd.databases['<database_name>']

Metadata#

Q: How do I see the Database metadata?

bd.Database('<database_name>').metadata

Q: How do I change the Database metadata?

bd.Database('<database_name>').metadata['<some_key>'] = '<some_value>'

Q: How do I see which other databases this Database refers to?

bd.Database('<database_name>').metadata['depends']

Q: How can I see what kind of modelling paradigm and storage engine a Database uses?

This information is given to a limited degree by the database backend:

bd.Database('<database_name>').metadata['backend']

There are three backends in a normal Brightway installation:

  • sqlite: The default backend. Uses SQLite like a graph database.

  • iotable: Uses the SQLite database for nodes, but stores edges only in datapackages. Limits edges to a single numerical value without uncertainty, but gives better performance for large IO data.

  • multifunctional: Stores multifunctional processes as a custom node type, and automatically allocates following the given database or process preferences when creating datapackages.

Searching#

Q: How do I search a Database?

bd.Database('<database_name>').search('<my_query_string>')

See bw2data.backends.base.SQLiteBackend.search for documentation and function options.

Datapackages#

Q: How do I get the bw_processing datapackage for this Database?

bd.Database('<database_name>').datapackage()