Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMeinderts committed Mar 25, 2022
1 parent 58db757 commit 6e43e34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A Python module for creation, validation, and transformation of EPC representati
- [GS1Keyed](#gs1keyed)
- [Tag encoded](#tag-encoded)
- [Generic parsing](#generic-parsing)
- [Exceptions](#exceptions)
- [Development](#development)
- [Testing](#testing)
- [Coverage](#coverage)
Expand Down Expand Up @@ -82,20 +83,24 @@ An example highlighting the different options for the `SGTIN` scheme can be foun

## Generic parsers
The following generic parser functions are available
- `base64_to_epc`
- `binary_to_epc`
- `hex_to_epc`
- `tag_uri_to_epc`
- `base64_to_tag_encodable`
- `binary_to_tag_encodable`
- `hex_to_tag_encodable`
- `tag_uri_to_tag_encodable`
- `epc_pure_identity_to_gs1_element`
- `epc_pure_identity_to_gs1_element_string`
- `epc_pure_identity_to_gs1_key`
- `epc_pure_identity_to_gs1_keyed`
- `epc_pure_identity_to_scheme`
- `epc_pure_identity_to_tag_encodable`
- `get_gs1_key`

## Example usage
### SGTIN
#### Pure identity
Given an `SGTIN` in EPC URI representation, `urn:epc:id:sgtin:00000950.01093.Serial`, an epcpy `SGTIN` object can be created as follows
```python
from epcpy.epc_schemes.sgtin import SGTIN
from epcpy.epc_schemes import SGTIN

sgtin = SGTIN.from_epc_uri("urn:epc:id:sgtin:00000950.01093.Serial")

Expand Down Expand Up @@ -189,6 +194,18 @@ get_gs1_key("urn:epc:idpat:sgtin:00000950.01093.*")
- Binary strings
- Hexadecimal strings

## Exceptions
Especially when applying generic parsing, exceptions may be thrown when passing invalid data. One can import the `ConvertException` class to specially deal with exceptions thrown by this library:
```python
from epcpy import ConvertException, get_gs1_key

try:
get_gs1_key("urn:epc:idpat:sgtin:00000950.*.*")
except ConvertException as e:
print(e)
# Could not create valid scheme from given id pat
```

## Development

This project uses [Poetry](https://python-poetry.org/) for project management.
Expand Down
16 changes: 15 additions & 1 deletion notebooks/gs1_converters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
"sys.path.insert(0, \"..\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from epcpy import ConvertException, get_gs1_key\n",
"\n",
"try:\n",
" get_gs1_key(\"urn:epc:idpat:sgtin:00000950.*.*\")\n",
"except ConvertException as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -329,7 +343,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 6e43e34

Please sign in to comment.