anytype-cli
Command-line interface for the Anytype local API, built on anytype.
Install
Configure
Configuration can be set with command-line parameters or environment variables.
-
Url The default url is the desktop client
http://127.0.0.1:31009. Override with--urlor the environment variableANYTYPE_URL. -
Key Storage The default key storage method should work on most platforms. Options for overriding the defaults are described below in Key storage.
# use headless server and custom key path
Generate api key (first-time authentication)
-
Desktop: If the Anytype desktop app is running, type
anyr auth loginand the app will display a 4-digit code. Enter the code into the cli prompt, and a key is generated and stored in the KeyStore. -
Headless server: If you are using the headless cli server, start the server, run
anytype auth apikey create anyrto generate and display a key, save it in a file, and set the key file path as described in Key storage.
Run
# show options
# check authentication status
# List spaces your user is authorized to access
# List spaces with json output
Common options
--helpshow context-specific help
Configuration
--urlanytype endpoint url--keyfile,--keyfile-path,--keyring,--keyring-service: see Key storage
Output format
--json(same as default).--pretty(json pretty-print)-t/--table(table format, easy to read in terminal)--quiet(minimal output)
Filters
-
--filter- add filters -
--type- limit search results to type(s) -
--sort- sort results by property key (ascending) -
--desc- if used with--sort, sort descending -
There are some apparent bugs in anytype-heart that limit the functionality of search filters, especially in 'list' commands. See Troubleshooting for current known issues.
Examples
List objects in a space
# List <ENTITY> in a space. (entities: object, member, property, template)
# anyr <ENTITY> list <SPACE_ID_OR_NAME>
# list objects in space 'Personal'
# list types in space 'Personal'
Search in space
# search space "Work" for tasks containing the text "customer"
List tasks in space
space_id="Work" # specify space using name or id
for
Get objects from a collection list or grid view.
If you have a list or grid formatted view, you can use view objects to list the view items by specifying the space name, list, and view.
- Results are filtered and sorted by the criteria in the view.
- View can be specified by the view id or view name.
- The --json and --pretty format outputs include all properties of the objects.
Table listing features for view objects:
- Table listing defaults to name column only. Specify columns in table output with
--cols/--columnsand a comma-separated list of property keys. Example--cols name,creator,created_date,status - Format dates with strftime format:
--date-formatorANYTYPE_DATE_FORMAT, defaults to%Y-%m-%d %H:%M:%S. - Members names are displayed instead of member id.
Example: get all tasks in space "Work" from view "All"
# show names of all tasks in space "Work", using view 'All'
# show columns: Name, Created By, and Status (note: column names are specified by property_key)
# get tasks from view ByProject in json, with all properties
Key storage
anyr requires an api key to access Anytype documents, which is obtained with a one-time authentication step.
First, decide which of two methods will be used for storing the key. The key should be kept secret like other passwords, as it can allow access to unencrypted anytype documents. Preferably, the api key is stored in the secure OS Keyring, which requires biometric or password authentication. Alternately, the key can be saved in a file on your drive, which is less secure.
Key storage is determined in the following order of precedence:
- If flag
--keyfileis present, or environment variableANYTYPE_KEYSTORE_FILEis1, api keys are stored in a file in a config folder.
| Platform | Value | Example |
|---|---|---|
| Linux | $XDG_CONFIG_HOME or $HOME/.config |
/home/alice/.config/anyr/api.key |
| macOS | $HOME/Library/Application Support |
/Users/Alice/Library/Application Support/anyr/api.key |
| Windows | {FOLDERID_RoamingAppData} |
C:\Users\Alice\AppData\Roaming\anyr\api.key |
| (other) | ./anyr/api.key |
-
If arg
--keyfile-pathis set, or environment variableANYTYPE_KEY_FILEis set, api keys are stored in a file with that path. -
If flag
--keyringis present, orANYTYPE_KEYSTORE_KEYRINGis1, the OS keyring is used and prompts user with service name "anyr". -
If arg
--keyring-serviceis set, or environment variableANYTYPE_KEY -
If environment variable
ANYTYPE_KEYSTORE_KEYRINGis1ortrue, -
If none of the above overrides are present, for MacOS and Windows, key storage defaults to the OS keyring for MacOS and Windows, and the default file path for Linux and other platforms.
Logging
Debug logging
RUST_LOG=debug
Log HTTP requests and responses:
RUST_LOG=warn,anytype::http_json=trace
Testing
Python CLI tests expect the same environment variables as the API tests:
ANYTYPE_TEST_URL(orANYTYPE_URL)ANYTYPE_TEST_KEY_FILE(orANYTYPE_KEY_FILE)ANYTYPE_TEST_SPACE_ID
License
Licensed under either of:
- Apache License, Version 2.0 (
LICENSE-APACHE) - MIT License (
LICENSE-MIT)