Metadata-Version: 2.5
Name: ocf-types
Version: 1.2.1-alpha.1
Summary: Python types for the Open Cap Format (OCF), generated from the OCF JSON Schemas.
Project-URL: Homepage, https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF#readme
Project-URL: Repository, https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF
Project-URL: Issues, https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF/issues
License: ### Schema and Documentation License
        
        Version 1.0.1, April 3, 2024
        
        Copyright (C) 2024 Open Cap Table Coalition <https://opencaptablecoalition.com/>
        
        #### 1. LICENSE
        
        **By using and/or copying Open Cap Table Coalition JSON Schema files or documentation thereof
        (each, individually, an "OCF File", and, collectively, the "OCF Files"), you (the licensee)
        agree that you have read, understood, and will comply with the following terms and conditions**:
        
        Permission to copy and distribute OCF Files, in any medium for any purpose and without fee or
        royalty is hereby granted, provided that
        
        1. For _ALL_ copies of an OCF File or portions thereof that are **not** JSON Schema files, you include
        
        - A link to the original OCF File and
        - A notice in the form "Copyright © [$date-of-ocf-file] [Open Cap Table Coalition](https://opencaptablecoalition.com)."; and
        
        2. For _ALL_ copies of an OCF File or portions thereof that **are** JSON Schema files, you include
        
        - A `$comment` field with a value of: "Copyright © [$date-of-ocf-file]
          Open Cap Table Coalition (https://opencaptablecoalition.com) / Original File: [$url-of-original-schema-file]"
        
        When space permits, inclusion of the full text of the **NOTICE** (as defined below) should be provided. We request
        that authorship attribution be provided in any software, documents, or other items or products
        that you create pursuant to the implementation of OCF Files, or any portion thereof.
        
        No right to create modifications or derivatives of OCF Files is granted pursuant to this license,
        except as follows:
        
        _To facilitate implementation of the technical specifications set forth in
        the OCF Files, anyone may prepare and distribute derivative works and
        portions of the OCF Files in software, in supporting materials accompanying
        software, and in documentation of software, PROVIDED that all such
        works include the notice below. HOWEVER, the publication of derivative
        works of OCF Files for use as a technical specification is expressly prohibited._
        
        In addition, "Code Components" - sample OCF file implementations, sample OCF JSONs and computer
        programming language code - are licensed under the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0).
        
        The full "Notice" is:
        
        > "Copyright © [$date-of-ocf-file] Open Cap Table Coalition. This software or document
        > includes material copied from or derived from [title and URI of the OCF File]."
        
        #### 2. DISCLAIMERS
        
        OCF FILES ARE PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES,
        EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS
        FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE OCF FILES ARE
        SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY
        THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE
        FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE OCF FILES
        OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF.
        
        The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining
        to the OCF Files or their contents without specific, written prior permission. Title to copyright
        in the OCF Files will at all times remain with copyright holders.
License-File: LICENSE.md
Keywords: cap-table,ocf,open-cap-format,types,typing
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: typing-extensions>=4.9
Description-Content-Type: text/markdown

# ocf-types

Python types for the
[Open Cap Format (OCF)](https://github.com/Open-Cap-Table-Coalition/Open-Cap-Format-OCF), generated
directly from the OCF JSON Schemas.

> **Generated. Do not edit by hand.** `ocf_types/__init__.py` is produced by
> `npm run build:ocf-types-python` from the schemas under [`/schema`](../../schema). It is built at
> release time and is _not_ committed to the repository.

This is the Python counterpart of [`@open-captable/ocf-types`](../ocf-types), the TypeScript types.

## Install

```bash
pip install ocf-types
```

The package version is the OCF schema release it was generated from: `ocf-types==1.2.0` has the
types for OCF `v1.2.0`. It needs Python 3.10 or later and depends only on `typing_extensions`.

## Usage

```python
import ocf_types as ocf


def quantity_transferred(transfer: ocf.StockTransfer) -> str:
    return transfer["quantity"]


issuer: ocf.Issuer = {
    "object_type": "ISSUER",
    "id": "issuer",
    "legal_name": "Example Co",
    "formation_date": "2022-01-03",
    "country_of_formation": "US",
}
```

Every type is a `TypedDict`, a `Literal` or a union of those, so an OCF object stays the plain
`dict` that `json.load` gives you. The package adds no behaviour at run time.

## What's included

One named type per OCF schema:

-   **Objects, types and file wrappers** are `TypedDict` classes. A field the schema does not
    require is `NotRequired`.
-   **Enums** are `Literal` types: `StockClassType = Literal["COMMON", "PREFERRED"]`.
-   **Scalar types** are aliases: `Numeric = str`, `Date = str`.
-   **Versioned schemas** are the union of their versions:
    `EquityCompensationIssuance = EquityCompensationIssuanceV1 | EquityCompensationIssuanceV2`.

### Objects are built the way OCF builds them

OCF composes each object from primitives with `allOf`. The Python types keep that, where the
TypeScript types flatten it:

```python
class Transfer(TypedDict):
    balance_security_id: NotRequired[str]
    resulting_security_ids: list[str]


class StockTransfer(Object, Transaction, SecurityTransaction, Transfer):
    object_type: Literal["TX_STOCK_TRANSFER"]
    quantity: Numeric
```

So a function that takes a `Transfer` accepts a stock, convertible, warrant or equity compensation
transfer.

For each primitive there is also a union of everything built from it, named `Any` plus the
primitive: `AnyTransfer`, `AnyIssuance`, `AnyTransaction`, `AnyObject`, `AnyConversionTrigger`. Use
one when code handles every member and should be checked against the fields they share:

```python
def results(transfer: ocf.AnyTransfer) -> list[str]:
    return transfer["resulting_security_ids"]  # every transfer has this


def quantity(transfer: ocf.AnyTransfer) -> str:
    return transfer["quantity"]  # error: a convertible transfer has an amount, not a quantity
```

### Names

The names are the ones the TypeScript types use, without the `OCF` prefix: `StockIssuance` here is
`OCFStockIssuance` there. A Python module is its own namespace, so `import ocf_types as ocf` gives
`ocf.StockIssuance`. To generate with the prefix, pass `--prefix OCF` to
`npm run schema:gen-python-types`.

## What the types do not check

A type says which fields an object has and what each holds. It cannot say everything a JSON Schema
does. These are not represented:

-   patterns and formats (a `Numeric` or a `Date` is a `str`);
-   minimums and other limits on a value;
-   conditional requirements, such as "an option has an `exercise_price`";
-   that no other field is allowed.

Validate OCF data against the JSON Schemas for full correctness, for example with
[`@open-captable/cli`](https://www.npmjs.com/package/@open-captable/cli). Treat a value as its OCF
type once it has passed.

## Type checkers

The types are checked in CI with **pyright** and **mypy** in strict mode, as an installed package:
correct uses must pass, and a set of deliberate mistakes must each be reported.

A schema often narrows a field of a schema it is built from: every object narrows `object_type` from
the `ObjectType` enum to its own value. The types allow that by declaring such a field `ReadOnly` in
the base class ([PEP 705](https://peps.python.org/pep-0705/)).

An older mypy does not accept that narrowing when it checks the module's own source: mypy 1.18.2
reports "Overwriting TypedDict field", and mypy 2.4.1 does not. This does not affect an installed
package, which mypy does not report on. It matters only if you copy `ocf_types` into your own source
tree. As an installed package the types were tested with mypy 1.18.2 and 2.4.1, and pyright 1.1.414.

## License

Generated from the OCF schemas. See [LICENSE.md](LICENSE.md).
