---
title: "Project Libraries"
description: "Learn how to create and import projects as libraries in Lean CLI."
canonical: https://www.quantconnect.com/docs/v2/lean-cli/projects/libraries/project-libraries
markdown: https://www.quantconnect.com/docs/v2/lean-cli/projects/libraries/project-libraries.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/05%20Lean%20CLI/06%20Projects/09%20Libraries/02%20Project%20Libraries
modified: 2026-10-29
index: https://www.quantconnect.com/llms.txt
---

# Project Libraries

[Documentation](https://www.quantconnect.com/docs/v2.md) > [Lean CLI](https://www.quantconnect.com/docs/v2/lean-cli.md) > Projects > Libraries > Project Libraries

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

Project libraries are QuantConnect projects you can merge into your project to avoid duplicating code files. If you have tools that you use across several projects, create a library.

To use the CLI, you must be a member in an [organization](https://www.quantconnect.com/docs/v2/cloud-platform/organizations/tier-features.md) on a paid tier.

## Create Libraries

To create a library, open a terminal in one of your [organization workspaces](https://www.quantconnect.com/docs/v2/lean-cli/initialization/organization-workspaces.md) and then [create a project](https://www.quantconnect.com/docs/v2/lean-cli/projects/project-management.md#02-Create-Projects) in the `Library` directory.

```python
$ lean project-create "Library/MyLibrary"
Successfully created Python project 'Library/MyLibrary'
```

The library name can only contain letters (a-z), numbers (0-9), and underscores (_). The library name can't contain spaces or start with a number. To create a library directory, set the name to `Library / directoryName / libraryName` (for example, `Library / Tools / Calculators`).

The `lean project-create` command creates a new project based on your [default programming language](https://www.quantconnect.com/docs/v2/lean-cli/projects/project-management.md#03-Set-the-Default-Language). To create a C# library, add the `--language csharp` option.

```python
$ lean project-create "Library/MyLibrary" --language csharp
Successfully created C# project 'Library/MyLibrary'
Restoring packages in 'Library\MyLibrary' to provide local autocomplete
Restored successfully
Successfully created C# project 'Library/MyLibrary'
```

## Add Libraries

Follow these steps to add a library to your project:

1. Open a terminal in your [organization workspace](https://www.quantconnect.com/docs/v2/lean-cli/initialization/organization-workspaces.md) that contains the library.
2. Run `lean library add "<projectName>" "Library/<libraryName>"`.

   ```python
   $ lean library add "My Project" "Library/MyLibrary"
   Adding Lean CLI library D:\qc\lean-cli\Library\MyLibrary to project D:\qc\lean-cli\My Project
   ```
3. In your project files, import the library class at the top of the page.
   ```python
   from MyLibrary.main import MyLibrary
   ```
   In general, use `from <libraryName>.<fileNameWithoutExtension> import <memberName>`.
4. In your project files, instantiate the library class and call its methods.
   ```python
   x = MyLibrary()
   value = x.add(1, 2)
   ```

## Rename Libraries

Follow these steps to rename a library:

1. Open the [organization workspace](https://www.quantconnect.com/docs/v2/lean-cli/initialization/organization-workspaces.md) that contains the library.
2. In the `Library` directory, rename the library project.
   The library name can only contain letters (a-z), numbers (0-9), and underscores (_). The library name can't contain spaces or start with a number. To create a library directory, set the name to `Library / directoryName / libraryName` (for example, `Library / Tools / Calculators`).
3. If you have a copy of the library in QuantConnect Cloud, open a terminal in your organization workspace and push the library project.
   ```
   $ lean cloud push --project "Library/MySpecialLibrary"
   [1/1] Pushing 'Library\MySpecialLibrary'
   Renaming project in cloud from 'Library/MyLibrary' to 'Library/MySpecialLibrary'
   Successfully updated name, files, and libraries for 'Library/MyLibrary'
   ```

## Remove Libraries

Follow these steps to remove a library from a project, open a terminal in your [organization workspace](https://www.quantconnect.com/docs/v2/lean-cli/initialization/organization-workspaces.md) that stores the project and then run `lean library remove "<projectName>" "Library/<libraryName>"`.

```python
$ lean library remove "My Project" "Library/MyLibrary"
```

## Delete Libraries

To delete a library, open a terminal in your [organization workspace](https://www.quantconnect.com/docs/v2/lean-cli/initialization/organization-workspaces.md) that contains the library and then run `lean project-delete "Library/<libraryName>"`.

```
$ lean project-delete "Library/MyLibrary"
Successfully deleted project 'Library/MyLibrary'
```

## Best Practices

Each library is a project, so it has its own [file quota](https://www.quantconnect.com/docs/v2/cloud-platform/projects/files.md#10-Quotas). If a project outgrows its quota, move part of the code into a library.

Libraries are shared, so when you edit one, every project that uses it picks up the change. Add code to a library when it's stable and several projects need it. Keep work in progress and code that only one project uses in the project itself.
