This is an unofficial .NET client for the Unstructured API. Refer to Official Unstructured API Docs to understand about the project and steps to use the hosted service or deploy your own instance using Docker.
Install package Bash.UnstructuredIO.Client
from Nuget. Here's how via command line:
Install-Package Bash.UnstructuredIO.Client
The UnstructuredClient
class can be used both by dependency injection or directly instantiating it wherever required. The first parameter is the server URL of the Unstructured instance. It can either be set to the official hosted API or your own instance. The seond one is the api-key which is optional and can be omitted.
builder.Services.AddSingleton<IUnstructuredClient>(
new UnstructuredClient("http://localhost:8000", "my-key-123")
);
var unstructuredClient = new UnstructuredClient("http://localhost:8000", "my-key-123");
The PartitionAsync
method returns a ApiResponse
object that has the parameters of Data
, Message
and StatusCode
.
- The
Data
property is a list ofElements
that have been extracted from the document. - The
Message
andStatusCode
properties return a message if the extraction was successful or not.
var filePath = "SampleFiles\\lorem_ipsum.docx";
var result = await _unstructuredClient.PartitionAsync(filePath, CancellationToken.None);
var elements = result.Data;
foreach (var element in elements)
{
Console.WriteLine(element.Text);
}
See the api parameters page for all available Extraction Options
.
var options = new ExtractionOptions()
{
Strategy = UnstructuredConstants.Strategy.HighResolution,
Coordinates = true
};
var result = await unstructuredClient.PartitionAsync(filePath, options, CancellationToken.None);
The UnstructuredConstants
contains a set of constants that can be used in the SDK.
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
This was a project aimed at learning how NuGet packages can be created along with the itch of doing some .NET stuff besides work. Contributions are very welcome and needed. It is not probably following the best practices so willing to learn whoever contributes to do a code review!
This project is licensed under the MIT License - see the LICENSE.txt file for details.