# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
