Xbrl 5.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Xbrl --version 5.1.0                
NuGet\Install-Package Xbrl -Version 5.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xbrl" Version="5.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xbrl --version 5.1.0                
#r "nuget: Xbrl, 5.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xbrl as a Cake Addin
#addin nuget:?package=Xbrl&version=5.1.0

// Install Xbrl as a Cake Tool
#tool nuget:?package=Xbrl&version=5.1.0                

Import the Xbrl namespace and components by placing the following code at the top of your code document:

using Xbrl;

Opening an XBRL Instance Document

An Xbrl document can be opened through a byte Stream. This stream can be sourced from a locally saved file or through the "SecuritiesExchangeCommission.Edgar" NuGet solution package. I've used the named NuGet package here:

//Search for a 10-K XBRL document and then download to a Stream
EdgarSearch es = await EdgarSearch.CreateAsync("INTC", "10-K");
EdgarSearchResult esr = es.GetFirstResultOfFilingType("10-K");
Stream s = await esr.DownloadXbrlDocumentAsync();

//Read the XBRL document
XbrlInstanceDocument doc = XbrlInstanceDocument.Create(s);

Listing all facts

//List all facts
foreach (XbrlFact fact in doc.Facts)
{
	Console.WriteLine(fact.Label + ": " + fact.Value.ToString("#,##0.00");
}

Listing all Context References

Each Context Reference contains five properties:

Id - The ID of the Context Ref. This is used by Facts to reference their time period.
TimeType - Specifies the time type for this context reference (either a period with a start or end date, or a "snapshop" on a specific day)
InstantDate - If the time type is instant ("snapshot"), this marks the date of the snapshot.
StartDate - If the time type is period (a period of time), this marks the period begin date.
EndDate - If the time type is period (a period of time), this marks the period end date.

Example of listing all properties of each context reference in an Instance Document:

//List all context references
foreach (XbrlContext context in doc.Contexts)
{
    Console.WriteLine("ID: " + context.Id);
    Console.WriteLine("Time Type: " + context.TimeType.ToString());
    if (context.TimeType == XbrlTimeType.Instant)
    {
        Console.WriteLine("Instant Date: " + context.InstantDate.ToShortDateString());
    }
    else if (context.TimeType == XbrlTimeType.Period)
    {
        Console.WriteLine("Start Date: " + context.StartDate.ToShortDateString());
        Console.WriteLine("End Date: " + context.EndDate.ToShortDateString());
    }
}

Referencing a Fact's Context Reference

The XbrlInstanceDocument class provides the GetContextById method to search through the array of Context References and return the match.
You can pass the ContextId string to this method to return the XbrlContext object. For example:

//Get a fact's Context Reference
XbrlContext context = doc.GetContextById(doc.Facts[0].ContextId);

Using the XBRL Helper

Many companies will include multiple facts of the same type in their document, each for a different fiscal period. For example, including the annual revenue of 2014, 2015, and 2016, all with them same label name. This package also provides a helper class to assist with extracting of current facts, related directly to this period.
Import the helper class by placing this at the top of your code file:

using Xbrl.Helpers;

This will add an extension method to an XbrlInstanceDocument object called GetValueFromPriorities. This method will look for facts that are only relevent to the documents current time period. You can provide multiple labels to search for and the method will search for a fact with the first label, move onto the next if it was unable to find one, and so forth.
For example, if a company either labeled their Current Assets from their balance sheet as "AssetsCurrent" or "CurrentAssets", we would use the following code to return this fact.

XbrlFact current_assets = doc.GetValueFromPriorities("CurrentAssets", "AssetsCurrent");

Converting an Instance Document to a Common Financial Statement

Companies use different terms and keywords to refer to common items on their financial statements. The XBRL package also provides a way to convert an XBRL Instance Document into a "common" financial statement with data that is commonly found in every set of financial statemnets like Revenue, Net Income, Assets, Equity, etc.
Place this line at the top of you code file:

using Xbrl.FinancialStatement;

Importing the namespace with the code below adds an extension method to the XbrlInstanceDocument class. Below is an example of converting an XbrlInstanceDocument into a Financial Statement.

FinancialStatement fs = doc.CreateFinancialStatement();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Xbrl:

Package Downloads
Aletheia

Package Description

Luca

Financial statements simplified. Receive a financial statement for any publically traded company with one line of code.

TimHanewich.Investing

Investing toolkit creating by Tim Hanewich

Luca.Cloud

Peripheral library for accessing financial statements, delegating generation to the cloud (using the Luca API service).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.2.0 2,861 9/21/2022
5.1.1 25,786 6/19/2021
5.1.0 2,584 5/31/2021
5.0.0 3,639 3/30/2021
4.0.0 1,979 1/26/2021
3.1.0 559 6/23/2020
3.0.0 1,050 6/14/2020
2.6.5 621 6/13/2020
2.6.4 444 6/13/2020
2.6.3 611 6/12/2020
2.6.2 618 6/12/2020
2.6.1 501 6/12/2020
2.6.0 491 6/11/2020
2.5.0 453 6/7/2020
2.4.0 1,835 6/7/2020
2.3.0 468 6/7/2020
2.2.0 564 6/7/2020
2.1.0 697 6/6/2020
2.0.1 671 6/6/2020
2.0.0 521 5/24/2020
1.0.0 812 5/5/2020