> For the complete documentation index, see [llms.txt](https://openrarity.gitbook.io/developers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openrarity.gitbook.io/developers/quick-guides/integrating-openrarity-in-your-application.md).

# Integrating OpenRarity in your application

To use OpenRarity library with your own NFT datasets use following code snippet in your application:

```python
# OpenRarity version 0.4.0-beta
from open_rarity import (
    Collection,
    Token,
    RarityRanker,
    TokenMetadata,
    StringAttribute,
)
from open_rarity.models.token_identifier import EVMContractTokenIdentifier
from open_rarity.models.token_standard import TokenStandard

# Create OpenRarity collection object and provide all metadata information
collection = Collection(
    name="My Collection Name",
    attributes_frequency_counts={
        "hat": {"cap": 1, "visor": 2},
        "shirt": {"blue": 2, "green": 1},
    },
    tokens=[
        Token(
            token_identifier=EVMContractTokenIdentifier(
                contract_address="0xa3049...", token_id=1
            ),
            token_standard=TokenStandard.ERC721,
            metadata=TokenMetadata(
                string_attributes={
                    "hat": StringAttribute(name="hat", value="cap"),
                    "shirt": StringAttribute(name="shirt", value="blue"),
                }
            ),
        ),
    ],
)  # Replace inputs with your collection-specific details here


# Generate scores for a collection
ranked_tokens = RarityRanker.rank_collection(collection=collection)

# Iterate over the ranked and sorted tokens
for token_rarity in ranked_tokens:
    token_id = token_rarity.token.token_identifier.token_id
    rank = token_rarity.rank
    score = token_rarity.score
    print(f"\tToken {token_id} has rank {rank} score: {score}")

```

If you don't have internal datasets , consider using OpenSea api to provide collection data. This example using library helper methods that are resolving collection/token information from OpenSea API:

```python
# OpenRarity version 0.4.0-beta
from open_rarity import RarityRanker
from open_rarity.resolver.opensea_api_helpers import (
    get_collection_from_opensea,
)

slug = 'proof-moonbirds'
# Create OpenRarity collection object from OpenSea API
collection = get_collection_from_opensea(slug)

# Generate scores for a collection
ranked_tokens = RarityRanker.rank_collection(collection=collection)

# Iterate over the ranked and sorted tokens
for token_rarity in ranked_tokens:
    token_id = token_rarity.token.token_identifier.token_id
    rank = token_rarity.rank
    score = token_rarity.score
    print(f"\tToken {token_id} has rank {rank} score: {score}")

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://openrarity.gitbook.io/developers/quick-guides/integrating-openrarity-in-your-application.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
