{"id":9853,"library":"jupysql","title":"JupySQL","description":"JupySQL (version 0.11.1) enhances SQL interaction within Jupyter notebooks, allowing users to connect to various databases and execute queries directly using IPython magic commands. It supports advanced features like variable interpolation, caching, and data visualization. The project is actively maintained with frequent releases, typically every few weeks.","status":"active","version":"0.11.1","language":"en","source_language":"en","source_url":"https://github.com/ploomber/jupysql","tags":["jupyter","sql","database","ipython","data science","magic commands"],"install":[{"cmd":"pip install jupysql","lang":"bash","label":"Core Installation"},{"cmd":"pip install jupysql[postgres]","lang":"bash","label":"With PostgreSQL Support (Example)"}],"dependencies":[{"reason":"Core ORM and SQL toolkit used for database connectivity.","package":"sqlalchemy","optional":false},{"reason":"PostgreSQL driver. Install via `jupysql[postgres]` extra.","package":"psycopg2","optional":true},{"reason":"MySQL driver. Install via `jupysql[mysql]` extra.","package":"pymysql","optional":true}],"imports":[{"note":"JupySQL functionality is primarily exposed via IPython magic commands, which must be loaded using this extension.","wrong":"import jupysql","symbol":"%load_ext sql","correct":"%load_ext sql"},{"note":"Used for global configuration of JupySQL settings.","symbol":"jupysql.configure","correct":"import jupysql\njupysql.configure(result_limit=100)"},{"note":"For programmatic configuration and access to plotting functions.","symbol":"jupysql.plot","correct":"from jupysql import plot\nplot.configure_styles(template='ggplot')"}],"quickstart":{"code":"# Load the JupySQL extension\n%load_ext sql\n\n# Connect to an in-memory SQLite database\n%sql sqlite:///:memory:\n\n# Create a table and insert some data\n%%sql\nCREATE TABLE employees (\n    id INTEGER PRIMARY KEY,\n    name TEXT,\n    department TEXT,\n    salary INTEGER\n);\nINSERT INTO employees (id, name, department, salary) VALUES\n    (1, 'Alice', 'Sales', 50000),\n    (2, 'Bob', 'Marketing', 60000),\n    (3, 'Charlie', 'Sales', 55000);\n\n# Query the data\n%sql SELECT * FROM employees WHERE department = 'Sales';","lang":"python","description":"This quickstart demonstrates how to load the JupySQL extension, connect to an in-memory SQLite database, create a table, insert data, and execute a simple SQL query using the `%sql` and `%%sql` magic commands."},"warnings":[{"fix":"Update your `jupysql.configure` calls:\n- Replace `display_limit` with `result_limit`.\n- For style configuration, use `from jupysql import plot; plot.configure_styles(...)`.","message":"The `jupysql.configure` function's arguments `display_limit` and `style` were changed. `display_limit` was renamed to `result_limit`, and `style` was moved to `jupysql.plot.configure_styles`.","severity":"breaking","affected_versions":"Prior to 0.10.0"},{"fix":"Always include `%load_ext sql` as the first line in your Jupyter notebooks or when starting an interactive IPython session where you intend to use JupySQL magic commands.","message":"JupySQL's primary functionality relies on IPython magic commands (`%sql`, `%%sql`). These require `%load_ext sql` to be run at the beginning of each new notebook or IPython session.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When embedding Python variables into SQL queries, use the double curly brace syntax: `my_var = 'Sales'; %sql SELECT * FROM employees WHERE department = '{{my_var}}'`.","message":"JupySQL uses `{{variable}}` syntax for Python variable interpolation within SQL queries, which differs from standard f-strings or `.format()` methods.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install jupysql` in your terminal or notebook environment.","cause":"The jupysql package is not installed in the current environment.","error":"ModuleNotFoundError: No module named 'jupysql'"},{"fix":"Add `%load_ext sql` at the beginning of your notebook or session before using any `%sql` or `%%sql` commands.","cause":"The JupySQL IPython extension (`%load_ext sql`) has not been loaded, so the magic commands are not available.","error":"NameError: name 'sql' is not defined"},{"fix":"Verify that your database server is running, the database 'mydb' exists, and the connection string `%sql postgresql://user:password@localhost:5432/mydb` is correct. Also, ensure the necessary database driver (e.g., `psycopg2`) is installed via `pip install jupysql[postgres]`.","cause":"The database specified in the connection string does not exist, the server is not running, or connection details are incorrect.","error":"OperationalError: (psycopg2.OperationalError) connection to server at \"localhost\" (127.0.0.1), port 5432 failed: FATAL: database \"mydb\" does not exist"},{"fix":"Replace `display_limit` with `result_limit` in your `jupysql.configure` call. If you were configuring styles, use `from jupysql import plot; plot.configure_styles(...)` instead.","cause":"You are using `jupysql.configure` with an argument that was renamed in version 0.10.0.","error":"TypeError: configure() got an unexpected keyword argument 'display_limit'"}]}