|
| 1 | +Getting Started |
| 2 | +=============== |
| 3 | + |
| 4 | +This page gives an introduction to **python-stix** and how to use it. |
| 5 | + |
| 6 | +.. note:: |
| 7 | + |
| 8 | + This page is being actively worked on; feedback is always welcome. |
| 9 | + |
| 10 | +Prerequisites |
| 11 | +------------- |
| 12 | + |
| 13 | +The python-stix library provides an API for creating or processing STIX content. As such, it is a developer tool that can be leveraged by those who know Python 2.6/2.7 and are familiar with object-oriented programming practices, Python package layouts, and are comfortable with the installation of Python libraries. To contribute code to the python-stix repository, users must be familiar with `git`_ and `GitHub pull request`_ methodologies. Understanding XML, XML Schema, and the STIX language is also incredibly helpful when using python-stix in an application. |
| 14 | + |
| 15 | +.. _git: http://git-scm.com/documentation |
| 16 | +.. _GitHub pull request: https://help.github.com/articles/using-pull-requests |
| 17 | + |
| 18 | +Your First STIX Application |
| 19 | +--------------------------- |
| 20 | + |
| 21 | +Once you have installed python-stix, you can begin writing Python applications that consume or create STIX content! |
| 22 | + |
| 23 | +.. note:: |
| 24 | + |
| 25 | + The *python-stix* library provides **bindings** and **APIs**, both of which can be used to parse and write STIX XML files. For in-depth description of the *APIs, bindings, and the differences between the two*, please refer to :doc:`api_vs_bindings/index` |
| 26 | + |
| 27 | +Creating a STIX Package |
| 28 | +*********************** |
| 29 | + |
| 30 | +.. code-block:: python |
| 31 | + |
| 32 | + from stix.core import STIXPackage, STIXHeader # Import the STIX Package and STIX Header APIs |
| 33 | +
|
| 34 | + stix_package = STIXPackage() # Create an instance of STIXPackage |
| 35 | + stix_header = STIXHeader() # Create an instance of STIXHeader |
| 36 | + stix_header.description = "Getting Started!" # Set the description |
| 37 | + stix_package.stix_header = stix_header # Link the STIX Head to our STIX Package |
| 38 | +
|
| 39 | + print(stix_package.to_xml()) # print the XML for this STIX Package |
| 40 | + |
| 41 | +Parsing STIX XML |
| 42 | +**************** |
| 43 | + |
| 44 | +.. code-block:: python |
| 45 | +
|
| 46 | + from stix.core import STIXPackage # Import the STIX Package API |
| 47 | +
|
| 48 | + fn = 'stix_content.xml' # The STIX content filename |
| 49 | + stix_package = STIXPackage.from_xml(fn) # Parse using the from_xml() method |
| 50 | + |
| 51 | +Examples |
| 52 | +-------- |
| 53 | + |
| 54 | +The python-stix GitHub repository contains several example scripts that help illustrate the capabilities of the APIs. These examples can be found `here`_. These scripts are simple command line utilities that can be executed by passing the name of the script to a Python interpreter. |
| 55 | + |
| 56 | +.. _here: https://github.com/STIXProject/python-stix/tree/master/examples |
| 57 | + |
| 58 | +.. code-block:: python |
| 59 | +
|
| 60 | + Example: |
| 61 | + $ python ex_01.py |
| 62 | + |
| 63 | +.. note:: |
| 64 | + |
| 65 | + You must install python-stix before running these example scripts. |
0 commit comments