FMC OpenAPI
fmc_openapi is a Python package that simplifies interaction with Cisco Firepower Management Center (FMC) APIs. It dynamically parses the OpenAPI (Swagger) specification to discover available endpoints and interact with them using the operationId.
To identify which operations are supported, you can refer to the Operation ID table.
🚀 Features
- 🔍 Parses the Swagger file to discover endpoints
- 💡 Calls API operations by operationId
- 🔐 Session handling (login/logout)
- 🧰 Simplifies complex API interactions
- ⚠️ Error handling built-in
- 🏢 SCC/CDO Token-Based Authentication
- 🔄 Automatic pagination handling (manual pagination is also possible)
- 📦 Bulk operations
- 📄 All endpoints defined in the Swagger spec
📦 Installation
pip install fmc_openapi
Import API client
from fmc_openapi import FMCOpenAPIClient
🧑💻 Usage Example
Connecting to FMC (username/password)
from fmc_openapi import FMCOpenAPIClient
with FMCOpenAPIClient(
hostname="fmc.example.com",
username="your_username",
password="your_password",
verify=False
) as fmc:
domains = fmc.operation("getAllDomain")
Connecting to SCC (token-based)
from fmc_openapi import FMCOpenAPIClient
with FMCOpenAPIClient(
hostname="scc.example.com",
token="your_token_here",
verify=False
) as fmc:
domains = fmc.operation("getAllDomain")
Get all access policy rules
import jmespath
with FMCOpenAPIClient(
hostname="fmc.example.com",
username="your_username",
password="your_password",
verify=False
) as fmc:
# Get domain UUID
domains = fmc.operation("getAllDomain")
domain_uuid = jmespath.search("items[?name=='my-domain'].uuid | [0]", domains)
# Get ACP UUID
acp_response = fmc.operation("getAllAccessPolicy", domainUUID=domain_uuid)
acp_uuid = jmespath.search("items[?name=='my-policy'].uuid | [0]", acp_response)
# Get all access policy rules (with automatic pagination)
rules = fmc.operation(
"getAllAccessRule",
limit=1000,
domainUUID=domain_uuid,
containerUUID=acp_uuid,
expanded=True
)
Manual Pagination
rules = fmc.operation(
"getAllAccessRule",
limit=1000,
domainUUID=domain_uuid,
containerUUID=acp_uuid,
expanded=True,
manual_pagination=True
)
Creating Objects
payload = {
"name": "obj-192.168.1.0",
"type": "Network",
"value": "192.168.1.0/24",
}
fmc.operation("createMultipleNetworkObject", payload=payload, domainUUID=domain_uuid)
Bulk Operations
response = fmc.operation(
"getHitCount",
limit=1000,
domainUUID=domain_uuid,
containerUUID=ac_uuid_selected,
filter=f"deviceId:{device_uuid}",
expanded=True,
bulk=True
)
🧪 Running Tests
Tests are written using pytest.
To run tests:
poetry run pytest
Or activate the environment first:
poetry shell
pytest
🛠 Project Structure
fmc_openapi/
├── __init__.py # Imports FMCOpenAPIClient
├── client.py # Main client class
├── swagger.py # Swagger parser
├── utils.py # Logging and request helpers
tests/
├── test_swagger.py # Tests for Swagger JSON fetching and operation extraction
├── test_operation.py # Tests for executing API operations using operationId
├── test_auth.py # Tests for authentication: login and logout
├── test_client.py # General client behavior and utility method tests
📄 License
GNU GPL v3 License. See LICENSE for details.
🤝 Contributing
Pull requests are welcome! If you plan to add new features, open an issue first to discuss it.
- Fork the project
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a pull request
✉️ Contact
Questions? Ideas? Open an issue or drop a message.
Metadata
Release files for fmc_openapi 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fmc_openapi-0.1.3.tar.gz | 19.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fmc_openapi-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.1 kB
Release files / fmc_openapi-0.1.3.tar.gz
| Download URL | fmc_openapi-0.1.3.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
821603d7771bdac5ac10d4897054b2c5dfc7a4e60ea528659c43e9c974a7731f
|
|
BLAKE2b-256 checksum How to use checksums |
b99c0cf28970eced32b68db0daa497b60753c0286a5345647705ac400ac2372c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
|
Release files / fmc_openapi-0.1.3-py3-none-any.whl
| Download URL | fmc_openapi-0.1.3-py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0ac3281e5ba3690b53efc659520218475fbddc0fffc77854a309dd47570aac0
|
|
BLAKE2b-256 checksum How to use checksums |
851477926a408ee30eb013623daef35890fbd5778cac485b621edfcf2195b977
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure
|