Keep artifacts local in a cloud instance

If you want to default to keeping artifacts local in a cloud instance, enable keep_artifacts_local.

Let us first create a cloud instance that woul store artifacts exclusively on S3.

!lamin login testuser1
!lamin init --storage s3://lamindb-ci/keep-artifacts-local
Hide code cell output
 logged in with email testuser1@lamin.ai (uid: DzTjkKse)
! updating cloud SQLite 's3://lamindb-ci/keep-artifacts-local/.lamindb/lamin.db' of instance 'testuser1/keep-artifacts-local'
! locked instance (to unlock and push changes to the cloud SQLite file, call: lamin disconnect)
 initialized lamindb: testuser1/keep-artifacts-local

Let’s import lamindb and track the current notebook run.

# !pip install 'lamindb[jupyter]'
import lamindb as ln

ln.track("l9lFf83aPwRc0000")
Hide code cell output
 connected lamindb: testuser1/keep-artifacts-local
 created Transform('l9lFf83aPwRc0000'), started new Run('bYSUDZcz...') at 2025-07-21 11:35:15 UTC
 notebook imports: lamindb==1.9.0

Toggling setting “keep artifacts local”

You can checkmark the “Keep artifacts local” box on the instance settings tab.

Or toggle it through the following instance setting.

ln.setup.settings.instance.keep_artifacts_local = True

Create a local storage location

Call the following for a – potentially pre-existing – root path and a unique host identifier.

ln.Storage(root="./our_local_storage", host="abc-institute-drive1").save()
Hide code cell output
 created managed storage location at /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage, see: https://lamin.ai/testuser1/infrastructure
Storage(uid='6ovIb7Ce0CP8', root='/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage', type='local', region='abc-institute-drive1', instance_uid='6uGWmLpZlNoJ', branch_id=1, space_id=1, created_by_id=1, run_id=1, created_at=2025-07-21 11:35:17 UTC)

Now, you have two storage locations: one in the S3 bucket, and the other locally.

ln.Storage.df()
Hide code cell output
uid root description type region instance_uid space_id run_id created_at created_by_id _aux branch_id
id
2 6ovIb7Ce0CP8 /home/runner/work/lamindb/lamindb/docs/faq/our... None local abc-institute-drive1 6uGWmLpZlNoJ 1 1.0 2025-07-21 11:35:17.507000+00:00 1 None 1
1 kh5iUhzwmPIE s3://lamindb-ci/keep-artifacts-local None s3 us-west-1 6uGWmLpZlNoJ 1 NaN 2025-07-21 11:35:08.603000+00:00 1 None 1

Use a local storage location

If you save an artifact in keep-artifacts-local mode, by default, it’s stored in local storage.

original_filepath = ln.core.datasets.file_fcs()
artifact = ln.Artifact(original_filepath, key="example_datasets/file1.fcs").save()
local_path = artifact.path  # local storage path
local_path
Hide code cell output
 defaulting to local storage: /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage
PosixUPath('/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage/.lamindb/0fAze6nycnxwcYNm0000.fcs')

You’ll see the .fcs file named by the uid in your .lamindb/ directory under ./our_local_storage/:

assert artifact.path.exists()
assert artifact.path.as_posix().startswith(ln.settings.local_storage.root.as_posix())
ln.settings.local_storage.root.view_tree()
Hide code cell output
1 sub-directory & 2 files with suffixes '.txt', '.fcs'
/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage
└── .lamindb/
    ├── storage_uid.txt
    └── 0fAze6nycnxwcYNm0000.fcs

Pre-existing artifacts

Assume you already have a file in your local storage location:

file_in_local_storage = ln.core.datasets.file_bam()
file_in_local_storage.rename("./our_local_storage/output.bam")
ln.UPath("our_local_storage/").view_tree()
Hide code cell output
1 sub-directory & 3 files with suffixes '.txt', '.bam', '.fcs'
/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage
├── output.bam
└── .lamindb/
    ├── storage_uid.txt
    └── 0fAze6nycnxwcYNm0000.fcs

When registering an artifact for it, it remains where it is.

my_existing_file = ln.Artifact("./our_local_storage/output.bam").save()
ln.UPath("our_local_storage/").view_tree()
Hide code cell output
1 sub-directory & 3 files with suffixes '.txt', '.bam', '.fcs'
/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage
├── output.bam
└── .lamindb/
    ├── storage_uid.txt
    └── 0fAze6nycnxwcYNm0000.fcs

The storage path of the artifact matches the pre-existing file:

my_existing_file.path
Hide code cell output
PosixUPath('/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage/output.bam')

Switching between local storage locations

You might have several local storage locations. Here is how you can switch between them.

ln.Storage(root="./our_local_storage2", host="abc-institute-drive1").save()
ln.settings.local_storage = "./our_local_storage2"  # switch to the new storage location
Hide code cell output
 created managed storage location at /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage2, see: https://lamin.ai/testuser1/infrastructure
 defaulting to local storage: /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage2

Ingest a file into the new local storage location.

filepath = ln.core.datasets.file_fastq()
artifact3 = ln.Artifact(filepath, key="example_datasets/file.fastq.gz").save()

Inspect where all the files are.

ln.Artifact.df(include=["storage__root", "storage__region"])
Hide code cell output
uid key storage__root storage__region
id
3 cleVgIKNZPU8GYtg0000 example_datasets/file.fastq.gz /home/runner/work/lamindb/lamindb/docs/faq/our... abc-institute-drive1
2 3YG94AaYCtAuTBaR0000 output.bam /home/runner/work/lamindb/lamindb/docs/faq/our... abc-institute-drive1
1 0fAze6nycnxwcYNm0000 example_datasets/file1.fcs /home/runner/work/lamindb/lamindb/docs/faq/our... abc-institute-drive1

Upload a local artifact to the cloud

If you’d like to upload an artifact to the cloud storage location to more easily share it or view it through web applications, you pass upload=True to the save() method.

artifact.save(upload=True)
 moved local artifact to cache: /home/runner/.cache/lamindb/0fAze6nycnxwcYNm0000.fcs
Artifact(uid='0fAze6nycnxwcYNm0000', is_latest=True, key='example_datasets/file1.fcs', suffix='.fcs', size=19330507, hash='rCPvmZB19xs4zHZ7p_-Wrg', branch_id=1, space_id=1, storage_id=1, run_id=1, created_by_id=1, created_at=2025-07-21 11:35:18 UTC)

You now see the artifact in the S3 bucket:

ln.settings.storage.root.view_tree()
2 sub-directories & 3 files with suffixes '.db', '.txt', '.fcs'
s3://lamindb-ci/keep-artifacts-local
└── .lamindb/
    ├── 0fAze6nycnxwcYNm0000.fcs
    ├── lamin.db
    ├── storage_uid.txt
    └── _exclusion/

And it’s no longer present in local storage:

assert artifact.path.exists()
assert not local_path.exists()
assert artifact.path.as_posix().startswith(ln.settings.storage.root.as_posix())
ln.settings.local_storage.root.view_tree()
1 sub-directory & 2 files with suffixes '.txt', '.fastq.gz'
/home/runner/work/lamindb/lamindb/docs/faq/our_local_storage2
└── .lamindb/
    ├── storage_uid.txt
    └── cleVgIKNZPU8GYtg0000.fastq.gz

Upload directly to the cloud

You can also directly upload via upload=True:

filepath = ln.core.datasets.file_mini_csv()
artifact2 = ln.Artifact(filepath, key="example_datasets/mini.csv").save(upload=True)
artifact2.path
S3QueryPath('s3://lamindb-ci/keep-artifacts-local/.lamindb/JVzfyQowZEtpkjOE0000.csv')

Now we have two files on S3:

ln.Artifact.df(include="storage__root")
uid key storage__root
id
4 JVzfyQowZEtpkjOE0000 example_datasets/mini.csv s3://lamindb-ci/keep-artifacts-local
3 cleVgIKNZPU8GYtg0000 example_datasets/file.fastq.gz /home/runner/work/lamindb/lamindb/docs/faq/our...
2 3YG94AaYCtAuTBaR0000 output.bam /home/runner/work/lamindb/lamindb/docs/faq/our...
1 0fAze6nycnxwcYNm0000 example_datasets/file1.fcs s3://lamindb-ci/keep-artifacts-local

Update storage description

You can add a description to the storage location by using the description field.

storage_record = ln.Storage.get(root__endswith="our_local_storage")
storage_record.description = "Our shared directory for project X"
storage_record.save()
ln.Storage.df()
uid root description type region instance_uid space_id run_id created_at created_by_id _aux branch_id
id
3 ODA5aIE7iVYL /home/runner/work/lamindb/lamindb/docs/faq/our... None local abc-institute-drive1 6uGWmLpZlNoJ 1 1.0 2025-07-21 11:35:19.165000+00:00 1 None 1
2 6ovIb7Ce0CP8 /home/runner/work/lamindb/lamindb/docs/faq/our... Our shared directory for project X local abc-institute-drive1 6uGWmLpZlNoJ 1 1.0 2025-07-21 11:35:17.507000+00:00 1 None 1
1 kh5iUhzwmPIE s3://lamindb-ci/keep-artifacts-local None s3 us-west-1 6uGWmLpZlNoJ 1 NaN 2025-07-21 11:35:08.603000+00:00 1 None 1

Delete the test instance

Delete the artifacts:

artifact.delete(permanent=True)
artifact2.delete(permanent=True)
artifact3.delete(permanent=True)
my_existing_file.delete(permanent=True, storage=False)
 a file/folder remains here: /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage/output.bam

Delete the instance:

ln.setup.delete("keep-artifacts-local", force=True)
Hide code cell output
 deleted storage record on hub eb35d80e9c4d5d02aab65a03c95bb70c | s3://lamindb-ci/keep-artifacts-local
 deleted storage record on hub 8cde376c68be43b0a9e46ec35a537e95 | /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage
 deleted storage record on hub 198067aa3138436d802ae8815c1035d7 | /home/runner/work/lamindb/lamindb/docs/faq/our_local_storage2
 deleted instance record on hub cc7f2489bf7251f79ff9ca8df7ac045b