### Initializing Snyk Client with Custom API URL - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This example shows how to initialize the Snyk client to connect to a local Snyk installation or a private instance by providing the API URL as the second argument during client instantiation. ```Python import snyk client = snyk.SnykClient("", "") ``` -------------------------------- ### Executing PySnyk Example Scripts Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This snippet shows the general command structure for executing `pysnyk` example scripts. It requires specifying the Snyk organization ID as a command-line argument. ```Python python examples/ --orgId= ... ``` -------------------------------- ### Testing npm Packages Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command tests an npm package for vulnerabilities. It requires the Snyk organization ID, package name, and package version as command-line arguments. ```Python python examples/api-demo-5d-test-npm-package.py --orgId= --packageName= --packageVersion= ``` -------------------------------- ### Listing Snyk Project Issues (Standard) Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command lists all issues for a specific Snyk project. It requires both the organization ID and the project ID. An optional parameter allows capturing the output in an Excel spreadsheet. ```Python python examples/api-demo-2-list-issues.py --orgId= --projectId= ``` ```Python python examples/api-demo-2-list-issues.py --orgId= --projectId= --outputPathExcel=/path/to/output.xlsx ``` -------------------------------- ### Initializing SnykClient for REST API and Basic GET Requests (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet demonstrates how to initialize the `SnykClient` for the REST API by specifying a version and URL. It then shows basic GET requests to retrieve organization and user data, including how to override the API version for a specific request and pass query parameters like `limit`. ```python rest_client = SnykClient(snyk_token, version="2022-02-16~experimental", url="https://api.snyk.io/rest") print(rest_client.get(f"/orgs/{snyk_org}").json()) # this supports overriding rest versions for a specific GET requests: user = rest_client.get(f"orgs/{snyk_org}/users/{snyk_user}", version="2022-02-01~experimental").json() # pass parameters such as how many results per page params = {"limit": 10} targets = rest_client.get(f"orgs/{snyk_org}/targets", params=params) ``` -------------------------------- ### Testing Java Packages Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md These commands test a Java package for vulnerabilities using its groupId, artifactId, and version. Two syntax options are provided for specifying the package details, either with explicit flags or a colon-separated string. ```Python python examples/api-demo-5-test-java-package.py --orgId= --groupId= --artifactId= --packageVersion= ``` ```Python python examples/api-demo-5-test-java-package.py --orgId= :@ ``` -------------------------------- ### Testing RubyGem Packages Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command tests a RubyGem package for vulnerabilities. It requires the Snyk organization ID, package name, and package version as command-line arguments. ```Python python examples/api-demo-5b-test-rubygem-package.py --orgId= --packageName= --packageVersion= ``` -------------------------------- ### Generating Project Dependencies and Licenses Report Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command generates a report of all dependencies (including transitive) and associated licenses for a Snyk project or across all projects in an organization. It requires the `XlsxWriter` Python package and supports multiple output formats including Excel, CSV, nested JSON, and flat JSON. ```Python python examples/api-demo-10-project-deps-licenses-report.py --orgId= --projectId=all --outputPathExcel=my-report.xlsx ``` -------------------------------- ### Creating Jira Issues for Snyk Project Issues Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command automates the creation of Jira issues for each Snyk project issue. It requires the Snyk organization ID, project ID, desired Jira issue type ID, and the target Jira project ID. ```Python python examples/api-demo-6b-create-jira-issues-for-issues.py --orgId= --projectId= --jiraIssueType= --jiraProjectId= ``` -------------------------------- ### Finding Issues Without Jira Issues Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command identifies and lists all Snyk project issues that do not currently have an associated Jira issue. It requires the Snyk organization and project IDs. ```Python python examples/api-demo-6-find-issues-without-jira-issues.py --orgId= --projectId= ``` -------------------------------- ### Listing Snyk Project Issues (Aggregated) Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command lists all aggregated issues for a specific Snyk project, providing a consolidated view. It requires both the organization ID and the project ID. The output can optionally be captured in an Excel spreadsheet. ```Python python examples/api-demo-2c-list-issues-aggregated.py --orgId= --projectId= ``` ```Python python examples/api-demo-2c-list-issues-aggregated.py --orgId= --projectId= --outputPathExcel=/path/to/output.xlsx ``` -------------------------------- ### Instantiating SnykClient for V1 and REST APIs Simultaneously (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This example illustrates how to instantiate two separate `SnykClient` instances: one for the V1 API and another for the REST API. This allows for concurrent interaction with both API versions within the same application, demonstrating how to fetch organization data using each client. ```python snyk_org = "df734bed-d75c-4f11-bb47-1d119913bcc7" v1client = SnykClient(snyk_token) rest_client = SnykClient(snyk_token, version="2022-02-16~experimental", url="https://api.snyk.io/rest") v1_org = v1client.organizations.get(snyk_org) rest_org = rest_client.get(f"/orgs/{snyk_org}").json() ``` -------------------------------- ### Testing Python (pip) Packages Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command tests a Python (pip) package for vulnerabilities. It requires the Snyk organization ID, package name, and package version as command-line arguments. ```Python python examples/api-demo-5c-test-python-package.py --orgId= --packageName= --packageVersion= ``` -------------------------------- ### Updating Snyk Project Settings - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This example shows how to update specific settings for a `snyk.models.Project` object. It uses the project's `settings` manager to modify properties like `pull_request_test_enabled`. ```Python project.settings.update(pull_request_test_enabled=True) ``` -------------------------------- ### Using Low-Level HTTP Methods with pysnyk Client (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Demonstrates direct usage of low-level HTTP methods (`get`, `delete`, `put`, `post`) available on the Snyk client. These methods allow direct interaction with the Snyk API by providing the path and optional data payload, with authentication handled automatically by the client. ```Python client.get("") client.delete("") client.put("", ) client.post("", ) ``` -------------------------------- ### Updating GitHub Checks Settings Source: https://github.com/snyk-labs/pysnyk/blob/master/examples/README.md This command updates the GitHub checks settings for a specified Snyk project or all GitHub projects within your Snyk organization. It allows enabling or disabling pull request tests by setting `pullRequestTestEnabled` to `true` or `false`. ```Python python examples/api-demo-11-update-github-checks.py --orgId= --projectId=|all --pullRequestTestEnabled=[true|false] ``` -------------------------------- ### Retrieving Specific Snyk Organization by ID - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This example demonstrates how to directly retrieve a single `snyk.models.Organization` object if you already know its unique ID. This is useful for quickly accessing a specific organization's details and associated managers. ```Python client.organizations.get("") ``` -------------------------------- ### Initializing Snyk Client with API Token - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet demonstrates the basic initialization of the Snyk client by providing your Snyk API token. By default, this client will connect to the public Snyk service. ```Python import snyk client = snyk.SnykClient("") ``` -------------------------------- ### Inviting New Users as Administrators (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Illustrates how to invite a new user to a Snyk organization with administrator privileges. The `admin=True` argument is passed to the `invite` method to grant administrative access to the invited user. ```Python >>> org = client.organizations.first() >>> org.invite("example@example.com", admin=True) ``` -------------------------------- ### Inviting New Users to an Organization (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Shows how to invite a new user to a Snyk organization via the API using the `invite` method. It first retrieves the desired organization object and then calls `invite` with the new user's email address. ```Python >>> org = client.organizations.first() >>> org.invite("example@example.com") ``` -------------------------------- ### Importing Projects with Specific Manifest Files (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Illustrates how to import a project while specifying particular manifest files to be scanned. The `files` optional argument is used to target specific dependency files, such as 'Gemfile.lock', during the project import process. ```Python org.import_project("github.com/user/project@branch", files=["Gemfile.lock"]) ``` -------------------------------- ### Importing Projects from GitHub/Docker Hub (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Demonstrates how to import new projects from GitHub or Docker Hub into a Snyk organization using the high-level `import_project` method. It retrieves the first available organization and then calls `import_project` with the repository URL. ```Python org = client.organizations.first() org.import_project("github.com/user/project@branch") org.import_project("docker.io/repository:tag") ``` -------------------------------- ### Testing Python Dependencies in a Pipfile (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Demonstrates how to test all Python dependencies defined in a `Pipfile` for vulnerabilities. This is achieved by opening the `Pipfile` and passing its file handle to the `test_pipfile` method of the organization object. ```Python >>> org = client.organizations.first() >>> file = open("Pipfile") >>> org.test_pipfile(file) ``` -------------------------------- ### Testing a Specific Python Package for Vulnerabilities (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Shows how to test a specific Python package (e.g., 'flask' version '0.12.2') for vulnerabilities using the `test_python` method on an organization object. It also demonstrates accessing detailed vulnerability information like title and identifiers from the returned `IssueSet`. ```Python >>> org = client.organizations.first() >>> result = org.test_python("flask", "0.12.2") >>> assert result.ok False # You can access details of the vulnerabilities too, for example >>> result.issues.vulnerabilities[0].title 'Improper Input Validation' >>> result.issues.vulnerabilities[0].identifiers {'CVE': ['CVE-2018-1000656'], 'CWE': ['CWE-20'] ``` -------------------------------- ### Retrieving All Projects for First Organization - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet illustrates how to access all projects associated with the first organization found for the client. It's a common pattern to chain manager calls to navigate the Snyk API hierarchy. ```Python client.organizations.first().projects.all() ``` -------------------------------- ### Initializing Snyk Client with Custom User-Agent - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet illustrates how to set a custom `User-Agent` string for API requests made by the Snyk client. This can be useful for identifying requests originating from specific applications or scripts. ```Python import snyk client = snyk.SnykClient("", user_agent="") ``` -------------------------------- ### Retrieving All Projects Across All Organizations - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This convenient method allows fetching all projects that the authenticated user has access to, across all their Snyk organizations, directly from the client object. ```Python client.projects.all() ``` -------------------------------- ### Handling Pagination and Custom Headers with SnykClient REST API (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet demonstrates advanced REST API usage, including how to handle pagination using `get_rest_pages` to retrieve all results from a paginated endpoint. It also shows how to make a POST request and override request headers, such as `Content-Type`, for specific API calls. ```python rest_client = SnykClient(snyk_token, version="2022-02-16~experimental", url="https://api.snyk.io/rest") params = {"limit": 10} targets = rest_client.get(f"orgs/{snyk_org}/targets", params=params).json() print(len(targets["data"])) # returns 10 targets all_targets = rest_client.get_rest_pages(f"orgs/{snyk_org}/targets", params=params) print(len(all_targets)) # returns 33 targets, note we don't have to add .json() to the call or access the "data" key, get_rest_pages does that for us # Override Content-Type header (or others) as needed for response = rest_client.post(f"orgs/{snyk_org}/invites", body={"email": "some.body@snyk.io", "role": "f8223479-01a9-4774-8e29-06ce9a0513d6", headers={"Content-Type": "application/vnd.api+json"}}) ``` -------------------------------- ### Initializing Snyk Client with Retry Logic - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This code demonstrates how to configure the Snyk client to automatically retry failed API requests. It allows specifying the maximum number of `tries`, the initial `delay` between attempts, and a `backoff` multiplier for subsequent delays. ```Python import snyk client = snyk.SnykClient("", tries=4, delay=1, backoff=2) ``` -------------------------------- ### Initializing pysnyk Client for REST API (Python) Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md Illustrates how to obtain a Snyk organization ID, which is a prerequisite for using the experimental REST (v3) API with pysnyk. This ID is typically found in the Snyk organization settings and is required for making subsequent REST API calls. ```Python # To get this value, get it from a Snyk organizations settings page snyk_org = "df734bed-d75c-4f11-bb47-1d119913bcc7" ``` -------------------------------- ### Filtering Snyk Projects by Tag - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet demonstrates how to filter a list of projects by one or more tags. The `filter` method accepts a list of dictionaries, where each dictionary specifies a 'key' and 'value' for the tag. ```Python client.organizations.first().projects.filter(tags = [{"key": "some-key", "value": "some-value"}]) ``` -------------------------------- ### Retrieving All Snyk Organizations - Python Source: https://github.com/snyk-labs/pysnyk/blob/master/README.md This snippet shows how to fetch a list of all Snyk organizations that the authenticated user is a member of. It returns a list of `snyk.models.Organization` objects, which can then be used to access organization-scoped resources. ```Python client.organizations.all() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.