CluedIn Magic
On this page
IPython, the command shell behind Jupyter notebooks, provides an awesome feature called magics. In short, you can skip writing Python code and use more like command line syntax. This approach can simplify many repeating tasks, including work with CluedIn Python SDK.
In this article, we want to introduce you to CluedIn Magic – the package that lets you work with CluedIn API with minimal code.
Install CluedIn Magic
-
CluedIn Magic depends on CluedIn Python SDK, so you only need to install one package to get them both:
%pip install cluedin-magicWhen working with products like Microsoft Fabric, Synapse Analytics, Databricks, and so on, we usually pre-install packages in an environment so that there is no need to run the line above.
-
We can now load CluedIn Magic by calling the
%load_extmagic:%load_ext cluedin_magic -
After this, you can call
%cluedinmagic. If you do it without parameters or with wrong parameters, it will provide you with brief help instructions:Available commands: get-context, search Usage: %cluedin get-context --jwt <jwt> %cluedin search --context <context> --query <query> [--limit <limit>]
Get CluedIn context
When you work with CluedIn API, you need a context—a domain, organization name, email, password, or API token. What if we tell you that you just need the API token, and then CluedIn Magic will automagically resolve the rest? Let’s try it!
-
At first, you only need an API token—you can get one in CluedIn > Administration > API Tokens.
-
In the following example, we store the API token in an environment variable, which is then retrieved into a local variable:
access_token = %env ACCESS_TOKENctx = %cluedin get-context --jwt $access_token -
Pass the value to CluedIn Magic, and it will give you a working CluedIn context:
ctx = %cluedin get-context --jwt eyJhbGci...5Odvpr1gYou can use this context now with CluedIn Python SDK or CluedIn Magic.
Search
Let’s say that you want to load all /Infrastructure/User entities.
-
Provide a context and a query, and get a pandas DataFrame with your data:
%cluedin search --context ctx --query +entityType:/Infrastructure/User
-
You can get a sample by providing a limit if you have millions of entities.
-
In this example, we retrieve ten entities out of all entities in the system:
%cluedin search --context ctx --query * --limit 10 -
In this example, we retrieve ten records of type
/IMDb/Namewhereimdb.name.birthYearvocabulary key property does not equal\\N:%cluedin search --context ctx --query +entityType:/IMDb/Name -properties.imdb.name.birthYear:"\\\\N" --limit 10
-
-
You can save the results in a variable and use it as a usual pandas DataFrame:
pd = %cluedin search --context ctx --query +entityType:/IMDb/Name +properties.imdb.name.birthYear:1981 pd.head()